Difference between revisions of "Rednet.receive"

From ComputerCraft Wiki
Jump to: navigation, search
(document distance-to-sender return)
Line 3: Line 3:
 
|name=rednet.receive( timeout )
 
|name=rednet.receive( timeout )
 
|args=A number representing the seconds to wait or leave empty to wait unlimited
 
|args=A number representing the seconds to wait or leave empty to wait unlimited
|returns=a tuple where the first value is the sending computers id and the second the message string
+
|returns=a tuple where the first value is the sending computer’s id, the second is the message, and the third is the distance in metres to the sender (or <code>nil</code> if using redpower bundled cable instead of a modem)
 
|api=rednet
 
|api=rednet
 
|addon=ComputerCraft
 
|addon=ComputerCraft
Line 10: Line 10:
 
{{Example
 
{{Example
 
|desc=waits unlimited till someone sends a message to this computer and displays it
 
|desc=waits unlimited till someone sends a message to this computer and displays it
|code=senderId, message = rednet.receive()term.write(message)
+
|code=senderId, message, distance = rednet.receive()<br>term.write(message)
 
}}
 
}}
 
}}
 
}}

Revision as of 04:55, 2 April 2012


Grid Redstone.png  Function rednet.receive( timeout )
Waits till timeout or another computer send a message to this computer. (see rednet.broadcast( message ) and rednet.send( receiverID, message ). To get the id from a computer see os.computerID(). In case a Timeout occurs the return id and message are set to nil
Syntax rednet.receive( timeout )(A number representing the seconds to wait or leave empty to wait unlimited)
Returns a tuple where the first value is the sending computer’s id, the second is the message, and the third is the distance in metres to the sender (or nil if using redpower bundled cable instead of a modem)
Part of ComputerCraft
API rednet

Examples

Grid paper.png  Example
waits unlimited till someone sends a message to this computer and displays it
Code
senderId, message, distance = rednet.receive()
term.write(message)