Posted 08 September 2012 - 03:06 PM
How to loop a program?
while true do
for i = 1,var do
end
repeat
var = var+1
until var == 8
while not turtle.forward() do
turtle.dig()
end
*whistles* Take a pick. There's infinite loops likewhile true do
terminating likefor i = 1,var do end
or wait until a condition is met likerepeat var = var+1 until var == 8
or while something is happening like if your turtle can't go forward:while not turtle.forward() do turtle.dig() end
It's more of a question of "What do I use for this program?"
Hope that helps!
inventory=1,16
sapling=1
bonemeal=2
wood=3
fuel=16
function chop()
turtle.dig()
turtle.digUp()
end
function moveup()
turtle.up()
end
function replant()
turtle.select(sapling) while turtle.place(sapling) do
turtle.select(bonemeal) while turtle.place(bonemeal) do
end
end
if turtle.getItemCount(sapling) <20 then
turtle.turnRight()
turtle.select(1)
turtle.suck(1)
if turtle.getItemCount(bonemeal) <20 then
turtle.select(2)
turtle.suck(2)
turtle.turnLeft()
end
end
end
function bank()
if turtle.getItemCount(wood) >25 then
turtle.turnRight()
turtle.select(wood)
turtle.drop()
turtle.turnLeft()
end
end
if turtle.getFuelLevel() <100 then
turtle.refuel(fuel)
end
while turtle.detect() do
print ("Chopping")
chop()
print ("Moving Up")
moveup()
end
print ("Moving Down")
while not turtle.detect() and not turtle.detectDown() do
turtle.down()
end
print ("Replanting")
replant()
print ("Banking")
bank()
turtle.select(1)
You have several loops there. Do you want it to constantly run that program? Use "while true do" and put "end" at the very bottom.
function run()
--your whole looping code
end
function quit()
while true do
input = io.read()
if input == "stop" then
break
end
end
parallel.waitForAll(quit, run)