Time Remaining: String Formatting

Get help using Construct 2

Post » Wed Jan 18, 2012 1:29 am

I made a little counter for time remaining to level ends in my game. I can't upload it now, but the example consists only in:

1. Add a Text on layout;
2. Add a global variable like "secondsToPlay" and set a number of seconds, for example 150 for 2 minutes and a half, or 120 to 2 minutes on Event Sheet;
3. Add Event: System > Every 1 second(s);
- 3.1. Add Action > Text > "Time Remaining: " & Floor(secondsToPlay/60) & ":" & Floor(secondsToPlay%60)
- 3.2. Add Action > System > Subtract 1 from secondsToPlay;

The counter will start: 2:0 - 1:59 - 1:58 - ... - 1:9 - n

The problem is: As you can see, I don't know how I can put a zero left on numbers to have this visual representation: 02:00 - 01:59 - 01:58 - ... - 01:09 - n.

In programming languages, for example, we can format the outputed string like: print "Missiles: %02" % numberOfMissiles and obtain a plain text like: "Missiles: 003".

From now on, the question is obvious: "How can I do this with Construct 2?", how can I format my string? Or... if anyone has a better way to do this...

Thanks in advance.hexodin2012-01-18 01:39:48
B
9
S
3
G
5
Posts: 2
Reputation: 3,201

Post » Wed Jan 18, 2012 1:43 am

time<10 ?"0"&time :time
Probably a few other ways as well.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Wed Jan 18, 2012 2:02 am

C2 has the ZeroPad function? If so, use ZeroPad(secondsToPlay,2)
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Wed Jan 18, 2012 3:16 am

well
[code]right("00"&seconds,2)[/code]
works fine (:Yann2012-01-18 03:18:26
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Jan 18, 2012 10:50 am

Thank you, about the ZeroPad function, returns a error on r75: "Unknow Expression 'ZeroPad'", but the "right" function works well.hexodin2012-01-18 11:00:40
B
9
S
3
G
5
Posts: 2
Reputation: 3,201


Return to How do I....?

Who is online

Users browsing this forum: Matthew de, nexlove and 25 guests