Print variables as double digits

Get help using Construct 2

Post » Mon Apr 08, 2013 1:09 pm

Hi all I've a clock in my game and I have 3 variables for hours, minutes and seconds.

I am printing these into my scene and it appears as "0h 0m 0s" but I want it to look like "00h 00m 00s"

Is there a way to print these variables as double digits?

Best,
Mik
B
44
S
13
G
8
Posts: 622
Reputation: 7,417

Post » Mon Apr 08, 2013 1:51 pm

There sure is: zeropad(number, digits).
B
57
S
15
G
11
Posts: 912
Reputation: 12,626

Post » Mon Apr 08, 2013 6:51 pm

Thanks, I don't quite understand how to use it though, I'm using it here:

set text: "Time " & zeropad(0,hours) & "h" & zeropad(0,minutes) & "m" & zeropad(0,seconds) & "s"

and it's just constantly adding 0 to seconds...
B
44
S
13
G
8
Posts: 622
Reputation: 7,417

Post » Mon Apr 08, 2013 7:02 pm

zeropad(number, digits)

Number = the number you want to pad. In your case, this would be the variable representing the hour/minute/second/etc.

Digits = the total number of digits you want displayed.

For example:

zeropad(5,2) results in "05".
zeropad(141,3) results in "141"
zeropad(101,10) results in "0000000101"
B
64
S
19
G
8
Posts: 341
Reputation: 12,195

Post » Mon Apr 08, 2013 10:47 pm

Ahhhhhhh that's easy - thanks guys!
B
44
S
13
G
8
Posts: 622
Reputation: 7,417


Return to How do I....?

Who is online

Users browsing this forum: LunaticCat, WesleyDeveloper9 and 4 guests