Rednet message (event)

From ComputerCraft Wiki
Jump to: navigation, search


Grid Modem.png  Event rednet_message
Fired when any rednet.send()'d message arrives through an open modem.
Returned Object 1 The computer ID of the sender (see os.getComputerID()).
Returned Object 2 The message. Functions / coroutines sent are converted to nil. Prior to about CC 1.53, so were tables, which required use of textutils.serialize() to transmit.
Returned Object 3 The protocol used, or nil if none was specified. Prior to CC 1.6, this was the distance (in blocks) between the computers.


Grid paper.png  Example
Prints a message
Code
while true do
  event, senderId, message, distance = os.pullEvent("rednet_message")
  print( "Computer: "..senderId.." sent a message: "..message.." from "..distance.." blocks away!" )
end



Grid paper.png  Example
Ignores messages from any computer other than the one with id 5
Code
while true do
 event, senderId, message, distance = os.pullEvent("rednet_message")
 if senderId == 5 then
   print("Got a message from the boss saying: "..message)
 end
end