Log In  

Forgot to post this here the other day: PICO-8-Token-Optimizations

Lots of people working on larger projects (or more topically, the collab16 games) end up hitting the token limit, and people in the PICO-8 community have come up with plenty of handy tricks to deal with that. Some of them are common knowledge or pretty easy to figure out on your own, but others are a bit obscure, so I figured it'd be useful to compile a list of general purpose tricks and techniques for cutting down your tokens.

If you know of any handy tips that aren't listed or have any corrections/improvements, feel free to let me know or contribute to the repository!

P#29581 2016-09-28 11:08 ( Edited 2016-09-30 20:56)

Great list, very nice!

P#29583 2016-09-28 11:35 ( Edited 2016-09-28 15:35)

Thanks seleb! Should be pretty useful to have a common repository for these.

The manual states that periods are not counted as tokens:
"commas, periods, LOCALs, semi-colons, ENDs, and comments are not counted."

But after doing a quick test, they do seem to count as tokens as stated on your guide. I wonder if the manual is referring to a different usage-context for periods or if this is a bug on the token count system?

P#29595 2016-09-28 12:48 ( Edited 2016-09-28 16:48)

Some pretty cool notes, Seleb ! I code pretty tightly so hopefully I won't need these. But they are there if I do !

P#29600 2016-09-28 13:50 ( Edited 2016-09-28 17:50)

@guerragames: are you talking about the section about replacing table access with locals? I think what's actually going on is that "table.property" is 2 tokens, but the tokens are "table" and "property", with a free period in between.

The other thing to remember is that ".." is the string concatenation operator, so if you checked if periods counted by opening PICO-8 and typing in a bunch of periods, you'd end up with a non-zero token count, but none of them would actually be "periods". (this was the first thing I did when I saw your post and it confused me for a minute)

P#29603 2016-09-28 14:32 ( Edited 2016-09-28 18:32)

Yeah, i was talking about "table.property"... which makes a lot of sense now if you think about it how you described it. For some reason I was hoping it would consider it as a whole variable without taking the dereferencing into account.... well, more opportunities to get some tokens back!

P#29607 2016-09-28 15:44 ( Edited 2016-09-28 19:44)

Aw shit...well no wonder my "small" games end up high in tokens. I understood the free periods just like Jose mentioned, that "player.hp" is 1 token and not 2. And I've been using that notation all over the place.

I was basically over-architecting my games. I guess it's a reminder that basic games need basic code...or close to it.

Super good to know now plus all the optimization stuff.

P#29615 2016-09-28 16:51 ( Edited 2016-09-28 20:51)

While applying the calling functions with strings transform on my code, I ran into an issue with the arithmetic-equals operators:

function test(n) 
    return flr(rnd(n)) + 30

print(test"5") -- fine
print(10 + test"5") -- also fine
x = 10
x += test"5" -- unexpected symbol near '5'

Do you want this in the "Calling Functions with Strings" caveat section as example code, or just a note?

P#29749 2016-09-30 16:56 ( Edited 2016-09-30 20:56)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-05-29 06:14:05 | 0.015s | Q:18