How do I read a message and send it to another computer via rednet?
[Lua][Rednet][Programming]Reading message to send via Rednet?
Started by EmTeaKay, Jun 20 2012 11:12 PM
11 replies to this topic
#1
Posted 20 June 2012 - 11:12 PM
#2
Posted 20 June 2012 - 11:14 PM
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.
#3
Posted 20 June 2012 - 11:15 PM
Thanks, but I mean if I want to type the message out of lua. That, to my knowledge, can only be used in lua.
#5
Posted 20 June 2012 - 11:20 PM
You have to make a program to do it, there isn't a default program to send/receive messages.
Try with this one:
And to receive:
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)
#6
Posted 20 June 2012 - 11:23 PM
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?
#7
Posted 20 June 2012 - 11:24 PM
Almost, should be:
rednet.open("right")
while true do
local msg = read()
rednet.broadcast(msg)
end
#8
Posted 20 June 2012 - 11:30 PM
Perfect! This works amazingly.
Now, how do I send a command through a rednet message? I.e. a reboot message.
Now, how do I send a command through a rednet message? I.e. a reboot message.
#9
Posted 20 June 2012 - 11:36 PM
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).
#10
Posted 20 June 2012 - 11:37 PM
Would I do this?
if msg == reboot then os.reboot() end
#11
Posted 20 June 2012 - 11:52 PM
yes.
3 user(s) are reading this topic
0 members, 3 guests, 0 anonymous users












