Log In  

Surprisingly with all the updates PICO-8 has received, it has one gross error in it that took me hours to debug and later find out and break it into the exact components giving the error alone. It was definitely a case of "it's not my fault." Could cause problems later in other carts and programs.

This will not run:

if (key=="(") print"open"

This will also not run:

if (key==")") print"close"

This will run:

if (key=="[") print"open"

Wow. And no-one's discovered this till now ??

P#67302 2019-09-05 21:02 ( Edited 2019-09-06 04:08)

After correcting the syntax of the if statements (missing 'THEN' and 'END') all of your examples work as expected. Did I miss something?

This:

key = "("

if (key=="(") then 
 print "open"
end

resulted in 'open' being printed.

P#67315 2019-09-06 00:51 ( Edited 2019-09-06 00:55)
1

JasonE, Pico-8 normally allows inline "IF" statements to skip "THEN" and "END" tokens, but only if the conditional is enclosed in parentheses.

Presumably it's not properly detecting the parens.

(This is an extension to Lua. standard Lua always requires the "then" and "end" tokens)

P#67317 2019-09-06 03:09 ( Edited 2019-09-06 03:14)

I see, my mistake. I did quite a bit of lua programming before coming to Pico-8 and made my assumption based on the error when I ran the OP's code. This is the error I get when running:

key = "("

if (key=="(")
 print "open"
'then' expected near 'print'

All in the name of saving tokens I suppose :)

P#67318 2019-09-06 03:41

Yes, JasonE, you missed something. :)

This kind of error should not exist. I knew the solution was to break it to a IF/THEN/END statement. (I'm not that bad a programmer, I hope). I was just surprised to see something so simple create an error.

And no, apLundell, =I= missed something.

I didn't know that LUA required THEN and END for any IF statement ... so the error must go to the nice shortcut ZEP incorporated into PICO that is non-standard with LUA and likely can be easily fixed by said author.

All in all, quite the learning experience.

P#67320 2019-09-06 03:52 ( Edited 2019-09-06 04:05)

Lesson to be learned: sometimes lexing is difficult. ;)

P#67321 2019-09-06 03:59
1

For a workaround until then, you can use escape character encoding to hide the "unclosed" parentheses from the preprocessor.

"(" -> "\40"
")" -> "\41"

i.e.

key="\40"
if (key=="\40") print("open")

P#67322 2019-09-06 04:02 ( Edited 2019-09-06 04:04)

Good solution that, Catatafish. I don't want to convolute my code anymore than it already is though so for now I'll just use IF/THEN/END when comparing character parentheses in a string.

P#67324 2019-09-06 04:06

Yo David, If you could, please get on discord. I might require your expertise

P#67407 2019-09-08 19:17 ( Edited 2019-09-08 19:17)

Let me see if I can finish the cart I'm working on first. Should be no more than a day now.

P#67417 2019-09-09 01:08
1

COMPLETE !
https://www.lexaloffle.com/bbs/?tid=35307

Scrub, I think our ideas are worth sharing.

Pick a new thread in Lexaloffle and I'll join you there to see what I can help you with. We can share our ideas with the rest of the community this way.

P#67444 2019-09-09 20:51 ( Edited 2019-09-09 21:23)

Alright, well I have a game I don't want to share yet, mainly just because of it's pure stupidity. And well to keep it a secret I can't go asking for help compressing an image of the main character.

P#67454 2019-09-09 23:59

You could use my compressor if you want. Minju your games are usually not very big in code size. Could post the image here (or in fresh thread) and I'll write the code to show you how to embed it easily.

P#67455 2019-09-10 00:01

Can I use an example image? Just so my dude isn't shown?
sorry

P#67456 2019-09-10 00:03

This is my example image

P#67458 2019-09-10 00:15 ( Edited 2019-09-10 00:16)

It needs to be 64x64 or 128x128.
If you can, copy and paste it direct from PICO so you can be certain what you're sending me uses the exact PICO palette and is precisely what you're getting.

:)

P#67470 2019-09-10 02:06 ( Edited 2019-09-10 02:07)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 19:50:55 | 0.008s | Q:28