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

how to add 0 to a single digit countdown timer?

Asked by 4 years ago

hi there, I had a timer script that will output a timer like this screenshot.

here is the code.

 for i = GameLength, 0, -1 do
        local minutes = math.floor(i / 60)
        local seconds = i - (minutes * 60)
        Status.Value = (minutes..":"..seconds)
        wait(1)
    end

so my question is how to make the timer more intuitive by adding a 0 after counting down from 10. like this screenshot.

thanks

1 answer

Log in to vote
1
Answered by 4 years ago

This has been covered many times, e.g. in this thread on the devforums.

Essentially, you can use the string.format function to format the seconds string padded with 0s to a specific width, e.g.

for i = 101, 1, -1 do print(string.format( "%.3i", i )) end

prints the numbers from 101 to 1 padded with 0s to a width of 3 (indicated by the number between '.' and 'i', so e.g. 54 becomes 054 and 3 becomes 003.

0
thanks for the answer. it works. jacobian65 19 — 4y
Ad

Answer this question