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:
gameWillTerminate
setup
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.
import "CoreLibs/graphics"
-- Use common shorthands for playdate code
local gfx <const> = playdate.graphics
local display <const> = playdate.display
gfx.setBackgroundColor(gfx.kColorWhite)
function myGameSetUp()
print( "setup")
end
myGameSetUp()
function playdate.gameWillTerminate()
print( "gameWillTerminate")
end
function playdate.gameWillSleep()
print( "gameWillSleep")
save()
end
function playdate.update()
end
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'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.
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.
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.