Posted 15 July 2012 - 11:03 PM
this is my code for a mining turtle. Can you help me find what's wrong? the error i got was"lua:1:attempt to index ? (a nil value)"
function dig( _input1, _input2, _input3 )
x ::= _input1
y ::= _input2
z ::= _input3
a ::= 0
b ::= 0
c ::= 0
turtle.digDown()
while c < z-1 do –if not at depth z, empty the layer
while b < y-1 do –if not at width y, empty the row
while a < x-1 do – if not a length x, empty the block ahead
if turtle.detect() == false then
turtle.forward()
a = a+1
else
turtle.dig()
turtle.forward()
a = a+1
end
end
if b=0 then –if the first row was just dug, make a left u-turn
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft
b = b+1
else –if the second row was just dug, make a right u-turn
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
b = b+1
end
a=0
end
turtle.turnRight()
for i=1, y-1 do
turtle.forward()
end
turtle.turnRight()
for i=1, x-1 do
turtle.forward()
end
for i=1, 2 do
turtle.turnRight()
end
turtle.digDown()
end
for i=1, z do – get out
turtle.up()
end
end
function dig( _input1, _input2, _input3 )
x ::= _input1
y ::= _input2
z ::= _input3
a ::= 0
b ::= 0
c ::= 0
turtle.digDown()
while c < z-1 do –if not at depth z, empty the layer
while b < y-1 do –if not at width y, empty the row
while a < x-1 do – if not a length x, empty the block ahead
if turtle.detect() == false then
turtle.forward()
a = a+1
else
turtle.dig()
turtle.forward()
a = a+1
end
end
if b=0 then –if the first row was just dug, make a left u-turn
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft
b = b+1
else –if the second row was just dug, make a right u-turn
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
b = b+1
end
a=0
end
turtle.turnRight()
for i=1, y-1 do
turtle.forward()
end
turtle.turnRight()
for i=1, x-1 do
turtle.forward()
end
for i=1, 2 do
turtle.turnRight()
end
turtle.digDown()
end
for i=1, z do – get out
turtle.up()
end
end