Log In  


if state==0 then
if btn(5) then state=1 end
elseif state==1
...
end

^ This gives me a syntax error for an unknown reason... It says: syntax error line 11: if btn(5) then state=1 end 'then' expected near 'if'.

What is that all about?



Have you tried "if btn(5) == true". I've had a few instances where I've needed to make the "true" explicit (same sort of error iirc) not sure why though (I'm a hack programmer at best, I just know that sometimes Ive needed to make it explicit, other times it seems to work with just the bool)


Yep, I tried that. I'm now trying to get this code to work (as it uses less tokens):
if (state==0) then
if (btn(5)) state=1
elseif (state==1)
...
end

However I get the same error. :(


the second example is missing the then statement from line 2.

I just tried this code and it worked...

if state==0 then
if btn(5)==true then
state=1
end
elseif state==1 then
if btn(5)==true then
state=0
end
end

see if that works... good luck!

edit...

tried..
if state==0 then
if btn(5) then
state=1
end
elseif state==1 then
if btn(5) then
state=0
end
end

and that seemed to work as well now...

hopefully someone more experienced can explain!


Well from what I read in the Pico-8 manual the then statement is optional if the code is all on one line. I think there might be a bug in the interpreter.


The "then" was missing from the "elseif" block in your second post, @gitwalrus.

Your first post, however, looks like a bug.

if btn(5) then

should be valid.
You should never need to use "== true".


if state==0 then
  if btn(5) then state=1 end
elseif state==1
  print("one")
end

... has a syntax error with the missing "then", as mentioned. The error message is sensible: "'then' expected near 'print'" But the line number is wrong: line 2, even if I push the elseif down with newlines. So if your elided portion in the elseif block resembles "if btn(5) then..." then the error message might be confusing. Fixing the "then" fixes the error.

if state==0 then
  if btn(5) then state=1 end
elseif state==1 then
  print("one")
end


[Please log in to post a comment]