rednet.receive
Waits for a Rednet message to be received by an opened modem, or until timeout seconds elapse. Takes another optional parameter, which limits messages able to be received to those broadcasted or sent with a matching protocol.
rednet.receive Function | |
---|---|
Syntax rednet.receive(
| |
Returns | number senderID, any message, string protocol |
API | rednet |
Source | Rednet API (source) |
|
|||
Since we have no arguments, rednet.receive will wait for the next message from any protocol. If a rednet message was received with the text "Hello world!", the the output would be as follows: | |||
Code | <nowiki>
local id, message, protocol = rednet.receive()
print(message)
</nowiki>
|
||
Output | "Hello world!"
|
|
|||
Since we have our timeout specified, rednet.receive will wait for the next message from any protocol, or until the timeout is up. If a rednet message was received with the text "Now there's a timeout!" before the timeout is up, the the output would be as follows: | |||
Code | <nowiki>
local id, message, protocol = rednet.receive(30)
print(message)
</nowiki>
|
||
Output | "Now there's a timeout!"
|
|
|||
Since we have our timeout and protocol specified, rednet.receive will wait for the next message from a specific protocol, or until the timeout is up. If a rednet message was received with the text "Now there's a protocol!" and protocol "ComputerCraft" before the timeout is up, the the output would be as follows: | |||
Code | <nowiki>
local id, message, protocol = rednet.receive("ComputerCraft", 30)
print(message)
</nowiki>
|
||
Output | "Now there's a protocol!"
|
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.