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
39
S
12
G
8
Posts: 580
Reputation: 7,108

Post » Mon Apr 08, 2013 1:51 pm

There sure is: zeropad(number, digits).
B
56
S
15
G
10
Posts: 910
Reputation: 11,952

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
39
S
12
G
8
Posts: 580
Reputation: 7,108

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
44
S
13
G
7
Posts: 338
Reputation: 10,379

Post » Mon Apr 08, 2013 10:47 pm

Ahhhhhhh that's easy - thanks guys!
B
39
S
12
G
8
Posts: 580
Reputation: 7,108


Return to How do I....?

Who is online

Users browsing this forum: Kagubro, Scofano and 22 guests