# how do you turn seconds into minutes and seconds

For questions about using Classic.

### » Wed Nov 04, 2009 5:21 pm

Hello everyone,

I am making a timer for a game, but at the moment it can only be in seconds (i.e. 100 seconds). Does anyone know how I can turn 100 seconds into 1 min 40 secs. Is this possible using events or will I have to use a piece of python code?

B
4
S
1
G
3
Posts: 25
Reputation: 1,125

### » Wed Nov 04, 2009 6:18 pm

It's easily possible in events! You just need a little math. If seconds is your number in seconds, floor(seconds / 60) is the minutes (divide by 60 and round down), and seconds % 60 is the seconds counter (modulo 60, ie. remainder after dividing by 60).
Scirra Founder
B
415
S
247
G
92
Posts: 25,281
Reputation: 200,831

### » Wed Nov 04, 2009 7:03 pm

I made a example for you.
Press the A key to start the timer.
It is ascending up to infinite or in this case all the number reach 0:00 and count up again.
B
24
S
5
G
4
Posts: 281
Reputation: 3,111

### » Thu Nov 05, 2009 1:09 pm

thanks toralord and Ashley,

Everybody states (quite rightly) how good construct is, and for me as a newbe to gamemaking it is the only platform I would attempt to write the game i am making at the moment. But the other great thing about construct is how supportive everyone is. I have asked three questions so far and I have never had to wait more than two hours for an answer. People like me are really grateful for the help!

thanks again.
B
4
S
1
G
3
Posts: 25
Reputation: 1,125

### » Tue Nov 24, 2009 7:05 am

[quote="Ashley":1ds9taky]It's easily possible in events! You just need a little math. If seconds is your number in seconds, floor(seconds / 60) is the minutes (divide by 60 and round down), and seconds % 60 is the seconds counter (modulo 60, ie. remainder after dividing by 60).[/quote:1ds9taky]

what if you have above 59 minutes and you want hours too?
B
168
S
81
G
22
Posts: 1,815
Reputation: 24,863

### » Tue Nov 24, 2009 9:41 am

[quote="alspal":2unqdj5p][quote="Ashley":2unqdj5p]It's easily possible in events! You just need a little math. If seconds is your number in seconds, floor(seconds / 60) is the minutes (divide by 60 and round down), and seconds % 60 is the seconds counter (modulo 60, ie. remainder after dividing by 60).[/quote:2unqdj5p]

what if you have above 59 minutes and you want hours too?[/quote:2unqdj5p]

hours: floor(seconds / 3600) (or: seconds / 60 / 60)
then use the result of seconds modulo 3600 for the rest of the calculations as seen above

totalseconds = 3980
hours = floor(totalseconds / 3600) = 1
totalseconds = totalseconds % 3600 = 380
minutes = floor(totalseconds / 60) = 6
seconds = totalseconds % 60 = 20

ZeroPad(hours, 2) & ":" & ZeroPad(minutes, 2) & ":" & ZeroPad(seconds, 2)
"01:06:20"

yeah, nice

EDIT: I forgot, in case someone asks for days too, just start with floor-dividing by 86400 (=3600 * 24) and use totalseconds % 86400 for the rest of the calculations.

Now try to find yourself the right value for weeks
B
24
S
8
G
10
Posts: 1,822
Reputation: 8,291

### » Tue Nov 24, 2009 11:32 am

Cheers!
Also, I'd never noticed that zeropad system expression before - that's really useful!
B
168
S
81
G
22
Posts: 1,815
Reputation: 24,863

Return to Help & Support using Construct Classic

### Who is online

Users browsing this forum: No registered users and 0 guests