How to handle time in an idle game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By andersmmg

I’m working on a small game where time should continue to pass at least half speed when the game is closed. How should I go about this? Like, how would I save the current time and compare it next time it’s open?

:bust_in_silhouette: Reply From: Gabriel

Use OS.get_datetime() to get the time and save it to a file when you quit the game. When you open the game, load the file and use OS.get_datetime() again. Then compare the two results to get the variation of time.

More info: OS.get_datetime(), File class

How would I do that when an Android game is closed or switched from?

andersmmg | 2019-10-05 02:40

I’m sorry, but I’m not familiar with mobile development yet. I just assumed that you had some kind of button to handle quitting and one to load. Have you tried Handling quit requests?

Gabriel | 2019-10-05 03:07