BlueAmulet/picolove

Error: 'then' expected

Opened this issue · 2 comments

Does picolove not support the one-liner if?

Error: Error loading lua: patrick.p8:75: 'then' expected near 'menu_selection'
stack traceback:
        [string "boot.lua"]:637: in function <[string "boot.lua"]:633>
        [C]: in function 'error'
        cart.lua:429: in function 'load_p8'
        main.lua:140: in function '_load'
        main.lua:348: in function 'load'
        main.lua:719: in function <main.lua:711>
        [C]: in function 'xpcall'
        [string "boot.lua"]:650: in function <[string "boot.lua"]:639>
        [C]: in function 'xpcall'

Here's line 75:

    if (button==4) menu_selection=menu_selection==1 and #menu or menu_selection-1

I tried to replace it with a full if/end block but that just made it complain on another similar line.

The cart in question is here on GitHub, but I have the same problem with all my carts since I use the same boilerplate menu system.

OK, sorry, it's obviously supported, just not fully.

It supports multiple statements and an else branch, but apparently it doesn't support the same kinds of statements in its body as PICO-8. In this case, it seems that it fails to parse a one-line if body that has a ternary boolean statement. All others seem to work fine.

Other examples that don't work:

From the same cart as in the original comment:

if (destroyed==0 and mode==modes.play) local s=buttons.x..": skip" print(s,128-((keyboard and 7 or 8)*4),0,7)
if (patrick.x>0) local s=buttons.o..": play" print(s,128-((keyboard and 7 or 8)*4),0,7)                                                                                                                    

From this cart:

if (edit) level.start_pos={x=xpos/8,y=ypos/8}
if (lvl>9) x-=2