0 votes

So, I'm making a city building game similar to clash of clans. When the player builds something, a timer appears on top of the building showing how much time it takes to finish (e.g. 10 minutes). I'm now trying to figure out how to make the timer continue when the game is closed or the computer is shut down.

How can I measure the time since the game was last opened?

I considered using OS.get_datetime() but I'm new to godot and don't really know how that works.

Thanks in advance!

in Engine by (31 points)
edited by

1 Answer

+1 vote
Best answer

when you exit out of the game, just save the current time into a savefile. To get the time, use OS.get_datetime(). When you open the game again, check the time the second time. Then, subtract current time from previous time and you will get the amount of time passed since your last play through. Even though, if your game is dealing with real money (micro transactions), then I really wouldn't recommend doing so because it's very easy to edit the save file (even if it's encrypted). You should use servers to keep track of that.

by (83 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.