This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Send commands from Rednet
Started by mandisen2, 06 January 2013 - 04:00 AMPosted 06 January 2013 - 05:00 AM
So what I want to be able to do is to send a command to a turtle with rednet like excavate 10 or something like that. I know how to send messages to turtles but i cant make it excavate or tunnel or do commands. I tried doing the shell.run thing but then I would need to manually choose what size for it to dig. Pleasee help!
Posted 06 January 2013 - 05:07 AM
Computer code
Turtle code:
while true do
print("Turtle Control, please enter program")
rednet.send([turtle id], read())
end
Turtle code:
while true do
a, b = rednet.receive()
shell.run(B)/>
end
Edited on 29 May 2013 - 09:08 AM
Posted 06 January 2013 - 05:15 AM
Wouldn't this work? shell.run() doesn't require a comma between each argument
rednet.send(1, "excavate 10")
id, message = rednet.receive()
shell.run(message)
Turtle code:while true do a, b = rednet.receive() shell.run(a) end
shell.run(B)/> not a
Posted 06 January 2013 - 05:22 AM
Hmm, I tried it out but when i wrote "tunnel 10" it just says: No such program. I also tried Hello world and Excavate but it just said No such program :/
Posted 06 January 2013 - 05:27 AM
Lua god that worked when i put the b instead of a but what is the difference? :o/>
Posted 06 January 2013 - 06:09 AM
The line "a, b = rednet.receive() " set a and b equal to the first two returns of rednet.receive(), the ID of the sender and the rednet message string.
Posted 06 January 2013 - 09:18 AM
Wouldn't this work? shell.run() doesn't require a comma between each argument
You could always just have the receiving turtle parse out the message like the shell would.
id, msg = rednet.receive()
if msg then
local commandTable = {}
for str in string.gmatch(msg, "([^ \t]+)") do
table.insert(commandTable, str)
end
local command = table.remove(commandTable, 1)
command = shell.resolveProgram(command)
if command then
shell.run(command, unpack(commandTable))
end
end
Posted 06 January 2013 - 09:53 AM
This is completely inaccurate. shell.run() does, of course, require its arguments to be separated into arguments. Please don't spread misinformation.Wouldn't this work? shell.run() doesn't require a comma between each argument
Yes, of course, but you can use spaces to separate it. So wouldn't running a message containing "excavate 10" work?
Posted 06 January 2013 - 09:58 AM
Posted 06 January 2013 - 10:05 AM
I just tried "shell.run('edit stuff')" in the lua prompt and it worked fine.
Also, for that gmatch string of yours, couldn't you do "%S+" instead of "([^ \t]+)"?
Also, for that gmatch string of yours, couldn't you do "%S+" instead of "([^ \t]+)"?
Posted 06 January 2013 - 10:56 AM
Hah! I am wrong. Perhaps they moved it or I am completely misremembering. I will edit my posts to reflect that. Apologies, remix.