Restart and Recompile in Playdate Simulator

Tips on how to write a feature request:

  1. Describe your reason for requesting this feature. What problems are you running into?
  • Currently whenever you make a code change, you have to rerun a command line command and re-drag the .pdx folder in the simulator to load your new code.
  1. How would this request improve your experience developing for Playdate?
  • If there was a button where I could restart the game and recompile based on the same input/output paths, it would speed up the process of testing new code changes in the simulator.
  1. Include any other details you have relating to this request.
  • My current process is running

pdc ~/Documents/playdate/game/ ~/Documents/playdate/game/

in the MacOS terminal, then dragging the generated .pdx directory into the simulator. I currently do this every time I make code changes, but it would be nice if I could just press a button in the simulator to reload and recompile it once I drag the .pdx file into the simulator once.

1 Like

For what it is worth, using the C API on MacOS, the following line can be used in the terminal to rebuild and run the .pdx file in the simulator. Note that I run it based on the assumption that there is only one .pdx file.

make && open "$PLAYDATE_SDK_PATH/bin/Playdate Simulator.app" *.pdx

EDIT: The line can easily be changed to specify a specific .pdx, if necessary.

make && open "$PLAYDATE_SDK_PATH/bin/Playdate Simulator.app" MyGame.pdx

Also, the up arrow key can be used to rerun the command from the history so the above long line does not need to be typed out every time.

# up, up to execute from history
vim main.c
# edit main.c
# up, up to execute from history
make && open "$PLAYDATE_SDK_PATH/bin/Playdate Simulator.app" *.pdx
# repeat

I am using the bash shell.

I am also not typing the command in manually every time.

Not sure how others feel, but for me, the ideal workflow would just be one where the simulator could keep track of the input and output directories, and could recompile with the press of a button.

You didn't mention what platform you're on (EDIT: oops, you did mention MacOS, sorry!), but we have a workflow very close to what you want in Nova, our Mac development environment. Using the Playdate extension, it's very easy to rebuild and run your project with one keystroke.

If you're on MacOS but aren't using Nova, most IDEs support custom build/run commands, and @sgeos's suggestion above should be of use. If you're on Windows, instead of open you can use these commands to close the current simulator and launch a new one:

taskkill /IM PlaydateSimulator.exe
C:[...]\PlaydateSDK\bin\PlaydateSimulator.exe game.pdx

where [...] is the path to the folder containing PlaydateSDK and game.pdx is your compiled game.

Finally, if none of this is helpful, there is a shortcut: you don't have to drag the .pdx into the Simulator after rebuilding. As long as you rebuild it in the same location every time, you can just use the simulator's Restart (or Reset) menu item and it should relaunch and run the updated code.

1 Like

Hmm, I had thought that the restart button didn't automatically pick up the new .pdx file after recompiling it via the terminal, but looks like it is doing that. Whoopsie.

I'll try asking around the discord to see if others have set up any workflow similar to what I'm looking for then. Thanks

I just set up my environment last night (macOS + VSCode) and I'm happy with the iteration loop I have. Every time I hit CMD+S on a lua file, pdc builds and opens the simulator and switches focus to it. To accomplish this, I use the VSCode extension "Run On Save" by emeraldwalk. My settings.json looks like this:

{
  "playdate.output": "bin/Output.pdx",
  "Lua.diagnostics.globals": [
    "import",
    "playdate"
  ],
  "Lua.workspace.library": [
    "~/Developer/PlaydateSDK/CoreLibs"
  ],
  "emeraldwalk.runonsave": {
    "commands": [
        {
            "match": "\\.lua$",
            "cmd": "mkdir -p bin/Output.pdx; pdc source bin/Output.pdx && PLAYDATE_OUTPUT=bin/Output.pdx node ${workspaceFolder}/.vscode/run.js"
        }
    ]
}
}

and run.js looks like this:

const fs = require("fs");
const path = require("path");
const os = require("os");
const { exec } = require("child_process");
const process = require("process");

let sdkRoot = null;

let configPath = path.resolve(os.homedir(), ".Playdate", "config");
let configText = fs.readFileSync(configPath, "utf8");
let configLines = configText.split("\n");
configLines.forEach((line) => {
  let components = line.split("\t");
  if (components[0] == "SDKRoot") {
    sdkRoot = components[1];
  }
});

if (sdkRoot == null) {
  throw new Error("No SDK Root");
}

let simulatorPath = path.resolve(sdkRoot, "bin", "Playdate Simulator.app");
exec(`/usr/bin/open -a \"${simulatorPath}\" \"${path.resolve(process.cwd(), process.env["PLAYDATE_OUTPUT"])}\"`);

I don't like that bin/Output.pdx is defined a bunch of times in settings.json, but I don't know VSCode's setting system. If anyone knows a way, please let me know!

I didn't know about the runonsave extension. You're post really helped, thanks!

I ended up using the settings above but not using the .js file. I modified the "cmd" part of your settings like so:

"cmd": "mkdir -p bin/Output.pdx; pdc source bin/Output.pdx && open $PLAYDATE_SDK_PATH/bin/Playdate\\ Simulator.app bin/Output.pdx"

This is a simple solution for saving in VS Code on the Mac, building the pdx and then having it run in the sim. It's great.

Ooh, great simplification Paul :pray: I blindly copy pasta'd that js file but it's pretty unnecessary now that I read it!