Posted 08 September 2012 - 05:37 AM
I'm trying to write a program similar to the built in excavate program but more tailored to how I like to do things with my extremely limited abilities and knowledge of coding. It's late and I'm tired, and basically I can't spot why I'm getting the error: Quarry:40: attempt to call nil. Please keep in mind that the program is currently incomplete and will currently only work with odd valued widths.
term.clear()
term.setCursorPos(1,1)
print("Input length of area to be quarried: ")
input1 = read()
print("Input width of area to be quarried: ")
input2 = read()
print("Input current height: ")
input3 = read()
print("Input desired stopping level: ")
input4 = read()
length = input1
width = input2
height = input3-1
bottom = input4
x = 0
z = 0
a = 0
b = 0
i = 0
currentHeight = height
number = input2
level = height-bottom
y = currentHeight
odd = "false"
even = "false"
odd2 = "false"
even2 = "false"
aboveBottom = bottom+1
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Length will be "..length..", width will be "..width..", height is "..height..", and digging will stop at level "..bottom..".")
print("Is this correct?")
input5 = read()
if input5 == "yes" then
term.clear()
term.setCursorPos(1,1)
print("Engaging quarry process")
sleep(2)
commenceDigging()
else
print("Session terminated")
sleep(1)
term.shutdown()
end
function checkHeight(level)
if level%2 == 0 then
even2 = "true"
else
odd2 = "true"
end
end
function check(number)
number = input2
if number%2 == 0 then
even = "true"
else
odd = "true"
end
end
function commenceDigging()
check(number)
checkHeight(level)
if odd == "true" then
if odd2 == "true" then
while currentHeight>bottom do
if currentHeight == aboveBottom then
b = width
while b>0 do
if b == 1 then
clearRowRedAlpha()
else
clearRowRedAlpha()
nextRowLeft()
clearRowBlueAlpha()
nextRowRight()
end
end
else
clearLayerOddAlpha()
clearLayerOddBeta()
end
end
turtle.turnRight()
while z>0 do
turtle.forward()
z = z-1
end
turtle.turnRight()
while x>0 do
turtle.forward()
x = x-1
end
while currentHeight<height do
turtle.up()
currentHeight = currentHeight+1
end
dumpInventory()
end
end
end
function clearLayerOddAlpha()
b = width
while b>0 do
if b == 1 then
clearRowRedAlpha()
nextLayerOddAlpha()
else
clearRowRedAlpha()
nextRowLeft()
clearRowBlueAlpha()
nextRowRight()
end
end
end
function clearLayerOddBeta()
b = length
while b>0 do
if b == 1 then
clearRowRedBeta()
nextLayerOddBeta()
else
clearRowRedBeta()
nextRowRight()
clearRowBlueBeta()
nextRowLeft()
end
end
end
function clearRowRedAlpha()
a = length
while a>0 do
turtle.dig()
turtle.forward()
x = x+1
a = a-1
end
b = b-1
z = z+1
end
function clearRowRedBeta()
a = width
while a>0 do
turtle.dig()
turtle.forward()
z = z-1
a = a-1
end
b = b-1
x = x-1
end
function clearRowBlueAlpha()
a = length
while a>0 do
turtle.dig()
turtle.forward()
a = a-1
x = x-1
end
b = b-1
z = z+1
end
function clearRowBlueBeta()
a = width
while a>0 do
turtle.dig()
turtle.forward()
a = a-1
z = z+1
end
b = b-1
x = x-1
end
function nextRowLeft()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
end
function nextRowRight()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
end
function nextLayerOddAlpha()
turtle.digDown()
turtle.down()
turtle.turnRight()
currentHeight = currentHeight-1
end
function nextLayerOddBeta()
turtle.select(16)
if turtle.getItemCount() then
y = currentHeight
while y<height do
turtle.up()
y = y+1
end
turtle.turnRight()
dumpInventory()
while y>currentHeight do
turtle.down()
y = y-1
end
turtle.digDown()
turtle.down()
currentHeight = currentHeight-1
else
turtle.digDown()
turtle.down()
turtle.turnLeft()
currentHeight = currentHeight-1
end
end
function dumpInventory()
for i=1,16,1 do
turtle.select(i)
turtle.drop(64)
end
shell.run("turn","left",2)
end