What is playdate.gameWillTerminate()?

I'm making an idle game and am going to use playdate.gameWillTerminate() to calculate how much money the player has made while the game is closed, but I don't know how to use it. Is it a boolean value, or something else?

It’s a function you can define, for example:

function playdate.gameWillTerminate()
    -- everything in here gets performed once right before the game closes
    doYourStuff()
end

It just gets called once when the game is about to close; games can’t actually run anything while closed. It sounds like you probably want to use gameWillTerminate to save the game state and current time to a file (using playdate.datastore or similar). Then when the game starts back up, you can load the file, calculate the elapsed time, and calculate how much money the player made during that time.

2 Likes