how do you turn seconds into minutes and seconds

This forum is currently in read-only mode.
From the Asset Store
12 looping retro style music tracks for your indie games and projects
  • 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!

  • 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).

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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).

    what if you have above 59 minutes and you want hours too?

  • > 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).

    >

    what if you have above 59 minutes and you want hours too?

    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

  • Cheers!

    Also, I'd never noticed that zeropad system expression before - that's really useful!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)