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

turtle program help

Started by cmurtheepic, 09 February 2013 - 05:53 PM
cmurtheepic #1
Posted 09 February 2013 - 06:53 PM
help i can't get this to work

function start()
if redstone.getinput("back") then
turtle.place("front")
start()
end
end
start()
The_Awe35 #2
Posted 09 February 2013 - 07:17 PM
It looks like you are using the function in its own function. That's a big no no. Basically, when you run it, it is going to go down the code, then try to do the function start, go down the code again, try to do the function start again, into infinity. If you don't call the function in its own function
it will work fine. If you want it to repeat try doing a for loop or a while loop.


i = 5 -- however many time you want it to do it

for q = 1,i do
start()
end
or, if you want it to repeat forever try

while true do
start()
end


Next time, try to give more information, like the error code that the program spits back out at you.
ChunLing #3
Posted 09 February 2013 - 08:56 PM
What is "working"?

That is, what is this supposed to do?

Right now, it just throws an attempt to call nil error cause redstone.getinput is nil.
remiX #4
Posted 10 February 2013 - 12:14 AM
It looks like you are using the function in its own function. That's a big no no.

Only if the redstone input on the back is true
ChunLing #5
Posted 10 February 2013 - 05:47 AM
Meh, it's a no no for our purposes anyway. This code will never actually recurse because as it is now it won't run at all. Once conditions are arranged so that it can recurse, it will overflow the stack very quickly.