How to add debug-only functionality

Something common in other game SDKs is the ability to know whether or not your game is running in a debug build or a release build. This is useful for providing developer-only shortcuts, showing FPS, and other useful information when working on a game. I've been wanting this for my Playdate games, and I came up with what feels like a pretty simple yet useful solution: check the playdate.metadata.version for a "-dev" at the end to determine if it's a debug build.

Whenever I'm working on a project, between releases, I append -dev to the version in pdxinfo so that it's clear it's not a release build. All one then has to do is check this and use it accordingly.

Let's say this is your pdxinfo:

name=My Game
version=1.2-dev

Then in your code, if you have a global settings table, you can set isDebug
and then check it accordingly:

settings = {}
settings.isDebug = string.find(playdate.metadata.version, "-dev") ~= nil

-- somewhere else, like in your playdate.update:

if settings.isDebug then
    playdate.drawFPS(12, 12)
end

When it's time to create a release for your game, you would update the version and the buildNumber in pdxinfo. The version for that release build won't have -dev appended, so settings.isDebug would evaluate to false.

There are lots of possibilities for what you could do with this:

  • Add a debug-only menu to help jump to specific states in your game
  • Output additional logs that you wouldn't otherwise output
  • Check for keyboard input in the Simulator with playdate.keyPressed()

Hopefully this helps anyone wondering how to go about this. And if you have a different approach for this, I'd love to learn about it!

3 Likes