Posted 19 December 2012 - 04:47 AM
So I'm trying to make a program for a mining turtle that'll dig out a room x by y by z blocks. So far I've gotten it to dig out a 3x3x3 space, except at the end of its last loop, it repeats it's "dig up, go up" command. So I thought I'd make it detect if it was the last iteration of the loop with a simple if command, but it would not detect that. I even put some print() functions in that prove that the two variables are equal, but the if then does not run. Here's the code I have so far if that'll help. (x, y, and z are values you give the turtle.)
for i=1,z do
for i=1,(x-1) do
turtle.dig()
turtle.forward()
end
for i=1,(y-1) do
if (i % 2 == 0) then
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
elseif (i % 2 == 1) then
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
end
for i=1,(x-1) do
turtle.dig()
turtle.forward()
end
end
--Problem Code: It should print "It worked" and stop the loop when i is equal to z
print(i)
print(z)
if (i == z) then
print("It worked")
break
end
--x
if not (i == z) then
turtle.digUp()
turtle.up()
turtle.turnLeft()
turtle.turnLeft()
end
end