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

loop dont work

Started by gheotic, 02 January 2013 - 04:01 AM
gheotic #1
Posted 02 January 2013 - 05:01 AM
Hello everyone who is reading this i have some problems with my program

im trying to make a mining turtle to dig a tunnel, but it dosnt perform a loop correctly
i have tried testing it out by putting some gravel in front of it but it only dig 1 gravel out then carry on the script


local fuel = 1
local x = 0

term.clear()
term.setCursorPos(1,1)
print("Turtle has started")
function getFuel()
if turtle.getFuelLevel() <=10 then
turtle.select(1)
turtle.refuel(2)   
end
end
function Detect() -- this function
while turtle.detect() do
turtle.dig()
end
end
getFuel()
turtle.up()
while x < 16 do --digging the tunnel
Detect()
turtle.forward()
turtle.digDown()
turtle.turnRight()
Detect()
turtle.forward()
turtle.turnLeft()
turtle.digDown()
Detect()
turlle.forward()
turtle.digDown()
turtle.turnLeft()
Detect()
turtle.forward()
turtle.turnRight()
turtle.digDown()
x = x + 1
end
GopherAtl #2
Posted 02 January 2013 - 05:10 AM
there's a bit of a delay between digging and gravel falling into the new space to be detected. The simplest and most reliable way to dig through any amount of gravel is to make turtle.forward() the condition, like this…


while not turtle.forward() do
  turtle.dig()
end
W00dyR #3
Posted 02 January 2013 - 05:11 AM
You need to put a delay in the detect() function, else it digs a block, instantly detects (while gravel, as an entidy, is falling) and doesnt see anything, so continues.

Best way to do this is after turtle.dig(), add sleep(0.5)
gheotic #4
Posted 02 January 2013 - 05:25 AM
You need to put a delay in the detect() function, else it digs a block, instantly detects (while gravel, as an entidy, is falling) and doesnt see anything, so continues.

Best way to do this is after turtle.dig(), add sleep(0.5)

oh thanks alot :D/>
ChunLing #5
Posted 02 January 2013 - 04:10 PM
If you can use your movement function to detect the gravel, that's a bit more convenient. But for digging gravel that is falling into a space that you want cleared but won't be moving into, using detect with a sleep is better.
remiX #6
Posted 02 January 2013 - 10:05 PM
You need to put a delay in the detect() function, else it digs a block, instantly detects (while gravel, as an entidy, is falling) and doesnt see anything, so continues.

Best way to do this is after turtle.dig(), add sleep(0.5)

sleep(0.4) is the least time it needs, for maximum speed.