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

[lua][question] Why does my turtle shutdown?

Started by verteinwolf, 23 June 2012 - 08:21 PM
verteinwolf #1
Posted 23 June 2012 - 10:21 PM
I spent a while writing a program for a mining turtle and when I was finally done, i started it, it printed the questions accepted my answers and then the turtle shutdown without doing anything. what am I doing wrong?

code:


while side ~= "right" and side ~= "left" do
print("which side?")
side = read()
end
while height ~= "top" and height ~= "middle" and height ~= "bottom" do
print("what height?")
height = read()
end
function forward()
while turtle.forward() ~= true do
end
end
function back()
while turtle.back() ~= true do
end
end
function dig()
a = 0
while turtle.dig() == true and a<5 do
sleep(.8)
a = a+1
end
end
function digUp()
a = 0
while turtle.digUp() == true and a < 5 do
sleep(.8)
a = a+1
end
end
function dig3()
dig()
forward()
digUp()
turtle.digDown()
end
if height == "top" then
while turtle.down ~= true do
end
end
if height == "bottom" then
while turtle.up ~= true do
end
end
if side == "left" then
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
end
while turtle.itemCount( 9 ) < 1 do
dig3()
turtle.turnRight()
dig3()
turtle.turnLeft()
if turtle.compare() == false then
dig3()
turtle.back()
turtle.place()
end
turtle.turnLeft()
forward()
turtle.turnRight()
dig3()
turtle.turnLeft()
dig3()
turtle.turnLeft()
dig3()
turtle.turnRight()
dig3()
turtle.turnRight()
dig3()
if turtle.compare() == false then
dig3()
turtle.back()
turtle.place()
end
turtle.turnRight()
forward()
turtle.turnLeft()
forward()
dig3()
turtle.turnRight()
dig3()
end
MysticT #2
Posted 23 June 2012 - 10:49 PM
This lines are the problem:

...
while turtle.down ~= true do
...
while turtle.up ~= true do
...
You forgot the brackets in the function calls, so it was comparing the function (the actual function, not it's return value) with true (wich will always be false, function != boolean), so the loop never ended, causing a too long without yielding error.
verteinwolf #3
Posted 23 June 2012 - 11:00 PM
ah! thanks a lot! (it's always those little things that i miss) :P/>/>