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

3x3 tunnel program need help!

Started by AvidNinja, 24 November 2014 - 03:16 AM
AvidNinja #1
Posted 24 November 2014 - 04:16 AM
I have a turtle program from years ago, it mines a 3x3 tunnel and when full returns to starting point.

I want to stop it from returning when full, and only return after it reaches the distance you tell it.

I realize that once full it will drop blocks to the ground, im fine with that as I will be following to pick them up.

n1 = 0
n2 = 0
function text()

shell.run("clear")
print("fuel level: ".. turtle.getFuelLevel())
io.write "turtle will stop when this number reaches zero: "
io.write (n3)
print ""
print ""
print "or when the last slot in it's inventory is in use."

end


function Return()

repeat
turtle.back()
n2 = n2 - 1
until n2 == 0

end


function dig()

if turtle.getFuelLevel() < 3 then
for i = 1,16 do
if turtle.getItemCount(i) > 0 then
turtle.select(i)
if turtle.refuel(1) then
break
end
end
end
turtle.select(1)
end

if turtle.detectUp() == true then
turtle.digUp()
elseif turtle.detectDown() == true then
turtle.digDown()
else
n1 = n1 + 1
if n1 == 1 then
turtle.turnLeft()
while true do
if turtle.detect() == true then
turtle.dig()
else
break
end
sleep(0.4)
end
turtle.forward()
elseif n1 == 2 then
turtle.back()
turtle.turnRight()
turtle.turnRight()
while true do
if turtle.detect() == true then
turtle.dig()
else
break
end
sleep(0.4)
end
turtle.forward()
elseif n1 == 3 then
turtle.back()
turtle.turnLeft()
elseif n1 == 4 then
while true do
if n3 == 1 then
break
elseif turtle.getItemCount(16) ~= 0 then
n3 = 1
break
elseif turtle.detect() == true then
turtle.dig()
sleep(0.4)
else
break
end
end
turtle.forward()
n1 = 0
n3 = n3 - 1
n2 = n2 + 1
end
end
sleep(0.4)

end


function start()

shell.run("clear")
io.write "how long do you want the tunnel: "
n3 = io.read()
n3 = tonumber(n3)
while true do
if turtle.detect() == true then
turtle.dig()
sleep(0.4)
else
break
end
end
turtle.forward()
shell.run("clear")

end

– NO MORE FUNCTIONS :D/>

start()
while true do
text()
dig()
if n3 == 0 then
break
end

end
Return()
text()
sleep(2)
shell.run("clear")
print "DONE!"
print "or out of inventory…"


I fixed this code once before but lost it, and have since forgot how i did it… Please help!
AvidNinja #2
Posted 24 November 2014 - 05:02 AM
Looking at this I have come to the conclusion that all i need to do is delete the line of code that reads:

elseif turtle.getItemCount(16) ~= 0 then
n3 = 1
break

Can anyone confirm this?