Log In  

Cart #constantcompanion-8 | 2022-09-02 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA


This is a niche tool to help you save characters when writing carts that are codesize-constrained.

  • type in a number; press enter
  • then press up/down and ctrl-c/enter to copy a code
  • navigate back up (or press backspace) to start typing a new number

Example: 0x6000 can be written as 0x6000 (6 chars), 24576 (5 chars), 6^13 (4 chars) or ⌂-🐱 (3 chars!)

The tool sorts the results by character count (on twitter), so the top results are your best bet.

Update: The latest versions of pico8 have special P8SCII codes for poking which are often fewer characters than calling poke directly (even after using this tool). e.g. ?"\^!5f10249?" instead of poke(0x5f10,50,52,57,63). Consider using that instead! But this tool might still be useful sometimes, and at the very least, it's an interesting artifact.


While I was making Free Cell 1K (itch | twitter | bbs) for the #Pico1K jam, I realized I could save characters by taking advantage of the built-in constants. I needed to poke a few things to various addresses (for setting the palette, drawing dynamic shadows with bitplanes, and enabling the mouse) so I had code that looked like this:

-- 94 chars (not including comments or newlines)
poke(0x5F10,8,1,251,7,4,0,3,15) --palette
poke(0x5F2D,3) --mouse
poke(0x5F5C,-1) --disable btnp repeat
poke(0x5F5E,0xF4) --shadows on
poke(0x5F5E,0xFF) --shadows off

Each of those poke addresses uses 6 characters; we can do better! The first thing I did to save characters was this:

-- 84 chars (not including comments or newlines)

But then I saw @zep tweet a trick for writing sqrt(x) as x^█ instead (because █ (shift+A) is defined to have a value of 0.5), and I realized I could do even better: the 😐 (shift+M) character is defined to have a value of -24351.5, so I did this:

-- 95 chars (not including comments or newlines)

95 chars is not an improvement... yet! However, poke() ignores fractional addresses, so those .5s aren't necessary. Also, I was able to combine the 0x5F5C and 0x5F5E pokes into a single poke, which nullifies some of the relative advantage of the A=24365 technique. In the end, this was the shortest code I could find:

-- 64 chars (not including comments or newlines)

This saves 2 characters over the equivalent version that uses A=24365 instead of the moon face. (or maybe just 1 character, if the newline after q=poke2 can't be removed)

how did you know moon face was the one to use?!

I didn't! I wrote a program to brute-force try all the built-in symbols and see if any were useful for my needs. Check out tab 5 of the cart ("analysis") to see the brute-force algorithm I used.

I've cleaned that program up and posted it here for you. It might be less useful for tweetcarts (because stuff like 😐 takes up 2 characters on twitter) but it saved me 1~2 entire characters (genuinely very helpful!) during the Pico1K jam, and I hope it helps you too.

Leave a message here or tag me on twitter if you found it useful; I'd like to see what you make!

how does it work?

  1. build a list of all 150 "symbols" under consideration:
    • █▒🐱░✽●♥☉웃⌂😐♪◆…★⧗ˇ∧▤▥ (most symbols)
    • the numbers 0-9
    • and the negated version of everything above
    • the numbers 10-99 (but not their negated versions)
  2. try combining every pair of symbols a,b with these operations:
  3. if any result is between target and target+1, display the result. this was chosen because poke/memset/etc round their inputs down to the nearest integer. custom checks are easy to hack in yourself; search for "function near" in the code


  • v8:
    • add support for new pico-8 syntax a~b for bitwise not (1 char shorter than the old a^^b)
    • sort results by twitter character count instead of naive character count. thanks to jadelombax for the handy reference table here: https://www.lexaloffle.com/bbs/?tid=44375
  • v7: fix typo in v6
  • v6:
    • fix exponentiation parse order (-a^b gets parsed by pico8 as -(a^b), unlike any other operation on the list)
    • increase list scroll speed
    • clean up output list results a bit (e.g. no more -a+b, since b-a is shorter)
    • remove ~x from consideration; it's very similar mathematically to -x, so calculating it was making all searches slower for hardly any benefit. (the code is commented out, so you can re-add it yourself pretty easily if you download the cart and search for ~)
    • make it easier to do custom "is close enough" checking; search for "function near" in the code
  • v5: show options (and allow them to be copied) as soon as they're found. (no longer need to wait for the entire search to complete)
P#97937 2021-09-28 21:48 ( Edited 2022-09-02 22:49)



Thank you - this will be VERY useful! 🤓👍

P#98001 2021-09-29 19:12

Silly, but useful, nice job!

P#98024 2021-09-30 03:18

I am just now seeing this for the first time. It reminds me of the way I compress some data tables. I check to see which is smaller, a compression block or decompressed block.

Your Constant Companion @pancelor will definitely aid Twitter coders. Nicely done ! Gold star.

I am a little confused though. Shouldn't 5 return as ❎ ?

P#106360 2022-02-05 00:07 ( Edited 2022-02-05 00:20)

thanks! the tool has a big list of possible inputs including "5", "😐", and other single-character symbols, but it doesn't include "❎" -- because you can just type "5" instead ;)

P#106372 2022-02-05 02:32

Well it wasn't so much the fact it matched the same character size, @pancelor. I was wondering if you were checking every possible combination and permutation of creating an alternative method of either calculating or replacing the value with matched glyphs.

P#106375 2022-02-05 03:51

Wow. I just tried running your code, @pancelor, and it crashes straight out in immediate mode. Online too. I ran it in immediate mode though so I could F1 the screenshot to show you.

P#109692 2022-04-04 17:06

whoops, silly mistake on my part. thanks for the heads up -- fixed!

P#109700 2022-04-04 19:30

[Please log in to post a comment]