Countdown timer to display in hh:mm:ss format

CrumbyEntertainmentCrumbyEntertainment Member, PRO Posts: 32
edited December 2013 in Working with GS (Mac)
Hey guys so i made a countdown timer and i need it to display the time in the hh:mm:ss format.
I have scoured the forums and numerous example games but none showed what i needed. Say for example the timer was set to 3600 seconds. I would want the timer to read 01:00:00 for one hour. All i need is the functions to insert in the Display Text box.
Thanks in advance for the help.

Comments

  • CrumbyEntertainmentCrumbyEntertainment Member, PRO Posts: 32
    Hey guys so i made a countdown timer and i need it to display the time in the hh:mm:ss format.
    I have scoured the forums and numerous example games but none showed what i needed. Say for example the timer was set to 3600 seconds. I would want the timer to read 01:00:00 for one hour. All i need is the functions to insert in the Display Text box.
    Thanks in advance for the help.
  • allc1865allc1865 Member, PRO Posts: 777
    Check out this thread for a countdown timer:

    http://forums.gamesalad.com/discussion/comment/434691/#Comment_434691
  • CrumbyEntertainmentCrumbyEntertainment Member, PRO Posts: 32
    i checked it out but it doesn't display the time for hours and sadly, i do not know how to do that...
  • CaptFinnCaptFinn Member Posts: 1,828
    As much as his is asked for, It seems this would be pre programmed into the behaviors section of the creator. Like how animate is a widely asked for and needed thing. It just seems after a while things would become common place and just incorporated into the creator.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    What I do is to calculate the total time in seconds. I store that in an integer game attribute game.seconds. Then, for each digit, I calculate the correct value to display. For example, the number of hours would be contrained to floor(game.seconds/(60*60)). For example, if you have two hours, 15 minutes, and 40 seconds, you'd have a total of 8140 seconds (40+15*60+2*60*60). Taking floor(8140/(60*60)), you get 2. So the hours' one's digit would be 2. Of course, if you have more than 9 hours then you need to use the mod function to do hours%10 to get the correct hours' one's digit.

    I know that's just a start and doesn't cover every digit, but hopefully you find it helpful.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    [merged threads and moved to Working with GameSalad subforum]

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • CrumbyEntertainmentCrumbyEntertainment Member, PRO Posts: 32
    Awesome, that works perfectly. I will play around with the rest of the digits now.
    Thanks.
  • CrumbyEntertainmentCrumbyEntertainment Member, PRO Posts: 32
    Ok, so when I try to do the same logic for the minutes position using a time say 3660 (one hour one minute) it displays the time as 1:61:00 . As you know that is not correctly displayed. How do we keep it from going past 59 minutes? Here is my code for the hours and minutes position, below.
    floor(game.timer1/(60*60))..":"..floor(game.timer1/(60))
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You would use the mod() math function:

    mod(game.timer1/(60*60),60)

    Mod, also represented as '%', returns the remainder of a division expression. So 3660/3600=1R61 and thus (3660/3600)%60 = 1. That is, two hours and one minute. If you are using custom font digits, you'll have to code each digit. If you are using DisplayText, you can padInt(expression,2) and it will add a leading 0 when there are less than 10 seconds, minutes, hours, etc.

    I know I'm cramming in a lot of details but I'm a bit short on time and I'm also building exactly this system for a paying client so I'm not at liberty to share a demo at the moment. Someone else might be generous enough to do so!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • CrumbyEntertainmentCrumbyEntertainment Member, PRO Posts: 32
    Thanks, I completely understand your situation. Thanks for the input. I will try and figure it out.
    If anyone reading this knows how to do this, and is willing to show me an example I would gladly give due credit to you in the finished app.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Here are two demos that I learned from, both freely available. I modified the Custom Font Demo earlier today but you can turn the rule and second constrain behavior off if you want to see the original. Mine just left-justifies the digits on the scene.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • CrumbyEntertainmentCrumbyEntertainment Member, PRO Posts: 32
    edited December 2013
    Awesome thanks again!.
    So I actually figured it out and the only problem I have is that it counts fine in the hours position until i get past 9 hours. Once i get to 10 hours it switches to 110 hours..I know it is something to do with the math in the logic but i don't quite know how to approach it. Any help is appreciated, as always!
  • CrumbyEntertainmentCrumbyEntertainment Member, PRO Posts: 32
    If anyone reading this would like to know how to do this ( I have it worked out now) just send me a message!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.