Pico-8's built in retro limitations even extend to the code storage, and the sound storage.
Staying under the token count was a fun challenge. It certainly makes you find simpler ways of achieving the same thing, which is always good. Although this arbitrary limitation imposed by Pico 8 seems strange in todays world of gigabytes of RAM to work with, the problem solving you go through will be good experience for solving real optimisation problems on modern systems.
Having said that, the "compressed code limit" on top of this, comes as somewhat of a surprise. The manual states that you will run into the 8k token limit before the compressed code limit. But I continually found the inverse to be the case. At about 7k tokens (still 1k under the limit) the "compressed code" size was 30k bytes, twice the 15k limit. Even with all the text in the game removed it barely made a dint. I already use single letter variable names for frequently used variables, and I tried replacing function names and variable names with shorter versions of themselves and realised very quickly this wasn't going anywhere.
NOTE: It's debatable whether or not the limits on the code is where it should be, but I understand that the limit must be drawn somewhere to keep the spirit of the retro development goals of Pico8. And if we want to make a project using minimalist graphics but no code or tile map size limit (which would be very cool) there are other similar engines like Pico8 that are suited for this! Such as PicoLove, TIC-80, LIKO-12 and Pixel Vision 8, and of course, my favourite - just taking one of the mainstream game engines that are well suited to 2D, like Unity, Godot, or Defold, and just make your own little "meta engine" inside it, get all the benefits of that engine, such as multiplatform support, and no limitations!
It was only when I tried out PicoTool that I finally overcame this hurdle. Although you end up with an unreadable mess, so you want to edit it yourself, the pre-PicoTool, un-garbled code is here. But that is exactly at the token limit! No room for edits... so I've also provided this slightly earlier version, which gives you a bit of breathing room if you want to experiment, it's missing some tweaks that the final game has, which are bug fixes and extra minor features like the level intro. The final program has the token count maxed, and is about 25k compressed bytes, before running through PicoTool, which brings it down to 9k.
I started out replicating the music note for note. I used my MIDI USB keyboard and OpenMPT to rough it out (was easier) and then transposed the notes into Pico8. But to achieve the mulitiple harmonies, you use a new "sound effect" in the sound effect index for each instrument track, and I very quickly ran out of sound effect indexes.
So I did what other music developers did back in the day and use the arpeggio effect (the trilling notes you hear) which switch between 2 notes rapidly to give the impression of 2 notes being played at the same time. Pico-8's music tracker has a built in effect for this, like all good music trackers of the time, though it's got some strange limitations. Using this arpeggio trick, I came up with simpler versions of songs with less simultaneous notes (some are just a drum track and a melody!) and in the end, used far less sound effect indexes and was able to cram in all of the songs I wanted to - a total of 7, listed below. As you can see, every last sound index was used, I maxed it out, like the token count.
Music patterns:
00: Main theme
06: Death
07: Water theme
23: Bike theme
27: Janken game
31: Heli theme
33: Castle theme
39: Game over
Sound effect indexes:
00: Jump
01: Punch
02: Main theme: Bass Intro
03: Main theme: Melody Intro
04: Main theme: Bass 1
05: Main theme: Melody 1
06: Main theme: Bass 2
07: Main theme: Melody 2
08: Main theme: Base 3
09: Main theme: Melody 3
10: Main theme: Base 4
11: Main theme: Melody 5
12: Main theme: Percussion 1
13: Main theme: Percussion 2
14: Main theme: Percussion 3
15: Shoot
16: Block break
17: Coin
18: Game Over
19: Castle Theme: Melody 1
20: Castle Theme: Melody 2
21: Monster death
22: Angel: Melody
23: Angel: Harmony
24: Water hit
25: Water hit bass
26: Powerup pickup: Melody
27: Powerup pickup: Harmony
28: Laser Ring
29: Water theme: Bass 1
30: Water theme: Bass 2
31: Water theme: Bass 3
32: Water theme: Bass 4
33: Water theme: Melody 1
34: Water theme: Melody 2
35: Castle Theme: Melody 3
36: Castle Theme: Melody 4
37: Water theme: Melody 3
38: Water theme: Melody 4
39: Castle Theme: Melody 5
40: Pedicopter theme: Bass 1
41: Water theme: Solo 1
42: Water theme: Solo 2
43: Water theme: Solo 3
44: Water theme: Solo 4
45: Water theme: Solo 5
46: Water theme: Solo 6
47: Frog bubbles
48: Water theme: Percussion loop
49: Bike theme: Melody 1
50: Bike theme: Bass 1
51: Pedicopter theme: Bass 2
52: Bike theme: Melody 2
53: Janken match theme: Percussion 1
54: Bike theme: Bass 2
55: Bike theme: Melody 3
56: Janken match theme: Melody 3
57: Bike theme: Bass 3
58: ?? Percussion?
59: Janken match theme: Melody 1
60: Janken match theme: Melody 2
61: Castle theme: Percussion loop
62: Pedicopter theme: Melody 1
63: Pedicopter theme: Melody 2
You can compare the difference if you listen to this early version of the game, which has the first level and water level music, pretty much sounding as they do in the original game (don't play past the water level, it will crash because there's nothing else), and compare it to the music in the final release, by listening to it in this Alex Kidd in Pico World playthrough, where I used arpeggios to simulate harmonies, to cut down space requirements.
If you like this sort of thing, join the discord and/or subcribe to the newsletter, and I'll let you know when I upload more articles like this. I also have a Discord server where we can chat about game dev.