This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Cavtheman's profile picture

Need help sending command with arguments over rednet.

Started by Cavtheman, 09 August 2013 - 10:43 AM
Cavtheman #1
Posted 09 August 2013 - 12:43 PM
I have been trying to get my computer to send messages over rednet to my turtle, but i need a way to send a message from my computer telling the turtle to run the program.
The only problem is that the program needs an argument, fx "mine 10", and i haven't figured out, or found a way to do that yet.
if anybody could come up with a little bit of code to help me out,i would be so grateful! I am using the FTB Unleashed 1.1.3 pack
Bubba #2
Posted 09 August 2013 - 12:53 PM
Split into new topic.
HurricaneCoder #3
Posted 09 August 2013 - 01:53 PM
You can use conditional statement to set the variable.
Bubba #4
Posted 09 August 2013 - 02:48 PM
You can use conditional statement to set the variable.

That's not particularly feasible unless you have only a few preset options. For something like this, you can straight up send the argument through rednet and pass it to shell.run.

For example
Client:

local args = ... -- # This is how you can get arguments from the shell.
local modem = peripheral.wrap("top")
modem.transmit(1,1,args) --# Simply send the number straight to the turtle

Turtle:

local modem = peripheral.wrap("right")
modem.open(1)
local event, side, channel, from, message = os.pullEvent("modem_message") --# Just wait for a message
shell.run("rom/programs/excavate",message) --# Run the program, providing the given message as an argument

In order for this to work, all you have to do is run the program on the turtle and then run the client with the size as an argument.
Lyqyd #5
Posted 09 August 2013 - 02:57 PM
Shell.run can take the entire command-line string in the first argument, like this:


shell.run("excavate 16")
Cavtheman #6
Posted 09 August 2013 - 04:47 PM
I have tried running this, but i can't get the turtle to recieve the message, i have tried making print if it got the message, but nothing has happened, so i'm wondering, should i run it insinde the programs?
i'm guessing that i can run the turtle's on startup, and the client, i have to type in the program name, and then the argument, is that correct?
Bubba #7
Posted 09 August 2013 - 06:49 PM
I have tried running this, but i can't get the turtle to recieve the message, i have tried making print if it got the message, but nothing has happened
It's possible that you misspelled os.pullEvent("modem_message"). Check the spelling of modem_message very carefully because when you provide an argument to os.pullEvent it will filter the events until one matches it. Check out os.pullEvent on the wiki for more info.

i'm guessing that i can run the turtle's on startup, and the client, i have to type in the program name, and then the argument, is that correct?
Yes on both counts.
Cavtheman #8
Posted 14 August 2013 - 07:23 AM
I still can't get the turtle to recieve the message to run the program, i've checked everything, looked at the wiki, but i still can't figure out why it's not recieving. FTB Unleashed uses CC 1.53 could this have anything to do with it?
Cavtheman #9
Posted 14 August 2013 - 01:04 PM
I figured it out, i just realized that my computer was too far away from the turtle for it to recieve the signal, thank you for your help!