Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Does anyone have a good way to convert an integer into a countdown?

Asked by 6 years ago

Hi.

I was just wondering if anyone had a good way to convert an integer representing some seconds left for something (e.g., the time left until a round ends) into a countdown clock; for example, the integer 300 could be displayed as 5:00.

I have no idea where to start trying to make this, honestly; does anyone have anything?

Thanks.

0
Try it your self. You're basically asking for the code to be written for you, which is selfish. This is a HELP site, not a REQUEST. User#19524 175 — 6y
0
I was just asking @incapaz. :> Fireorius 51 — 6y

2 answers

Log in to vote
1
Answered by
cabbler 1942 Moderation Voter
6 years ago

I use this:

local function clock(int)
    return string.format("%d:%.2d", int/60,int%60)
end

Study Format if you don't understand the arguments. yw

0
Thank you so much man! :D Fireorius 51 — 6y
Ad
Log in to vote
1
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

Try this:

function TIME(t)
       local s = ((math.floor(t%60)))
       local m = (((math.floor(t/60)%60)))
       if s < 10 and s>=0 then s = '0'..s end
       return (m..':'.. s)
end

print(TIME(200)) -- 3 : 20

Answer this question