Read Device time

Hi,

How can i use the Device time (doesnt have to be server)?
I want it to make that every half hour you get an extra life. Also when the app is closed and reopend again.

Thanks in advance!

I believe you are looking for the Time() string expression:
http://wiki.compilgames.net/doku.php/gdevelop5/all-features/time/reference#time

I need help with this. I dont get it with only the wiki of time expression.

I want to read the time, so i can give the player, Every half hour an extra life.

How do i do this?

If you want to just track every 30 minutes of game time, use a timer that resets every 30 minutes (1800 seconds) along with doing whatever actions you want.

If you want to track every 30 minutes of realworld time, you are going to need to keep experimenting with the time expression along with variables. Probably something where you track “last time reward given” in some form of variable, and compare it to the current time. There aren’t any tutorials for this, so you are going to have to poke around a bit.

The typical pattern I’ve seen in software applications is to have a timer thread that tracks the current time and compares it to the last time it tracked to see how much time has passed between executions. In GDevelop terms I would design this by creating an “External Event” called RealtimeTracker and include that external event in all of my pertinent scene events. The conditions in RealtimeTracker would look get the device time using Time(“timestamp”) and then store that value immediately using Storage:
http://wiki.compilgames.net/doku.php/gdevelop5/tutorials/storage-action-explained#storage_action_explained
There would also need to be a condition that loads the previously stored time value and compares it to the current time before overriding that storage. You will also want to surround these conditionals with a scene timer check so that you only do this check every 30 seconds.
Storage is the only effective way to check realworld time changes when the app is not running.

This is the sort of thing you could run at the beginning of your game to get variables for logout and login time (you’ll also need month and year as well to set up a proper system), but basically you could expand on this to work out how much time has passed while the game was off, give extra lives based on that number, and then pair it with an active timer system that runs while the game is on, which also gives lives every 30 minutes. That would need to be a number that’s stored so if say 20 minutes have passed and they turn the game off, next time they play that 20 minutes is added to the amount of time that passed while the game was off.


Unfortunately I can’t show a full system and the math that would be involved with it because it ended up being a little too tricky for me months ago when I tried it for my game, but it is technically possible. It’s just very confusing once you factor in the changing of days and months and years lol

edit: I think you’d need to exclude the part that rewrites the times to storage at the beginning of the scene, that’s just how my dumbed down system works lol, but to track actual time youd need to write the current time to storage continually