Hello.
I was writing some code and came across this curiosity.
Now we all know that if you place a comparison inside parentheses that you neither need the THEN or END command.
if (a==b) print("match") |
However I am doing a comparison inside the comparison, nested, and it does not seem to work.
if (x<0) y=y-1 x=5 if (y==12) y=16 |
Any ideas on how to get this to work, guys, without using THEN or END, or is this a BUG ?



Hmmm, can you do this - not near PICO-8 to try it so no warranties expressed or implied :)
if (a==b) y=y-1 x=5 y=y==12 and 16 or y |



like +=, this is a pico8 ‘ease of use’ feature (eg handled by parser before being fed to lua)
been there for ages (forever?)



Hi @2bitchuck:
Oh gosh I wasn't going for obfuscation and my what a tangled web you did weave up there. :)
Nono, I was just thinking maybe I didn't type that correctly or something where you can have 2 IF
on the same line minus THEN
and END
with multiple parentheses.
Well it would ease my use
if it worked. However, if it is patently impossible for 2 IF
to be on the same line minus THEN and END, I will drop the request for a solution.
Thanks for the help, guys !



Yeah- @dw817
This is pico8 preprocessing- it's a hard language limit that only one parenthesis if can work per line- it can have multiple effects, but only one if statement.
If you wanted to be a horrible person who hates babies, you could still one line the code, though.
if (x<0) y=y-1 x=5 y = y==12 and 16 or y
The key here is y = y==12 and 16 or y
. If y does equal 12, then the ternary will turn the statement into y=16 otherwise, you'll get the statement y=y.
Don't do that
It's hard to read just do this
if x<0 then y=y-1 x=5 if (y==12) y=16 end |



Actually that's just what I did, @ReeceGames.
if x<0 then x=5 y=y-1 if (y==11) y=16 end |
I'd rather have clarity over compression any day. :)
I've also gotten out of the habit of using, a-=1
over a=a-1
I know you save a character yet I think the a=a-1
is easier to read.
Personally for any project I've ever written, including full games from the past, I have never run out of memory. Just lucky I guess. :)
[Please log in to post a comment]