Print time as minutes and seconds (properly)

Get help using Construct 2

Post » Wed May 28, 2014 3:12 am

During a level, I keep track of the time spent in that level as a seconds counter (every 1 second, increase counter by 1). After the level, I want to display the time spent as a minutes:seconds counter.

This is what I'm doing:

Text = floor(seconds/60) & ":" & seconds%60

The problem is that a single-digit seconds value will display as one digit. Example: 1:3 instead of 1:03. How do I fix this?

EDIT: Figured it out! Wasn't too hard, even.

1. Set text to minutes and separator: floor(seconds/60) & ":"
2. If seconds < 10 (seconds%60 < 10), append "0"
3. Append seconds: seconds%60
B
9
S
1
Posts: 98
Reputation: 853

Post » Wed May 28, 2014 4:35 am

Use zeropad(Value, N):

3. Append seconds: zeropad(seconds%60, 2)

zeropad adds 0s to the front of a number until it is N digits long.
B
39
S
12
G
11
Posts: 331
Reputation: 7,727

Post » Wed May 28, 2014 6:42 am

Here is demo made by Estúdio Célula 3
You do not have the required permissions to view the files attached to this post.
B
252
S
39
G
15
Posts: 1,964
Reputation: 40,753

Post » Fri May 30, 2014 3:57 am

@FragFather: Thanks for the tip! Didn't know that existed. That's simpler than my previous fix.
B
9
S
1
Posts: 98
Reputation: 853


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests