Difference between revisions of "Rednet message (event)"
From ComputerCraft Wiki
(Created event page) |
(Added code examples) |
||
Line 3: | Line 3: | ||
{{Event | {{Event | ||
|name=rednet_message | |name=rednet_message | ||
− | |desc=Fired when any Rednet message arrives. | + | |desc=Fired when any Rednet message arrives through an open modem. |
|return1=The computer ID of the sender (see [[os.computerID|os.getComputerID()]]). | |return1=The computer ID of the sender (see [[os.computerID|os.getComputerID()]]). | ||
− | |return2=The message. | + | |return2=The message as a [[string (type) | string]]. If message was previously a table see [[textutils.unserialize]] |
|return3=The distance between the modems. | |return3=The distance between the modems. | ||
+ | }} | ||
+ | {{Example | ||
+ | |desc=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 | ||
+ | }} | ||
+ | {{Example | ||
+ | |desc=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 | ||
}} | }} |
Revision as of 18:30, 18 January 2013
This page needs some serious TLC, stat! Please help us by cleaning it, fixing it up, or sparing it some love.
(Reason: A demonstration on the use and handling of this event would be beneficial. AfterLifeLochie 16:02, 30 November 2012 (MSK)) |
Event rednet_message | |
Fired when any Rednet message arrives through an open modem. | |
Returned Object 1 | The computer ID of the sender (see os.getComputerID()). |
Returned Object 2 | The message as a string. If message was previously a table see textutils.unserialize |
Returned Object 3 | The distance between the modems. |