AdvTunnel:133 'for' limit must be a number
Spoiler
local tArgs = { ... }
-- Explain how to use the program
if tArgs[1] == 'help' then
print('Usage:')
print('enter advTunnel : [length]')
return
end
-- Set our distance to mine
local mDistance = tArgs[1] or 1
function fuelLevel()
if turtle.getFuelLevel() > 80 then
turtle.refuel()
return
end
end
function turnAround()
turtle.turnRight(2)
end
function paveDown()
turtle.select(2)
turtle.placeDown()
end
function paveUp()
turtle.select(2)
turtle.placeUp()
end
function paveFront()
turtle.select(2)
turtle.place()
end
function detectFront()
if turtle.detect() then
paveFront()
end
end
function detectDown()
if turtle.detectDown() then
paveDown()
end
end
function detectUp()
if turtle.detectUp() then
paveUp()
end
end
function pave()
detectUp()
detectDown()
detectFront()
end
function reinforce()
detectUp()
detectFront()
end
function returnHome()
turnAround()
for returnLocation = 0, mDistance do
-- Make sure to deal with sand and friends
while turtle.detect() do turtle.dig() end
turtle.forward()
end
end
function digTunnel()
while turtle.detect() do turtle.dig() end
turtle.forward()
pave()
turtle.turnRight()
while turtle.detect() do turtle.dig() end
pave()
turtle.dig()
turtle.forward()
while turtle.detect() do turtle.dig() end
pave()
turtle.dig()
turtle.forward()
pave()
turtle.digUp()
turtle.up()
reinforce()
turtle.turnLeft()
reinforce()
turtle.turnLeft()
while turtle.detect() do turtle.dig() end
reinforce()
turtle.dig()
turtle.forward()
while turtle.detect() do turtle.dig() end
reinforce()
turtle.dig()
turtle.forward()
reinforce()
turtle.digUp()
turtle.up()
reinforce()
turtle.turnRight()
reinforce()
turtle.turnRight()
while turtle.detect() do turtle.dig() end
reinforce()
turtle.dig()
turtle.forward()
while turtle.detect() do turtle.dig() end
reinforce()
turtle.dig()
turtle.forward()
reinforce()
turtle.turnLeft()
reinforce()
turtle.down(2)
turtle.turnLeft()
turtle.forward(2)
turtle.turnRight()
fuelLevel()
end
for currentLocation = 0, mDistance do
digTunnel(currentLocation)
end
returnHome()
Im probably inefficient as all get with my main program loop, but I was mostly trying to get it to work and not worrying about elegance. Any help would be apreciated.
EDIT: I modified the code (changed mdistance to mDistance and made sure it was consistant through.) the program runs now, but I have a new problem. in the following section I tell it to move down two then turn left and forward 2 then turn right. however, it just goes down 1 and over 1.
turtle.turnLeft()
reinforce()
turtle.down(2)
turtle.turnLeft()
turtle.forward(2)
turtle.turnRight()
fuelLevel()
end
also, It doesnt handle sand or gravel at all. it just stops infront of them. I thought that this line would make it keep mining as long as it detected anything in front?
while turtle.detect() do turtle.dig() end
do I just need to loop it? if so I should just make the entire thing more optimized and repeat with loops.
I also just noticed that it isnt even placing blocks. which I wanted it to do (goal was to eliminate any liquids it comes in contact with,) so Im obviously missing something in the way Im constructing the code, or using the turtle commands.