About time

quantumsheepquantumsheep Member Posts: 8,188
edited November -1 in Working with GS (Mac)
Hey all!

Just a quickie about timers.

Now, I can make and display a timer that shows how many seconds are left. Or count up. That's all fine.

How do I display these seconds as minutes though? And hours? Anyone know off the top of their head?

Cheers,

QS :)

Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io

Comments

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Math:

    Hour=floor(game.Timer/3600)
    Minute=floor((game.Timer%3600)/60)
    Seconds=(game.Timer%60)
  • quantumsheepquantumsheep Member Posts: 8,188
    That hurts my head.

    But thanks! I think. How would that appear in a rule, as in, how do you display it?

    QS :)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Display Text: floor(game.Timer/3600)..":"..floor((game.Timer%3600)/60)..":"..(game.Timer%60)

    or something like that
  • quantumsheepquantumsheep Member Posts: 8,188
    AH! I think I get it! Thanks for all your help! :)

    A VERY HAPPY QS!!! :)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • quantumsheepquantumsheep Member Posts: 8,188
    Aha! It ALMOST works! :P

    When it gets down to single digits, no 0 is displayed.

    For example, four minutes and six seconds should read:

    4:06

    Instead it reads:

    4:6

    BAH!

    Anyone got a solution? I think displaying stuff like this would be useful to a lot of people.

    Especially me! :D

    Otherwise I'll just have to resort to displaying seconds. Which is a bit rubbish...

    Cheers in advance,

    QS :)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • CobraCobra Member Posts: 160
    You could try this Display Text:

    floor( game.TimeTaken /3600)..":"..floor((floor( game.TimeTaken /60)%60)/10)..(floor( game.TimeTaken /60))%10..":"..floor(( game.TimeTaken %60)/10)..game.TimeTaken %10

    In before CodeMonkey, who showed me that! ;)

    Any typos are mine... but provided there aren't any, that string should give you the time broken down digit-by-digit, so for example a time of one second should display as 0:00:01.
  • quantumsheepquantumsheep Member Posts: 8,188
    Oh you clever man! I'll give it a go now :)

    Thank you both!

    QS :)

    Aha! Your version doesn't work, alas, Cobra.

    On the plus side, that's the longest string I've ever put into a game, so a first there!

    I need to sleep - been up all night and I'm making silly mistakes. So I'll try again in a few hours.

    Thanks again for the input!

    QS :)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    I see your equation Cobra, and raise you another one.

    floor( self.myTime /3600)..":"..floor(floor(( self.myTime %3600)/60)/10)..floor((floor( self.myTime %3600)/60)%10)..":"..floor(( self.myTime %60)/10).. self.myTime %10
  • ktfrightktfright Member Posts: 964
    ???????????

    I am so confused now (X_x)
  • quantumsheepquantumsheep Member Posts: 8,188
    Heh - Codemonkey's last entry there works like a charm! Awesomeness!

    (though I generally disapprove of Math, I'll let this one slide)

    ;)

    Cheers,

    QS

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

Sign In or Register to comment.