Force save to disk

Is there a way to force any stored variables to save to persistent storage? As far as I'm aware, any variables you save with store only get written to disk when the player changes rooms or after a game ending (as per the pulpscript documentation).

I'm trying to make a city builder, and I'm worried a player might end up doing a lot of work in a single room that won't get saved to disk if they leave the game. Most modern games are constantly autosaving, so it would be great if there was some way to save the game that the player barely notices. It seems my options are:

  • Get the player to manually save by using a fin function
  • Use the fin function to autosave if the player hasn't changed rooms after a certain amount of time

Neither option is particularly appealing to me, since the screen goes fully black and it's a bit jarring for the player. Has anyone else had an issue with saving to persistent storage within a single room?

Unless you're looking at old docs it's right there in the section you linked - just call store on its own :slight_smile:

When "variableName" is omitted all values in persistent storage are written to disk immediately.

Wow, can't believe I missed that! I'd been working under the assumption that storing individual variables as I go would be optimal, since there are a lot of variables to keep track of in my game; but it seems like storing everything at once solves my issue.

It will be interesting to test whether there's a noticeable performance hit to writing all variables to disk, compared to attempting to save individual variables on the fly.

Thanks for your help! :playdate_proud:

Just to be clear you still have to specify individual variables to be stored, store on its own will just write the queued stores to disk as an alterative to needing to move room or call fin.

I hadn't realised this, you're totally right! I had kind of assumed that store worked in the same way as restore and toss with no variable specified; where it stores every saved value to disk, but I can see now that wouldn't be preferable and is not what the actually documentation says!

Thanks for clearing that up for me, seems I really didn't understand how persistent storage worked until you explained it to me! :playdate_goofy: