When is the best time to save user progress?

Good day.

I was wondering if When is the best time to save user progress?

should I put it in a timer, where it saves every second?

or should I put it in appSuspend or Exit function?

My save should be real time though, thanks in advance :slight_smile:

I save all of my data on exit. See code below

local function onSystemEvent( event )     if ( event.type == "applicationExit" ) then     file.save(settings)     print( "save\_state()" )     elseif ( event.type == "applicationStart" ) then     print( "load\_saved\_state()" )     elseif ( event.type == "applicationResume" ) then     print( "Resume: load\_saved\_state()" )        elseif (event.type == "applicationSuspend") then     print( "pause\_game()" )    end end

Edit  : It may depends on game. My games are not complicated :slight_smile:

A lot depends on your game’s goals and needs. If you’re doing a running game and there’s not a logical stopping point (end of level), then you might want save on suspend/exit as @Idurniat suggested above. If you have a logical stopping point, then save there.

Rob

My games is like a clicker game, once I exit, all of my data should still be saved. My only concern is if I do it every second, I might sacrifice the performance of my game, If I do it on AppExit/SUspend, some data might not be saved.

Saving every second does seem a bit extreme, but there is no reason why you couldn’t have more than one condition where you save. For example you could do all 3 of these:

  • Always save on exit/suspend.
  • Always save when user reaches a certain milestone (e.g. every 1000 clicks)
  • Save every 30 seconds.

Worst case scenario if the app crashes, the user will lose 30s of progress (which is not that bad). But if they had reached a milestone in that 30s then it would have saved again, so maybe they only lose 10s of progress.  

I would be reluctant to only save when the app exits/suspends, just in case a crash causes it to not save and the user loses all the progress from that session.

I save all of my data on exit. See code below

local function onSystemEvent( event )     if ( event.type == "applicationExit" ) then     file.save(settings)     print( "save\_state()" )     elseif ( event.type == "applicationStart" ) then     print( "load\_saved\_state()" )     elseif ( event.type == "applicationResume" ) then     print( "Resume: load\_saved\_state()" )        elseif (event.type == "applicationSuspend") then     print( "pause\_game()" )    end end

Edit  : It may depends on game. My games are not complicated :slight_smile:

A lot depends on your game’s goals and needs. If you’re doing a running game and there’s not a logical stopping point (end of level), then you might want save on suspend/exit as @Idurniat suggested above. If you have a logical stopping point, then save there.

Rob

My games is like a clicker game, once I exit, all of my data should still be saved. My only concern is if I do it every second, I might sacrifice the performance of my game, If I do it on AppExit/SUspend, some data might not be saved.

Saving every second does seem a bit extreme, but there is no reason why you couldn’t have more than one condition where you save. For example you could do all 3 of these:

  • Always save on exit/suspend.
  • Always save when user reaches a certain milestone (e.g. every 1000 clicks)
  • Save every 30 seconds.

Worst case scenario if the app crashes, the user will lose 30s of progress (which is not that bad). But if they had reached a milestone in that 30s then it would have saved again, so maybe they only lose 10s of progress.  

I would be reluctant to only save when the app exits/suspends, just in case a crash causes it to not save and the user loses all the progress from that session.