Supporting Modding

I was thinking a bit about what makes the playdate special, and why people would want the playdate over any other handheld. And one thing the Playdate has going for it, is it's open nature. But instead of only banking on the "anyone can make a game for it", it can be spun another way by saying "anyone can mod games for it". I'm not saying, every game should be modable, but it would make sense to put a focus on "modability" of Playdate games. And make development of "mod support" as easy as possible. Meaning to allow people to mod a game without necessarily having access to the source code.

I haven't really made a game with proper mod support yet, so this is all just very early and rough concepts. But I thought it would be helpful to start talking about this somewhere.

So my question would be to other more knowledgeable people:

  • How can we already do modding?
    • I guess all you really need is access to the filesystem (which we have) and then you can load files from a specific folder where people can put their modded files.
    • Custom Data files would be the easiest, like e.g. loading the name, HP and Attack of a custom enemy from a file (and adding them to all the other enemies)
    • Custom Assets (images, audio) should be a bit trickier, since they need to be in a special format, but you could probably have the user pre-process them
    • Custom Lua Scripts on the other hand I have no idea if and how that would work, if you would need to pre-compile them somehow or if they could be somehow added as is.
  • How SHOULD one add mod support?
    • Maybe I've overlooked something and it's all easier/harder than I think.
    • There are probably some best practices I have no clue about.
    • Or approaches to it that are favored by some people.
  • What tools and SDK functions should exist to make adding mod support as easy as possible?
    • Essentially once it's figured out, how to potentially do this, find out concrete things that Panic can add to the tooling or SDK to make adding mod support as painless as possible.

I'm gonna try and create some games with mod support in the coming weeks, and will try to find answers to those questions. Please feel free to answer them before that :slight_smile:

1 Like

I've been planning and implementing this in my game already.

I have an in-game level editor that writes JSON to the game sandbox folder.

In the game I store the following as JSON:

  • levels
  • vehicle physics modifiers
  • surface physics modifiers

Any level can reference one or more PNG files for various layers of graphics. Such as background, foreground, off-road area, hazardous areas, hot spots. Some PNGs are drawn to screen, others are used only for pixel-level collision.

So for a new level modders would generate some images in a paint program, and write or edit some JSON (or use the level editor rather than manually hack JSON).

For a new vehicle some JSON editing to get new handling, plus a sprite sheet to get new graphics. The sprite is time consuming, but I have a (mostly) automated workflow that generates one from 3D and post-processes it to 1bit, which of course I'll happily share with anybody remotely interested.

So, modding for my game is possible right now with no additional work needed. (Because this is how I'm adding my content myself.)

Improvements would only be to make it easier and more manageable. I'll think about those.

4 Likes

I haven't played with the API myself yet, but as I understand playdate.file.load(path, [env]) and playdate.file.run(path, [env]) may enable mods that include custom Lua source code that's been compiled to a PDX binary.

load returns the PDX binary as a callable function, which presumably would run the code and return whatever the module returns from a return statement on the top level? Is that something you can do in Lua?

You can also pass a custom environment as env, which will override the global namespace for the module. You could use that to pass an object that presents hooks into your game that mods can interact with.

3 Likes