Tips on when to do a sys.save

When is a good time to save the state of a game.
I’m not keen at saving on every action from the user.

I prefer that to do it on certain conditions like a milestone/checkpoints in the game.
I got some questions below, but would be great to get some advice on any recommendations and if there are any defold specific ones i should be aware of.

  1. Detect when game is paused or screen not active (mobile)
  2. Detect when game is being offloaded in memory
  3. Implement a reliable timer that will save every X interval

Thanks in advance!

Yeah, this is tricky and it depends quite a bit on the kind of game you are doing. You have listed three different strategies:

  1. Inactive. We do not have any callbacks when the app is put in the background so this is currently not possible.
  2. Offloaded. If you put save code in the final() function of some main script then it should be called when the game is terminated and offloaded.
  3. Create a small timer module (perhaps based on https://gist.github.com/britzl/0f6291990b0b11f92775), use repeated go.animate() calls or schedule a local notification (mobile only).

Unless you are saving a lot of data or doing it really frequently it shouldn’t really be a problem to save often.

function on_suspend(self)
would be useful for this. Available in other engines.

Then when app is suspended data can be saved for sure.

3 Likes