So basicly I want the player to have the option to watch an add for price, but I also want to set a timer so that the player can watch only X ads for 12 hours. My question is how can I make a function that counts time down even when the app is closed. I read somewhere that I can use the device’s time and date but I can’t do it myself. Thanks in advance.
What you probably want to do here is to compare dates to get the time that has passed. In other words, a Time Span.
THIS thread may help you.
Now remember that users could always cheat this by manually changing their device’s time. I would recommend checking it from a server instead of locally.
I hope that helps!
If I understand correctly, the fundamental requirement you have sounds like these:
given player has watched an ad for a reward fewer than threshold times in the current half-day when player wants to view an ad for a reward then player can view an ad for a reward given player has watched an ad for a reward threshold times in the current half-day when player wants to view an ad for a reward then player cannot view an ad for a reward
Trapping an event like “it’s been 12 hours” or “it’s midnight” is one way to implement that but there is nothing in the requirement that suggests it’s critical.
It smells more like a calculation than a change in state. The changes in state come from when a player actually does view an ad in exchange for a reward.
So, seeing as how it seems more like an authorization-calculation, that’s how I would treat it: refresh their ability to watch ads when you check to see if they have the ability to watch an ad.