Posted 30 December 2012 - 08:28 AM
Hi everyone. I have recently started programming for Computercraft and I am trying to write my own auto quarry (with custom dimensions) that dumps items in a chest when its inventory gets full. Here is the code below. It is quite messy right now, I am still testing it.
The code runs fine when I have an even Z value however when Z is odd (for example 3) it only runs an even number of times in function calculate (the part in bold). When I set Z to 3 that code should run twice and the else code once, however it does not run the second time. Please help me!
X = tonumber(read())
Y = tonumber(read())
Z = tonumber(read())
B = 0 -- Used to calcualte the turtles position.
C = 0 -- Used to calculate the turtles position.
D = 0 -- Used to calculate the turtles position.
A = 2
X = X - 1
Z = Z - 1
function mine()
while turtle.forward() == false do
if turtle.dig() == false then
turtle.attack()
end
end
end
function lineforward()
for num=1, X do
mine()
B = B + 1
end
end
function linebackward()
for num=1, X do
mine()
B = B - 1
end
end
function calculate()
if math.fmod(A, 2) == 0 then --This part of the code does not run the extra time with an odd Z value.
lineforward()
turtle.turnLeft()
mine()
turtle.turnLeft()
D = D + 1
else linebackward()
turtle.turnRight()
mine()
turtle.turnRight()
D = D + 1
end
A = A + 1
end
function level()
turtle.dig()
turtle.refuel(1)
turtle.forward()
turtle.turnRight()
for num=1, Z do
calculate()
end
end
level()
The code runs fine when I have an even Z value however when Z is odd (for example 3) it only runs an even number of times in function calculate (the part in bold). When I set Z to 3 that code should run twice and the else code once, however it does not run the second time. Please help me!