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

Goto and stuff...

Started by Evil_Bengt, 15 October 2014 - 05:59 AM
Evil_Bengt #1
Posted 15 October 2014 - 07:59 AM
This may not be as cc related as any other topics but is there any "goto"-command in Lua, like the one in batch when you can tell the program to continue from a certain line…?
Would be nice to know as that would help to make a turtle that can continue from where it left off….

Thanx
Edited on 15 October 2014 - 06:35 AM
Bomb Bloke #2
Posted 15 October 2014 - 10:35 AM
There is in Lua 5.2 (and presumably later), but Lua 5.1 (as incorporated by ComputerCraft) lacks it.

There are other ways to get a turtle to "continue where it left off", but the specifics vary depending on what it is the turtle actually does.
ShadowDisruptor #3
Posted 16 October 2014 - 12:51 AM
Not sure if this is what you mean, but you could break your code into functions and do it something like this:


function Function1()
  print("Hello world 1!")
end

function Function2()
  print("Hello world 2!")
end

function Function3()
  print("Hello world 3!")
end

Function3()
Function2()
if x > 3 then
   Function1()
end
if x < 3 then
   Function2()
end

EDIT:
As for the left off thing, you could do this

leftOff = 0
function Function1()
  print("Hello world 1!")
  leftOff = 1
end

function Function2()
  print("Hello world 2!")
  leftOff = 2
end

function Function3()
  print("Hello world 3!")
  leftOff = 3
end

if leftOff == 1 then
  Function2()
elseif leftOff == 2 then
  function3()
elseif leftOff == 3 then
  Function1()
else
  print("Error! Left off not valied!")
end
Edited on 15 October 2014 - 10:54 PM
Evil_Bengt #4
Posted 16 October 2014 - 07:17 AM
There is in Lua 5.2 (and presumably later), but Lua 5.1 (as incorporated by ComputerCraft) lacks it.

There are other ways to get a turtle to "continue where it left off", but the specifics vary depending on what it is the turtle actually does.

oh ok.. too bad…

Well thanx anyways

Not sure if this is what you mean, but you could break your code into functions and do it something like this:


function Function1()
  print("Hello world 1!")
end

function Function2()
  print("Hello world 2!")
end

function Function3()
  print("Hello world 3!")
end

Function3()
Function2()
if x > 3 then
   Function1()
end
if x < 3 then
   Function2()
end

EDIT:
As for the left off thing, you could do this

leftOff = 0
function Function1()
  print("Hello world 1!")
  leftOff = 1
end

function Function2()
  print("Hello world 2!")
  leftOff = 2
end

function Function3()
  print("Hello world 3!")
  leftOff = 3
end

if leftOff == 1 then
  Function2()
elseif leftOff == 2 then
  function3()
elseif leftOff == 3 then
  Function1()
else
  print("Error! Left off not valied!")
end

Hmm…. yeah that could work, thanx alot :D/>