I’m trying to create a timer that will show how long is left of a round in minutes and seconds by taking away 0.01 from a variable each second. The problem with this is when the timer gets to something like 3.00, when you take away 0.01, instead of going to 2.59, it will go to 2.99 and of course this is a problem so I’m wondering if anyone knows how I can make the variable count down in minutes and seconds or if there a better way to do it?
Is the variable meant to hold the amount of minutes left? If so, it’s better to store it in seconds and use a simple command in order to change it into a mm:ss string.
Here’s an example:
[lua]function TimeLeftForRound( TimeInSeconds )
local s = TimeInSeconds % 60
TimeInSeconds = math.floor( TimeInSeconds / 60 )
local m = TimeInSeconds % 60
return m .. ":" .. s
It seems to work however whatever number I have in my variable such as for example 12, it will say 12 seconds on the timer instead of 12 mins which is what i would like.
I got it working like how i wanted it though i was wondering how i could make it so when the timer gets to something like 0:9, instead of saying 9 seconds left, it says 09 seconds left so it looks like 0:09.
You can change the return to [lua]return string.format( “%02i:%02i”, m, s )[/lua]