Lives should come back every half hour, even while the game is closed
A countdown that runs inside the game stops when the app closes, and a timer that restarts on every launch gives away lives or takes them. The reliable way is to not run a timer at all and work everything out from two saved values. Here is that calculation and the three traps in it.
Why this works
A running countdown dies when the app closes, but the clock on the phone keeps going. So save only when the wait began and work out the rest when asked. Moving the start forward by whole waits, not to the present, keeps the leftover time and nobody loses it.
When not to use it
Skip it when the game must not trust the player's own clock, such as with paid rewards or a ranked game, because the clock can be turned forward to get lives free. There, let a server keep the time and hand out the lives.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 3 common mistakes and the fix
- A diagram of every state
- 34 lines of example code with 6 checks that pass
- How your AI shows you that it works
Say this to your AI
Use the Spielerando entry "Lives should come back every half hour, even while the game is closed" (read_entry lives-refill-over-time-without-a-timer) in my game. Build it step by step, and show me how you checked that it works.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP