Pulp Game Switchers

Building a simple game in Pulp is easy. Sometimes too easy, and your little game grows into a big one—so big that the editor or the runtime can struggle to run it. Maybe your game has a handful of modes and it makes sense architecturally to split them into separate modules for easier authoring. Or maybe you and some friends created a bunch of little Pulp games that you want to release as a single Playdate game. Here are two techniques to help you share your vision of a larger, multi-part Pulp game with the world.

1. The original act-based switcher

This approach is designed to work like a “Please change disk” screen from early computers and CD-based home consoles. When reaching the end of a game “act,” the game will prompt the player to open the system menu and manually change the act.

Switcher.zip (277 KB)

How it works

First, your game should be split up into multiple acts as individual Pulp games.

When it comes time to switch to the next act, the game should set gotoAct to the target act number, call store "gotoAct" then store (to force the write), and present a screen to the player telling them to open the system menu, change to that act, and dismiss the menu.

One possible way to do that is to add the following to your Pulp game object’s load event handler:

on load do
	thisAct = 1 // unique to each act
	restore
end

And this to the game object’s loop event handler:

on loop do
	if gotoAct>0 then
		if gotoAct!=thisAct then
			say "Switch to Act {gotoAct}"
		end
	end
end

You could also use goto to move the player to another room that acts as a custom prompt screen. Just remember that the loop event handler is called every frame so you’ll want to add an additional check to make sure they’re not already in the custom prompt room.

Once each act is ready, download it and add its pdx bundle to the already-compiled “Switcher.pdx” bundle. On macOS control+click on the bundle and select “Show Package Contents”. Delete the example “Switcher—Act-*.pdx” bundles if present. The names of the individual acts don’t matter as long as their natural sort order matches their intended play order. Copy the “card.pdi”, “icon.pdi”, “wrapping-pattern.pdi”, and “pdxinfo” files from one of the acts into the parent “Switcher.pdx” bundle then rename “Switcher.pdx” to match.

Now when you launch the renamed “Switcher.pdx” it should load the last played act or, if a player has never played before, the first one.

2. An automatic switcher

This approach allows individual Pulp games themselves to trigger the switch to a different bundled Pulp game by name.

AutoSwitcher.zip (207 KB)

How it works

All the game needs to do is set gotoPDX to the name of the desired game bundle (minus the “.pdx” extension) and call store "gotoPDX" then store (to force the write), eg.

gotoPDX = "Game-Menu"
store "gotoPDX"
store

Additionally, if the initial game is a title screen or menu. it can enable an option in the Playdate system menu to return to that initial game by setting enableMenu to the name that should appear in the menu, eg. “menu”, “reset”, or “title”. Again, after setting you should call store "enableMenu" then store (to force the write), eg.

enableMenu = "reset"
store "enableMenu"
store

Please note that all menu item names in the Playdate system menu are forced to lowercase and plan accordingly.

Download each Pulp game and add its pdx bundle to the already-compiled “AutoSwitcher.pdx” bundle. On macOS control+click on the bundle and select “Show Package Contents”. Delete the example “Game-*.pdx” bundles if present. Copy the card.pdi, icon.pdi, wrapping-pattern.pdi, and pdxinfo files from the initial or default game into the parent “AutoSwitcher.pdx” bundle then rename “AutoSwitcher.pdx” to match. Open “default.txt” and replace its contents with the name (minus the “.pdx” extension) of your initial game.

Now when you launch the renamed “AutoSwitcher.pdx” it will load the default game which can then load other bundled games on demand.

Not just for Pulp games?!

This also works with Lua games. You can change games by implementing the following function:

local ds = playdate.datastore
function saveStore()
	local data = ds.read('store')
	if data then
		data.gotoPDX = 'Game-Menu'
		ds.write(data, 'store')
	end
end

Please note, the function name must be exactly saveStore, take no arguments, and it cannot be declared local or the AutoSwitcher won’t be able to hook into it.

If you didn't find an answer above, contact us