Title [Question][Lua] Efficient digging through gravel
I'm trying to write a new excavation program. I really like the current one as a strip miner, but one thing bugs me. It's really inefficient digging 1 block at a time. Turtles can dig Up, Front, and Down, then move.
If anyone is interested, here's what i have so far
Sorry, the forum seems to have removed my line spacing
function digmove(times) for i=1,times do while not turtle.forward() do turtle.dig() sleep (0.2) end turtle.forward() turtle.digUp() turtle.digDown() end end function dopath() end function gotolevel() turtle.digDown() turtle.down() turtle.digDown() turtle.down() turtle.digDown() segmentdone=0 end function segment(segments) digmove(17) turtle.turnRight() moveone() turtle.turnRight() digmove(17) segmentdone=segmentdone+1 if segments>segmentdone then leftturn() end end function leftturn() turtle.turnLeft() moveone() turtle.turnLeft() end function moveone() while not turtle.forward() do turtle.dig() sleep (0.2) end turtle.forward() turtle.digUp() turtle.digDown() end gotolevel() dotimes=1 while dotimes>segmentdone do segment(dotimes-segmentdone) end
(Dont worry, i dont expect anyone to dig through that to find my problem. A lot of the functions are still being debugged)
The problem here is that it's possible for gravel to fall from the top/front to the front slot. If this happens, the turtle skips a point in the digmove loop, so he ends up turning early, and ruining his pattern. To avoid this, i changed his dig/move routine to the following
while not turtle.forward() do turtle.dig() sleep (0.2) end
Then once this while loop ends, he moves. If i've got it right (and i dont think i do), he should be only digging when there's something diggable in front of him, but continuing to dig until there is not.
Have I done this right? Is there a better way?











