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

Why does it do this?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
local TimeLimit = 360

TimerStart()
for i = TimeLimit, 0, -1 do
Time = "Time: " .. tostring(math.floor(i / 60)) .. ":" .. tostring(i % 60)
--TickSound()
G_MSG.Value = Time
wait(1)
end

When the time turns at 5:09 it turns to a 5:9 instead of 5:09 as i want it to!

Help!?

1 answer

Log in to vote
1
Answered by 8 years ago

string.format

When you hit 09, Lua doesn't see the leading 0s and just turns it into 9 as a string. The solution is to look into string formatting to make sure that it knows you want the leading 0s.

string.format(
    'Time: %.1d:%.2d', -- % means it's a new symbol, .1/.2 is how many places (As a minimum), d means a number (With no decimal places)
    time/60, -- Our minutes
    time%60 -- Our seconds
) --> 5:09
0
I still kinda don't get it. Since i got the time script from my friend... UltraUnitMode 419 — 8y
0
Well that's no use then. I can't help you if you don't understand your original script. User#6546 35 — 8y
0
I do understand that, But i dont understand string.formant and what you did.. UltraUnitMode 419 — 8y
0
Did you look on the page I linked, and read my comments? %.1d literally means a number to 1 place, and %.2d means the same to 2 places. I can't explain it any better than I already have. User#6546 35 — 8y
View all comments (2 more)
0
Oh i didnt see that part ops UltraUnitMode 419 — 8y
0
"oops." User#6546 35 — 8y
Ad

Answer this question