9 posts
Posted 02 February 2017 - 05:27 PM
Is there any way to jump in the code . Like in C# you can do someting like that
top:
blablabla
blabl
bbt
bla
test
notimportant
goto top:
1220 posts
Location
Earth orbit
Posted 02 February 2017 - 05:33 PM
Newer versions of Lua support a goto command, but CC Lua does not. I believe the only method of 'jumping around' is to use functions and call them like so…
local function one()
--# do something
end
local function two()
--# do something
end
local function three()
if not x then
two()
else
one()
end
end
9 posts
Posted 02 February 2017 - 05:38 PM
Thanks, didn't think about functions :)/>
7083 posts
Location
Tasmania (AU)
Posted 03 February 2017 - 12:02 AM
Though, if you want to create a loop structure then you should use a loop keyword, such as "while".
http://lua-users.org/wiki/ControlStructureTutorialIf you attempt to repeat a section of code by calling functions over and over then odds are you'll crash out with a stack overflow. Functions which call functions stay in memory, see, and if they're calling themselves recursively then you'll run out of the stuff pretty quickly.
About the one time you'd want to use "goto" is to escape from the middle of a nested loop structure (deep enough that you can't "break" the whole lot in one go). In
that case, since Lua 5.1 doesn't
have "goto", you might instead bundle the whole lot off into a function, which you could then "return" from at any point.