Posted 07 August 2013 - 09:47 PM
Title: Turtle Ignore the last move in the loop
So, I was making a program that would mine the certain area and I have problem that because of the loop, turtle goes one block further than it should go.
This is the code:
I know where the problem is, it is the line function, but I couldn't find a way to solve it.
Simply, I want it to make ignore the last function, forward() on the last loop of the line function.
Please help!
So, I was making a program that would mine the certain area and I have problem that because of the loop, turtle goes one block further than it should go.
This is the code:
local tArgs = {...}
term.clear()
term.setCursorPos(1,1)
print("Digging:")
print(" "..tArgs[1].." blocks Down")
print(" "..tArgs[2].." blocks Forward")
print(" "..tArgs[3].." blocks Side")
term.setCursorPos(18, 9)
textutils.slowPrint("made by okok99haha")
function down()
for i = 1, tArgs[1] do
while not turtle.down()
do turtle.digDown()
end
end
end
function up()
for i = 1, tArgs[1] do
while not turtle.up()
do turtle.digUp()
end
end
end
function forward()
while not turtle.forward()
do turtle.dig()
end
end
function line()
for aa = 1, tArgs[2] do
down()
up()
forward()
end
end
function turn()
turtle.turnRight()
turtle.turnRight()
end
function back()
for ab = 1, tArgs[2] do
turtle.forward()
end
end
function moveLine()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
end
for i = 1, tArgs[3] do
line()
turn()
back()
moveLine()
end
term.setCursorPos(1,11)
print("Done!")
print("Print Any Key to Exit")
os.pullEvent("key")
term.clear()
term.setCursorPos(1,1)
I know where the problem is, it is the line function, but I couldn't find a way to solve it.
Simply, I want it to make ignore the last function, forward() on the last loop of the line function.
Please help!