Timer Device only send 'On Success' event once.

Hello,

i am trying to reuse a timer device to do a “prepare yourself countdown” then when it’s finished, change his values and start it as a “game countdown”

i have something like this :

var GameStarted : logic = false;

OnBegin<override>()<suspends>:void=
  StartButton.InteractedWithEvent.Subscribe(OnStartButtonClicked)
  Timer.SuccessEvent.Subscribe(OnTimerCompleted)

OnTimerCompleted(Agent: ?agent):void=
  if (GameStarted?):
    #print game over & score
    set GameStarted = false
    Timer.Reset()
    StartButton.Enable()
  else:
    #print start
    set GameStarted = true
    StartTimer(60.0)

OnStartButtonClicked(Agent: agent):void=
  #print "get ready"
  StartTimer(5.0)
  StartButton.Disable()

StartTimer(Time:fload):void=
    Timer.SetMaxDuration(Time);
    Timer.SetActiveDuration(Time);
    Timer.Reset()
    Timer.Start();

So it pass thru the “OnTimerCompleted” once, but if i try to restart it, the event is not trigged anymore… any idea ?

Thanks.

Are you positive that the timer itself is running more than once? There is a setting on it called “Completion Behavior” which by default is set to “Stop”, which disables the timer from starting again. You have to switch it to “Reset” for it to be able to play again. Not sure if that’s what you’re dealing with here but figured I’d mention it.

Thanks, but if you check my code, i do a reset every time:

StartTimer(Time:fload):void=
    Timer.SetMaxDuration(Time);
    Timer.SetActiveDuration(Time);
    Timer.Reset()
    Timer.Start();

But if found somewhere on this forum that i am not the only one to have this problem, the other person who had this problem added a sleep of 0.2s to make it work… I changed my code to make a timer for the intro (get ready, 5, 4, 3 …) and then the game.

And it’s working…

By the way, it was not the full code, i copied & adapted the part of it that was problematic…