This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Affe3397's profile picture

Need help with a programm

Started by Affe3397, 27 October 2012 - 06:12 PM
Affe3397 #1
Posted 27 October 2012 - 08:12 PM
Hello,
I'm new in computercraft and made a program for stripmining.The turtle is digging correctly but stops after the first correct part.
please help me on this program to make it endless.
Thx Affe3397

The code:

for i=1,3 do
while turtle.detect()==true do
turtle.dig()
os.sleep(0.5)
end
turtle.forward()
while turtle.detectUp()==true do
turtle.digUp()
os.sleep(0.5)
end
end
turtle.turnRight()
for i=1,5 do
while turtle.detect()==true do
turtle.dig()
os.sleep(0.5)
end
turtle.forward()
while turtle.detectUp()==true do
turtle.digUp()
os.sleep(0.5)
end
end
turtle.turnRight()
turtle.turnRight()
for i=1,5 do
turtle.forward()
end
for i=1,5 do
while turtle.detect()==true do
turtle.dig()
os.sleep(0.5)
end
turtle.forward()
while turtle.detectUp()==true do
turtle.digUp()
os.sleep(0.5)
end
end
turtle.turnRight()
turtle.turnRight()
for i=1,5 do
turtle.forward()
end
turtle.turnLeft()
Lyqyd #2
Posted 27 October 2012 - 08:26 PM
To make it truly endless, you could just wrap it in a while true do loop. Try this:


while true do
    for i=1,3 do
        while turtle.detect() do
            turtle.dig()
            os.sleep(0.5)
        end
        turtle.forward()
        while turtle.detectUp() do
            turtle.digUp()
            os.sleep(0.5)
        end
    end
    turtle.turnRight()
    for i=1,5 do
        while turtle.detect() do
            turtle.dig()
            os.sleep(0.5)
        end
        turtle.forward()
        while turtle.detectUp() do
            turtle.digUp()
            os.sleep(0.5)
        end
    end
    turtle.turnRight()
    turtle.turnRight()
    for i=1,5 do
        turtle.forward()
    end
    for i=1,5 do
        while turtle.detect() do
            turtle.dig()
            os.sleep(0.5)
        end
        turtle.forward()
        while turtle.detectUp() do
            turtle.digUp()
            os.sleep(0.5)
        end
    end
    turtle.turnRight()
    turtle.turnRight()
    for i=1,5 do
        turtle.forward()
    end
    turtle.turnLeft()
end

I also removed the unnecessary '== true' from all of the while loops.
Affe3397 #3
Posted 27 October 2012 - 08:34 PM
Thank you for your quick and good help!
Its working^^