Hello fellow Piconians !
More trouble in paradise. Here now try out this code:
n=0 if n<10 then ::a:: ?"<" end ?"*" flip() n=n+1 goto a |
I want it to always show "<" despite the value of a
Yet, this doesn't run. Now granted I understand that the label a
is inside a conditional loop yet at least in the other programming languages I've worked in that shouldn't make a difference. It does here and comes back and says:
SYNTAX ERROR NO VISIBLE LABEL 'A' FOR <GOTO> AT LINE 11 (TAB 0) |
@zep is this a problem of Pico-8 or inherent in LUA itself ?



It looks like Lua does not support this structure. From https://www.lua.org/manual/5.2/manual.html#3.3.4 :
A label is visible in the entire block where it is defined, except inside nested blocks where a label with the same name is defined and inside nested functions. A goto may jump to any visible label as long as it does not enter into the scope of a local variable.



Pretty sure this is just how it works in Lua @dw817. I don't think it's specific to goto even, just a scoping issue.
The if
block creates a new scope and local variables defined inside won't be visible to the outside. Labels, I believe, behave like local variables which is why you're not able to use a
as a goto target.



Hi @luchak & @jasondelaat:
So the label if inside a loop is independent of the code outside it ?
Wait, so you're saying if I define LOCAL inside an IF statement that its value is lost outside the IF statement ?
Let's see this:
function try() local a=3 local b=4 if a==3 then local b=5 ?b end ?b end cls() try() |
5 4 |
OMy ! What unusual behavior. Languages I've used before would overwrite that upper local with the new one.
Hrrm ... There is still a great deal I do not understand about Pico-8 and LUA for that matter.
Thanks, guys !
Closing out this ticket.
[Please log in to post a comment]