Difference between revisions of "Rednet.send"
Apemanzilla (Talk | contribs) m |
Bomb Bloke (Talk | contribs) (CC 1.6 update adds protocols) |
||
Line 2: | Line 2: | ||
{{Function | {{Function | ||
|name=rednet.send | |name=rednet.send | ||
− | |args={{type|number}} receiverID, {{type|string}} message | + | |args={{type|number}} receiverID, {{type|string}} message, [<nowiki/>{{type|string}} protocol] |
|returns={{Type|boolean}} success code. True if a message has been sent (note - "sent", as opposed to "received" or even "was receivable"), false if not. | |returns={{Type|boolean}} success code. True if a message has been sent (note - "sent", as opposed to "received" or even "was receivable"), false if not. | ||
|api=rednet | |api=rednet | ||
|addon=ComputerCraft | |addon=ComputerCraft | ||
− | |desc=Allows a [[computer]] / [[turtle]] with an attached [[modem]] to send a message intended for a system with a specific ID. At least one such modem must first be " | + | |desc=Allows a [[computer]] / [[turtle]] with an attached [[modem]] to send a message intended for a system with a specific [[os.getComputerID|ID]] (compare [[rednet.broadcast|rednet.broadcast()]], which aims to target everything in range). At least one such modem must first be "[[Rednet.open|opened]]" before sending is possible. Assuming the target was in range and also had a correctly opened modem, it may then use [[rednet.receive|rednet.receive()]] to collect the message.<br><br> |
− | + | Messages are transmitted on a channel number equal to the target system's ID, with a suggested "reply" channel equal to the sending system's ID. Be aware that if other users are in range of your [[Wireless Modem|wireless]] network, or cabled into your [[Wired Modem|wired]] network, knowing / guessing your target ID number will allow them to [[Modem.open|manually open]] that channel on their own systems in order to receive your messages. As of ComputerCraft 1.6, all rednet messages are additionally sent on channel 65533 (allowing the [[Repeat (program)|repeat script]] to easily detect them).<br><br> | |
− | + | ComputerCraft 1.6 also introduces "[[Rednet (API)#Protocols|protocol]]" - simple string names indicating what the message is about. Receiving systems may filter messages according to their protocols, thereby automatically ignoring incoming messages which don't specify an identical string. It's also possible to [[rednet.lookup|lookup]] which systems in the area are interested in certain protocols, hence making it easier to determine where given messages should be sent in the first place.<br><br> | |
− | + | Messages are typically strings, however later versions of ComputerCraft ''(which?)'' may alternatively send tables instead. Those users still on older versions may find [[Textutils.serialize|textutils.serialize()]] useful when wanting to transmit tables. | |
|examples= | |examples= | ||
{{Example | {{Example | ||
Line 18: | Line 18: | ||
|code=rednet.send(22,"ComputerCraft") | |code=rednet.send(22,"ComputerCraft") | ||
}} | }} | ||
+ | {{Example | ||
+ | |desc=Sends a message to the system with the ID of 22, specifying a protocol of "TestMessages". | ||
+ | |code=rednet.send(22,"ComputerCraft","TestMessages") | ||
}} | }} | ||
+ | }} | ||
+ | |||
+ | {{RednetAPIFunctions}} | ||
[[Category:API_Functions]] | [[Category:API_Functions]] |
Revision as of 06:33, 6 June 2014
Function rednet.send | |
Allows a computer / turtle with an attached modem to send a message intended for a system with a specific ID (compare rednet.broadcast(), which aims to target everything in range). At least one such modem must first be "opened" before sending is possible. Assuming the target was in range and also had a correctly opened modem, it may then use rednet.receive() to collect the message. Messages are transmitted on a channel number equal to the target system's ID, with a suggested "reply" channel equal to the sending system's ID. Be aware that if other users are in range of your wireless network, or cabled into your wired network, knowing / guessing your target ID number will allow them to manually open that channel on their own systems in order to receive your messages. As of ComputerCraft 1.6, all rednet messages are additionally sent on channel 65533 (allowing the repeat script to easily detect them). ComputerCraft 1.6 also introduces "protocol" - simple string names indicating what the message is about. Receiving systems may filter messages according to their protocols, thereby automatically ignoring incoming messages which don't specify an identical string. It's also possible to lookup which systems in the area are interested in certain protocols, hence making it easier to determine where given messages should be sent in the first place. | |
Syntax | rednet.send(number receiverID, string message, [string protocol]) |
Returns | boolean success code. True if a message has been sent (note - "sent", as opposed to "received" or even "was receivable"), false if not. |
Part of | ComputerCraft |
API | rednet |
Examples
Example | |
Sends a message to the system with the ID of 22 (assuming a modem is attached and open). | |
Code |
rednet.send(22,"ComputerCraft") |
Example | |
Sends a message to the system with the ID of 22, specifying a protocol of "TestMessages". | |
Code |
rednet.send(22,"ComputerCraft","TestMessages") |
Rednet API Functions |
---|
rednet.open - rednet.close - rednet.send - rednet.broadcast - rednet.receive - rednet.isOpen - rednet.host - rednet.unhost - rednet.lookup |