Skip to content
This repository has been archived by the owner on Oct 24, 2020. It is now read-only.

Error: 'then' expected #23

Open
tobiasvl opened this issue Aug 9, 2018 · 2 comments
Open

Error: 'then' expected #23

tobiasvl opened this issue Aug 9, 2018 · 2 comments

Comments

@tobiasvl
Copy link

tobiasvl commented Aug 9, 2018

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.

@tobiasvl
Copy link
Author

tobiasvl commented Aug 9, 2018

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.

@tobiasvl
Copy link
Author

tobiasvl commented Aug 9, 2018

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

@tobiasvl tobiasvl mentioned this issue Oct 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant