Make a timer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Make a timer

Hi I want to create a tasks for my game using Java. I need to refresh data every 24 hours. For example I pressed button and it added one point at 00:00 this point must remove how can I make it?

8th Nov 2022, 1:47 PM
Dmytro Parkhomenko
Dmytro Parkhomenko - avatar
1 Answer
+ 4
I assume the user will not spend 24 hours waiting in front of your game. Everyone needs to eat and sleep. So you would somehow have to save the game state. Whether this is in a cloud database or in local storage, is an implementation detail. Probably you could save the timestamp when the triggering event occurs, or you could alternatively save the timestamp when the event needs to occur. What if the user is not using your app at that moment? Is it ok to fire the event, when the user comes online, or the app needs to send some timed notification. Your app will probably need to monitor in regular intervals, if the event should happen, by checking in the storage this timestamp.
8th Nov 2022, 4:04 PM
Tibor Santa
Tibor Santa - avatar