modem_message event

From ComputerCraft
Jump to: navigation, search
modem_message
Event
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.

Source CC:Tweaked

Occurs every time a wireless message has been received by a wrapped (wireless) modem that had the message's channel open.

ExampleExampleReceiving modem messages
Wraps a connected modem peripheral, opens channel 123 and listens for incoming messages.
Code
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