Description
Describe the project you are working on
Arcade-y 1v1 fighting game with time limits
Describe the problem or limitation you are having in your project
My game has time limits in rounds and matches (a match is first to 3 round wins). When the round timer hits 0, whoever has most health wins the round, and when the match timer hits 0, same thing, but they win the match. These are important to have, so the players don't stall the game for too long. As these have a big impact on the strategies the players use, they need to be clearly displayed, like with a Label.
Here is the problem: Matches can take around 5-10 minutes, so I'd like to show the minutes and seconds left, as most people understand better how much time 4 minutes & 32 seconds is, compared to 259 seconds, for example. However, Timer can only return time_left
in seconds. So now I have to write a function that turns seconds into minutes, and display that.
Considering how often time is used in real life, it's strange how Timer can't return this in a format that we use daily.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I propose a new function in Timer, that converts the seconds into integers which represent milliseconds, seconds, minutes and maybe hours, puts them in an array, and returns that. Days, months and anything past that is probably overkill?
So for example, if time_left
is 1234.5 seconds (20 minutes and 34.5 seconds), it would return an array like [50, 34, 20, 0]
Call it time_left_clock
, time_left_converted
or time_left_humane
or something. Better name suggestions are welcome.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Let's say I had a Timer with 64 seconds, and I wanted a label to display that as "1:04". I could do something like this:
var round_time = %RoundTimer.time_left_converted()
if round_time[1] < 10: # padding zero
round_time[1] = "0" + round_time[1]
%RoundTimeLabel.text = str(round_time[2]) + ":" + str(round_time[1])
If this enhancement will not be used often, can it be worked around with a few lines of script?
It is possible to make a function that converts seconds to minutes, hours and whatnot, here's one I found on Godot Forums archive:
func time_to_minutes_secs_mili(time : float):
var mins = int(time) / 60
time -= mins * 60
var secs = int(time)
var mili = int((time - int(time)) * 100)
return str(mins) + ":" + str(secs) + ":" + str(mili)
Is there a reason why this should be core and not an add-on in the asset library?
Displaying time in hours and minutes is so common that I feel it should be included out-of-the-box. Search for "godot timer minutes" in a search engine and you'll find many posts asking how to make Timers seconds into milliseconds, minutes and even hours.