Log In  

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 ?

P#121727 2022-12-02 16:42 ( Edited 2022-12-02 18:54)

1

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
P#121729 2022-12-02 16:48

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

been there for ages (forever?)

P#121734 2022-12-02 17:23

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.

@freds72:

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 !

P#121735 2022-12-02 18:52

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
P#121767 2022-12-03 08:42 ( Edited 2022-12-03 08:42)
1

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

P#121773 2022-12-03 17:45

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 16:59:59 | 0.031s | Q:19