Modem

Eventmodem_message
Occurs every time a wireless message has been received by (wireless) modem that had the message's channel open.
Returns
  • name : string The side or network name of the wrapped Modem that received the message
  • channel : number The channel the message has been send on
  • channel : number The desired reply channel the sender specified
  • message : any The message's content
  • distance? : number The distance from the sender to the receiver, in meters/blocks. This will not be set if the modems are in different dimensions.
Part of CC:Tweaked
ExampleReceiving modem messages
Wraps a connected modem peripheral, opens channel 123 and listens for incoming messages.
Code
<nowiki>
local modem = peripheral.find("modem")
modem.open(123)

while true do
  local event, peripheral_name, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  print("Received a message on channel", channel, "at", distance, "blocks away.")
  print("The message: ", message)
end
    </nowiki>
Eventrednet_message
Triggered by the rednet coroutine and is created from the modem_message event. For most use cases, rednet.receive is usually easier to use.
Returns
  • id : number The supposed ID of the sender.
  • msg : any The message.
  • protocol? : string The specified protocol. Prior to ComputerCraft 1.6, was the distance between sender and reciever.
Part of CC:Tweaked
ExamplePrint messages
Prints messages received through rednet. Requires that there is a modem open for rednet to use.
Code
<nowiki>
while true do
  local event, senderId, message, protocol = os.pullEvent("rednet_message")
  print("Computer", senderId, "sent a message", message, "with the", protocol, "protocol!")
end
    </nowiki>
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.