0 votes

I want to organize a virtual date and time in the game. For example: the game starts on the 1st of January 1905, and next time the game goes forward. Additionally, I want to determine the length of the virtual hour (say 6 minutes).

I can do it myself, means GDScript. But first I want to ask, in Godot there are standard tools to solve this problem?

in Engine by (355 points)

3 Answers

+2 votes

Usually, almost every high level language has a Date or DateTime object in its standard library, but after searching the doc, it turns out Godot hasn't one in GDScript (or it's not obvious :p) There is OS.get_date() but it returns today's time in a dictionary. So yeah, you have to implement that yourself.
Or you can post a request on Github if you feel it would be a useful addition.

by (27,958 points)
+2 votes

I solved this by using OS.get_unix_time() as the "zero point" for the start of my game time. When advancing the game time I add incrementally as much time (in seconds) as I want the game universe to move forward. Using the start time for comparison, I calculate how many seconds, minutes, hours, or days have passed.

Unfortunately there is no reverse function to determine the datetime from a UNIX timestamp, but at least it gives you an easier way to do the math.

by (30 points)

Thank you all for the answers. I will invent how to do it.

+2 votes

I hope this link to another answers could help.

http://www.godotengine.org/qa/3641/how-display-elapsed-time-in-game

by (515 points)
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.