Can someone with a bit more experience give me a bit of a guiding hand as to what I did wrong and what I need to do to fix it?
args = {...}
local direction
dirX,dirY,dirZ,facing = 0
--[[Meat of the program. Actually digs the hole.
It starts by looping X arrays, then moves back to starting position (0,0), moves
up or down, then mines that array as well.]]--
function mine()
forward()
local turnPat = 0
for dirZ in height do
for dirX in width do
for dirY in depth-1 do
forward()
end
if dirX != width do
if turnPat = 0 then
left()
forward()
left()
turnPat=1
elseif turnPat = 1 then
right()
forward()
right()
turnPat=0
end
end
end
if turnPat = 0 then
left()
--[[turnPat or turnPattern essentially is for the even/odd scenario while mining. When he finishes a column, he will either be in the top right or bottom right.]]--
while dirX-1 > 0 do
forward()
end
left()
while dirY-1 > 0 do
forward()
left()
left()
down()
end
else
right()
while dirX > 0 do
forward()
left()
down()
end
end
end
end
--[[Conveniently clears screen]]--
function clear()
term.clear()
term.setCursorPos(1,1)
end
function kill()
print("System shutting down in 2 seconds..")
clear()
end
--[[Navigation loop. Goes back to point 0,0,0 by looping through and
first moving X to 0, then Y, then Z. ]]--
function home()
--[[Nav to X = 0 loop]]--
if dirX < 0 then
while facing != 1 do
left()
end
while dirX < 0 then
forward()
end
elseif dirX > 0 then
while facing != 3 do
left()
end
while dirX > 0 then
forward()
end
end
--[[Nav to Y = 0 loop]]--
if dirY < 0 then
while facing != 0 do
left()
end
while dirY < 0 then
forward()
end
elseif dirY > 0 then
while facing != 2 do
left()
end
while dirY > 0 then
forward()
end
end
--[[Nav to Z = 0 loop]]--
while dirZ < 0 do
up()
end
while dirZ > 0 do
down()
end
end
--[[Navigation function. Fixes bearings to account for direction and shortens turn commands.]]--
function left()
if facing > 1 then
facing = facing-1
else
facing = 3
end
turtle.turnLeft()
end
function right()
if facing < 3 then
facing = facing+1
else
facing = 0
end
turtle.turnLeft()
end
function up()
z = dirZ+1
while turtle.detectUp() then
turtle.digUp()
sleep(.2)
end
turtle.up()
end
function down()
z = dirZ-1
while turtle.detectDown() then
turtle.digDown()
sleep(.2)
end
turtle.down()
end
function forward()
if facing == 0 then
dirY = dirY + 1
elseif facing == 1 then
dirX = dirX + 1
elseif facing == 2 then
dirY = dirY - 1
else
dirX = dirX - 1
end
while turtle.detect() then
turtle.dig()
sleep(.2)
end
turtle.forward()
end
--[[Figures out whether turtle should mine up or down]]--
function prep()
clear()
print("Which way for height? (DOWN/up)")
local response = read();
if response == "up" or "UP" then
direction = "up"
elseif response == "down" or "DOWN" then
direction = "down"
elseif response == nil then
direction == "down"
else
print("That is not a valid response, please give either 'up', 'down', or just hit ENTER")
sleep(5)
prep()
end
end
--[[Is getting and saving user's input when running the program into proper arguments.]]--
if #args > 0 then
if #args == 1 then
depth, width, height = tonumber(args[1])
elseif #args == 2 then
depth, width = tonumber(args[1])
height = tonumber(args[2])
else
depth = tonumber(args[1])
width = tonumber(args[2])
height = tonumber(args[3])
end
neededFuel = (width*depth*height)+(((width*depth*height)/192)*(width+depth+height))
if neededFuel > turtle.getFuelLevel() then
print("I estimate that I don't have enough fuel for this. I'd need about "..neededFuel)
print("and I only have about "..turtle.getFuelLevel().."\n\n")
print("Are you sure you want to do this? (yes/NO)")
response = read()
if response == "yes" or response == "YES" then
mine();
else
kill()
end
else
mine();
end
else
print("You did not provide enough arguments!\n")
print(">clearArea <depth> <width> <height>")
end