In SDK 2.0.1 on Mac, trying to implement save/load state, I've added a save call in gameWillTerminate, but in the Simulator this seems to be getting called when the game is launched but before my mainGameSetup function is called.
Running the below file in the simulator shows the following in the console:
If you then exit the app from the menu, you will then see another gameWillTerminate message
Not sure if its me doing something odd.
And for info, running from Visual Studio Code.
-- Common CoreLibs imports.
-- Use common shorthands for playdate code
local gfx <const> = playdate.graphics
local display <const> = playdate.display
Are you sure it's not being called on the prior instance of your game? E.G. You load your game in the Simulator, do some debugging, rebuild and relaunch your game and the old instance of your game is quit while the new instance is loaded so the
gameWillTerminate handler is called but on the older instance of the game.
I don't think so.
I've quit the app (menu home), get a "gameWillTerminate" log message, then restarted the debugger and then get the "gameWillTerminate" followed by "setup" log messges.
I've also quit the app, and closed the simulator, then restarted the debugging session and again get the gameWillTerminate followed by "setup" log messages.
Am I quitting in the right way?
Are you using the VSCode debugging extension? I can reproduce this, but only when debugging a game, not if I normally run it. EDIT: looks like you are.
Yes indeed I am - and indeed it doesn't seem to happen on when running on device but does make debugging my save state a little tricky
I cannot repro this in Nova on Mac, wither whilst debugging or not.
I see the following:
Launching game from Nova:
Relaunching from Nova
- old game: gameWillTerminate
- new game: init (only line visible in log for new game)
Pressing Cmd+R in Simulator:
Here's the code I used to help reproduce:
That is interesting. It makes sense since the Mac debugger was developed interacting with Nova, not VSCode, and I've found a couple differences in how they behave. That said, I believe I have a solution for this issue with VSCode and plan on getting it fixed today.
Thats excellent news - thanks very much!