I often see questions in the pico-8 discord's #help channel, questions that boil down to "my code isn't doing what I want, and I don't know what to do. help?" If you feel completely lost when your code doesn't work, this tutorial is for you! Or anyone really -- I personally use PRINTH/PQ constantly and it makes programming about a hundred times easier.
PRINTH ("print to host console") is the single most helpful tool I know for pico-8 debugging. When programming, your head can get out of sync with the computer, and you won't understand what it's doing. The best way I know to bring them back in sync is to slap down some PRINTHs all over the place! Print out some info to see what your code is actually doing, and figure out exactly where the code starts to stray from what you intended.
setup
Here's a video showing how to launch pico-8 with an attached console on Windows. You'll need to do this somehow, because PRINTH messages are only visible in the attached console.
The first 30 seconds of the video show how to create a shortcut to pico8.exe, and then edit that shortcut's "target" so that it will run from a console. After making it, you can move this shortcut anywhere you want.
The rest of the video walks through a simple debugging scenario, and ends by showing off PQ (see explanation below)
Linux/Mac:
PQ
PRINTH itself can be a bit annoying to use, so I built a function called PQ that's nicer to use. Feel free to copy it into any of your projects. If you find my functions helpful and you'd like to credit me, I'd appreciate it!
PRINTH annoyances
PQ library code
why not just PRINT?
Why go to the trouble of setting up a host console and printing there with PRINTH/PQ instead of just printing to the screen with PRINT? A few reasons:
- If you PRINT during the _UPDATE half of your game, those prints will be overwritten by the CLS at the start of your _DRAW function.
- Your game has bugs that you're trying to track down, that's why you're debugging. Are you sure that those bugs aren't somehow preventing or overwriting your PRINT statements?
- You can PRINTH the same thing on multiple frames then scroll through the history in the host console.
There's just too much extra stuff that happens between PRINT and when your eyes see the results. You want to be confident that your debugging system doesn't itself have bugs, so dumping the text as fast as possible (to the host console) is perfect.
If you can't/won't set up a host console for some reason, STOP is an ok alternative to PRINTH. Call stop("x="..tostr(x))
or stop(qq("x=",x))
, then type r
to resume your game after it hits the STOP statement.
example cart
This cart isn't too interesting to play, but I put it here to make it easy to download (load #printh_helpers
)
Alright that's it, my One Secret Trick for programming/debugging. Let me know if you found this helpful!



Excellent tutorial! I'm surprised it's so easy to do, I'd expect you'd have to make some PICO-8 game to receive it.



yes, sometimes I use a mac and I open Terminal in the folder where pico8 lives and run ./pico8
(I'm unsure what the exact name is). then the Terminal window stays open and the printh output is shown in that terminal.
I'm not happy with that setup, there's probably a more convenient way to do it. but I'm hardly ever on mac -- someone else would be able to make better instructions than me



pq() is super useful, was looking for something like this. Thanks!



I finally made an account purely to be able to comment that this is a game changer, thank you so much for putting this together. Just making my way through a tutorial and got stuck on a bit - haven't worked out what exactly is wrong yet, but I have so much more visibility about what's happening under the hood!
[Please log in to post a comment]