Hello everyone!
Hope all is well!
What I’m trying to do here is a Energy regeneration type deal (I call them treats ) these treats are to be used for different kinds of actions in the game.
For simplicities sake, you should have current_treats / max_treats
You get 1 treat every 10 seconds up to a max of 500, for example.
This is simple enough, while the game is running, that is. But if you log off for a while, and log back in…that’s where some issues (lag?) occur.
What is the expected result
When I log back in I calculate the following:
what is the time now
what was the last time the game was open
this gives me how much time I was out
I then add
time already waited which is how much time had passed before I left the game
If this total time is less than the time to generate 1 treat, then I do:
The time now + time required to get a treat (10 seconds) - what was already waited either before I exited or while away.
This seems to be working fine
The issue is when its more than the time of 1 treat (>10 seconds)
Sometimes its correct, sometimes it loses a second, the more times I open the game the the more time it loses - after about half an hour it can lose a whole treat.
The biggest issue is that it doesn’t always lose time, which is crazy and makes it really difficult to determine where are that 1 or more seconds of lag from. If it was a flat number each time that would be easy to offset or even identify the issue. But it’s not.
Please view the screenshot for exact steps
Will answer any additional questions asap
P.S.
I have given up on past projects due to this issue…
I made a promise to myself to not include something like this in a game again, since I dont know how to do it…however, this mechanic keeps clawing back into my games somehow…
