113 posts
Posted 21 June 2012 - 12:12 AM
How do I read a message and send it to another computer via rednet?
1604 posts
Posted 21 June 2012 - 12:14 AM
To receive a message:
local id, msg = rednet.receive()
to send:
rednet.send(theID, "The Message")
The id must be a number, and the message a string.
113 posts
Posted 21 June 2012 - 12:15 AM
Thanks, but I mean if I want to type the message out of lua. That, to my knowledge, can only be used in lua.
65 posts
Location
The Internet
Posted 21 June 2012 - 12:20 AM
Thanks, but I mean if I want to type the message out of lua. That, to my knowledge, can only be used in lua.
Please explain this better.
1604 posts
Posted 21 June 2012 - 12:20 AM
You have to make a program to do it, there isn't a default program to send/receive messages.
Try with this one:
local tArgs = { ... }
local id = tonumber(tArgs[1])
local msg = tArgs[2]
if not id or not msg then
print("Usage: send <id> <message>")
return
end
for _,s in ipairs(rs.getSides()) do
rednet.open(s)
end
rednet.send(id, msg)
And to receive:
for _,s in ipairs(rs.getSides()) do
rednet.open(s)
end
local id, msg = rednet.receive()
print(id, ": ", msg)
113 posts
Posted 21 June 2012 - 12:23 AM
Wow! Thanks for that, helped a lot. But this is too complicated for me. But thanks for the help.
while true do
rednet.open("right")
io.read = msg
rednet.broadcast(msg)
end
Will a variation of that work?
1604 posts
Posted 21 June 2012 - 12:24 AM
Almost, should be:
rednet.open("right")
while true do
local msg = read()
rednet.broadcast(msg)
end
113 posts
Posted 21 June 2012 - 12:30 AM
Perfect! This works amazingly.
Now, how do I send a command through a rednet message? I.e. a reboot message.
1604 posts
Posted 21 June 2012 - 12:36 AM
If you want the receiver to execute a command, it has to be waiting for a message, and then execute the command. There's different ways to do it, you can use keywords (like "reboot" to make the computer reboot), or make the computer execute any message it receives as a program (with shell.run).
113 posts
Posted 21 June 2012 - 12:37 AM
Would I do this?
if msg == reboot then
os.reboot()
end
134 posts
Location
Salt Lake, UT
Posted 21 June 2012 - 12:52 AM
yes.
1604 posts
Posted 21 June 2012 - 01:19 AM
Would I do this?
if msg == reboot then
os.reboot()
end
Yes, but remember to put quotes to the strings:
if msg == "reboot" then
os.reboot()
end