5 min Countdown timer doesn´t stop at zero

Hi.

I'm have a countdown timer that starts at 05:00 and should stop at 00:00. I created the timer with the help of two tutorials that I found on YouTube...
...But I encountered two minor issues that I don´t know how to solve.

First, you hardly see 05:00 when the timer starts. you see it for a millisecond before it goes to 04:59. Is there a way to "delay" it so that you can actually see the 05:00, before it starts the countdown?

Second, the logic below should stop at 00:00, according to one of the tutorials but when I preview it, it just goes past 00:00 and stops instead at 59:59.

Attributes
StartTime 0 real
MyTimer 0 real

Display Text

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

Change Attribute

  • game.StartTime to game.Time

Rule

  • When all conditions are valid, game.MyTimer to > 0
  • Constrain Attribut_e
  • _game.MyTimer to 300-( game.Time - game.StartTime )

Comments

  • CodeMonsterCodeMonster ACT, AustraliaMember Posts: 1,078

    i made this template over a year ago so I'm not to sure if this is what your after as i haven't opened it since. but give it a check.

    http://www.gsinvention.com/store/p49/Count_Down_Timer.html

  • FamTechAdminFamTechAdmin Member Posts: 47

    @CodeMonster thanks.

    I downloaded the rar file, but it doesn´t open in game salad. the .gsproj is 0 bytes for some reason. I extracted the files 3 times and and downloaded the the rar 2 times

  • CaptFinnCaptFinn Member Posts: 1,828
    edited May 2015

    Seems like you should just be able to use a if true/if false boolean.

  • yasoofxyasoofx Member Posts: 332

    Make an attribute Boolean called TimerMoving... then put it on a rule over timer which will be like: If TimerMoving is true then (Timer)

  • CodeMonsterCodeMonster ACT, AustraliaMember Posts: 1,078

    @FamTechAdmin oh sorry to hear, ill make an updated version now, to see if it helps, give me a sec.

  • FamTechAdminFamTechAdmin Member Posts: 47

    @FINNBOGG @yasoofx

    thanks for the tip... I found the bug.

  • FamTechAdminFamTechAdmin Member Posts: 47

    @CodeMonster no need, I found what was causing the problem

  • FamTechAdminFamTechAdmin Member Posts: 47

    I solved it by doing it like this

    Display Text

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

    //I added the change attribute below and a timer for the countdown
    Change Attribute

    • game.MyTimer to 300 //sets the timer to 5 minutes

    Timer

    • After 1 second //This allows the timer to show 05:00 for 1 second before starting the countdown.
    • Change Attribute
    • game.StartTime to game.Time
      
    • Rule

    • When all conditions are valid, game.MyTimer to > 0
    • Constrain Attribute
    • _game.MyTimer to 300-( game.Time - game.StartTime )

    then I also changed the rule, that I now realize that I forgot to mention in beginning (sorry about that), so that the timer should stop at 00:00.

    Rule

    • When all conditions are valid, game.MyTimer to = 0 //I had put game.Timer at first causing the timer to stop at 59:59 instead of 00:00. by changing it to the proper timer, it stopped the countdown at 00:00.
    • Change Scene
    • Go to scene: Game Over
Sign In or Register to comment.