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

turtle stopping in advance

Started by silwrk, 29 December 2012 - 03:24 AM
silwrk #1
Posted 29 December 2012 - 04:24 AM
Hi, I'm new to programming and having some slight issues. problem is when a player or animal is standing infront of turtle.
he will continue until there is another block behind the player and stop without digging out the rest of the way.

thanks in advance for any pointers

e=0
while e<10 do
if not turtle.detect() then
repeat
turtle.forward()
e=e+1
until turtle.detect()==true
else
repeat
turtle.dig()
until turtle.detect()==false
end
end
Fizzgig #2
Posted 29 December 2012 - 04:35 AM
the problem is where you place the enumerator. it always adds even if the turtle did not move. the turtle.forward() has a return so you can check it like this:

if turtle.forward() then e=e+1 end

that way if it did not move it wont add e to end prematurely
silwrk #3
Posted 29 December 2012 - 04:44 AM
thank you, that solved my problem :)/>