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!
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?
@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)
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!
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.
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 end print(test"5") -- fine print(10 + test"5") -- also fine x = 10 x += test"5" -- unexpected symbol near '5' print(x)
Do you want this in the "Calling Functions with Strings" caveat section as example code, or just a note?
[Please log in to post a comment]