This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Run Turtleprogram from a Computer?
Started by Klausar, 29 September 2012 - 04:16 PMPosted 29 September 2012 - 06:16 PM
I want to know how to run a Turtleprogram from my Computer. For Example if the program is "Stone" and mines at a stonegenerator, what should be the code for the Computer, and for the turtle? Oh and for example my treecutter asks me howmany trees it should cut down, I would also have to see that and answer it from my Computer.
Posted 29 September 2012 - 06:23 PM
I'm not sure what you're asking, but if you want to run a program on a computer that can only be found on a turtle, try this:
local program = "put the program name here"
shell.run( "copy", "rom/programs/turtle/" .. program, "/" )
shell.run( program )
Posted 29 September 2012 - 06:32 PM
I want to run a program on my turtle but start it from my computer.
Posted 29 September 2012 - 06:39 PM
I want to run a program on my turtle but start it from my computer.
Is the computer right next to the turtle? Do they have modems? Do they have a redstone connection? At least one of these things is required
Posted 29 September 2012 - 06:53 PM
They have modems, I'm not sure how to connect them though.
Posted 29 September 2012 - 07:03 PM
Ok. For the computer, this should run inside a program:
And for the turtle, run this:
local modemSide = "side of modem" --replace with side the modem is on
local turtleID = id of turtle --replace with turtle id. the id of the turtle can be found by typing 'id' into the turtle
rednet.open( modemSide ) --turns on the modem
rednet.send( turtleID, "begin" ) --sends the message "begin" to the turtle
And for the turtle, run this:
local modemSide = "right"
local programToRun = "name of program to run" --replace with name of program that you want to start remotely
while true do
id, msg, dist = rednet.receive() --waits for message
if msg == "begin" then --if the message says "begin" then start the program
shell.run( programToRun ) --starts the program
end
end
Posted 29 September 2012 - 07:11 PM
Doesn't work :)/>/> My Computer code looks like this:
While my startup for the turtle looks like this:
local modemSide = "right"
local turtleID = 4
rednet.open( modemSide ) --turns on the modem
rednet.send( turtleID, "begin" ) --sends the message "begin" to the turtle. The id of the turtle can be found by typing id into the turtle
While my startup for the turtle looks like this:
local modemSide = "right"
local programToRun = "stone"
while true do
id, msg, dist = rednet.receive()
if msg == "begin" then
shell.run( stone )
end
end
Posted 29 September 2012 - 07:14 PM
Hmmm, I haven't tested it myself. What error did it give? or did it just do nothing? Is the program's name stone, with all lowercase letters?
Posted 29 September 2012 - 07:15 PM
Tried with capital letters too and yes the program is called stone.
Posted 29 September 2012 - 08:03 PM
I've changed the rednet.receive() into an os.pullEvent()
Shouldn't make a difference, but I've traditionally used that, so I'm more comfortable with it.
The program "stone" should be in the root folder of the turtle, or the rom. Is it possible that you put the wrong modemSide? It depends on which way you face. The modem should light up red if you configured it properly. If it isn't change the modemSide or put the modem on the side "back"
Computer:
Turtle:
Shouldn't make a difference, but I've traditionally used that, so I'm more comfortable with it.
The program "stone" should be in the root folder of the turtle, or the rom. Is it possible that you put the wrong modemSide? It depends on which way you face. The modem should light up red if you configured it properly. If it isn't change the modemSide or put the modem on the side "back"
Computer:
local modemSide = "side of modem" --replace with side the modem is on
local turtleID = id of turtle --replace with turtle id. the id of the turtle can be found by typing 'id' into the turtle
rednet.open( modemSide ) --turns on the modem
rednet.send( turtleID, "begin" ) --sends the message "begin" to the turtle
Turtle:
local modemSide = "right"
local programToRun = "name of program to run" --replace with name of program that you want to start remotely
while true do
event, id, msg, dist =os.pullEvent( "rednet_message" ) --waits for message
if msg == "begin" then --if the message says "begin" then start the program
shell.run( programToRun ) --starts the program
end
end
Posted 30 September 2012 - 07:50 AM
Still nothing happens, that's weird.
Edit: The modem on the computer lights up, the one on the turtle doesn't, I tried all sides.
Edit: The modem on the computer lights up, the one on the turtle doesn't, I tried all sides.
Posted 30 September 2012 - 09:00 AM
You havent opened th modem on the tirtle add a
rednet.open("right")
to the start of your turtle programPosted 30 September 2012 - 09:05 AM
You havent opened th modem on the tirtle add ato the start of your turtle programrednet.open("right")
Thanks, but it still does nothing.
Posted 30 September 2012 - 09:08 AM
Well apart from that i cant see anything
Posted 30 September 2012 - 03:50 PM
Are they really far apart? By default, the config specifies that rednet can travel only 64 blocks (in version 1.3.*)
That's the only thing I can think of that might be stopping the from connecting now
That's the only thing I can think of that might be stopping the from connecting now
Posted 30 September 2012 - 03:52 PM
There are only 20 blocks of air between them. Not too far at all.
Posted 30 September 2012 - 04:18 PM
Ok, Let's make it use redstone instead then. Note that if you're using the tekkit pack, computers can output a signal into red alloy wire, but must receive a signal from redstone.
Change the redstoneSide to the side the computer will output to.
Computer:
Turtle:
Change the redstoneSide to the side the computer will output to.
Computer:
local redstoneSide = "side of modem" --replace with side the redstone is to be outputted from
rs.setOutput( redstoneSide, true ) --turns on redstone
sleep( 0.1 ) --waits
rs.setOutput( redstoneSide, false ) --turns off redstone
Turtle:
local programToRun = "name of program to run" --replace with name of program that you want to start remotely
while true do
event, param1, param2 =os.pullEvent( "redstone" ) --waits for redstone change
shell.run( programToRun ) --starts the program
sleep( 1 ) --sleeps so that it will not notice the redstone turning off. probably not necessary.
end
end
Posted 01 October 2012 - 02:35 PM
Sorry to Hijack this thread but i got the wireless way to work by adding rednet.open("right") at the top of the turtle program. Now, the mining program i have is controllable so that i can choose the dimensions of the tunnel and whether or not i would like to place torches along the way, how should i do to be able to acces that from the computer instead of having to start the turtle from the computer and then having to walk to the turtle to then get it to start?
Posted 01 October 2012 - 03:28 PM
Sorry to Hijack this thread but i got the wireless way to work by adding rednet.open("right") at the top of the turtle program. Now, the mining program i have is controllable so that i can choose the dimensions of the tunnel and whether or not i would like to place torches along the way, how should i do to be able to acces that from the computer instead of having to start the turtle from the computer and then having to walk to the turtle to then get it to start?
you may need to use events instead of calling read() so you can wait for the user to press a number or send a rednet message.
it's more complicated, but you could also use the parallel api to call read() in one function and listen for rednet in another, at the same time
Posted 01 October 2012 - 03:50 PM
Could you give some examples? I have like 0 experience with CC and lua exept some basic password locks :)/>/>
Posted 01 October 2012 - 04:52 PM
sure. Here's a simple way to wait for either a key press or a rednet_message:
If you want more flexibility at the cost of your program getting a lot more complicated to understand, try searching for the parallel api. Using it can run multiple functions at once, allowing part of your program to be sleeping or reading input, while other parts wait for rednet messages or create a good-looking UI.
while true do
local event, param1, param2, param3 = os.pullEvent()
if event == "rednet_message" and param2 == "message that was sent through rednet" then
--this happens if you receive the correct message
elseif event == "rednet_message" and param2 == "different rednet message" then --you can specify a lot of different events to wait for
--stuff that happens if that particular message is received
elseif event == "char" and param1 == "y" then --if the event was a character and the character was 'y'
--this happens if you press 'y' for yes
elseif event == "char" and param1 = "n" then
--this happens if 'n' is pressed
end
I recommend using the wiki to learn more. Try searching for events, os.pullEvent() and rednet.If you want more flexibility at the cost of your program getting a lot more complicated to understand, try searching for the parallel api. Using it can run multiple functions at once, allowing part of your program to be sleeping or reading input, while other parts wait for rednet messages or create a good-looking UI.
Posted 01 October 2012 - 04:53 PM
I actually have a small question, which isn't worth creating another thread for. I'm wondering how you get the ID of a turtle? If I add print(os.computerID) into the turtles startup, it shows random letters and numbers and those change everytime I restart.
Posted 01 October 2012 - 05:51 PM
if you just type in "id" in the turtle it will show up
Posted 24 April 2013 - 10:59 AM
The problem in the first code is that you called stone instead of "stone" so it lua will think taht is a variable and, it return nil, so it crash
EDIT: Necromancy!!
EDIT: Necromancy!!