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?

P#25696 2016-07-21 19:46 ( Edited 2016-07-21 23:46)

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)

P#25697 2016-07-21 21:35 ( Edited 2016-07-22 01:35)

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. :(

P#25699 2016-07-21 22:17 ( Edited 2016-07-22 02:17)

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!

P#25701 2016-07-21 22:57 ( Edited 2016-07-22 03:00)

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.

P#25715 2016-07-22 07:01 ( Edited 2016-07-22 11:01)

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".

P#25840 2016-07-24 22:12 ( Edited 2016-07-25 02:13)
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
P#25870 2016-07-25 16:05 ( Edited 2016-07-25 20:10)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 09:22:42 | 0.011s | Q:19