how do you turn seconds into minutes and seconds

For questions about using Classic.

Post » 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?

Thanks in advance!
B
4
G
3
Posts: 25
Reputation: 975

Post » 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
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Wed Nov 04, 2009 7:03 pm

I made a example for you.
http://download923.mediafire.com/qbn92m ... e/time.cap
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
21
S
4
G
4
Posts: 280
Reputation: 2,934

Post » 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
G
3
Posts: 25
Reputation: 975

Post » 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
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

Post » 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 ;)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Nov 24, 2009 11:32 am

Cheers!
Also, I'd never noticed that zeropad system expression before - that's really useful! :o
B
134
S
65
G
16
Posts: 1,766
Reputation: 19,190


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest