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

[SOLVED] [Question] How to make program never end?

Started by Agenerick, 16 January 2013 - 03:22 AM
Agenerick #1
Posted 16 January 2013 - 04:22 AM
I am making now a program to automaticaly chop down rubber trees (FTB mod pack :D/>) and I want to make the program never reach end. That's the code:


function Up()
  turtle.up()
end
function Dig()
  turtle.dig()
end
function DigUp()
  turtle.digUp()
end
function Dw()
  turtle.down()
end

while turtle.detectDown() do
  turtle.select(1)
  turtle.place()
  Up()
end

while turtle.detect() do
  Dw()
  Dig()
  Up()
  Dig()
  DigUp()
  Up()
  Dig()
  DigUp()
  Up()
  Dig()
  DigUp()
  Up()
  Dig()
  DigUp()
  Up()
  Dig()
  DigUp()
  Up()
  Dig()
  DigUp()
  Up()
  Dig()
  DigUp()
  Dw()
  Dw()
  Dw()
  Dw()
  Dw()
  Dw()
  Dw()
end
I know, it's so loong, please don't be mad…
zekesonxx #2
Posted 16 January 2013 - 04:29 AM
Wrap it in:

while true do
  code()
end

Also check out:

for i = 1,7 do
  Up()
  Dig()
  DigUp()
end
Agenerick #3
Posted 16 January 2013 - 04:36 AM
Wrap it in:

while true do
  code()
end

Also check out:

for i = 1,7 do
  Up()
  Dig()
  DigUp()
end
I think You don't understand what I wanna do. I want to make the program repeat without end, because the tree must grow. I'll try doing the whole code as function.

@EDIT:
Ok, now, it's working, thanks! :D/>
theoriginalbit #4
Posted 16 January 2013 - 04:39 AM
I think You don't understand what I wanna do. I want to make the program repeat without end, because the tree must grow. I'll try doing the whole code as function.
Making an infinite loop.

while true do
  -- code to infinitely loop goes here
end