How do I stop the Timer behavior from restarting?

0 favourites
  • 15 posts
From the Asset Store
Tabata timer
$9.99 USD
Template for Tabata timer, fully documented in comments and video
  • I have a simple game that keeps a running game timer. When the level is over I have a restart button that just restarts the layout, the game timer continues with no problems. However I have timers using the Timer behavior that reset messing up the timing of sound with the running game timer. How can I set a timer to the running game timer or stop the Timer from restarting?

  • I don't understand your post to be honest.

    With Timer behavior you can pause or stop timers. Or you can start timer only once, and in "On timer" event decide if it needs to be restarted again or not.

  • No I understand the functions of the Timer behavior. I dont want my Timer that is running to reset when the user resets layout. Example I have a sound that goes off every minute using the Timer behavior. When the user completes the task they can then click a restart layout button and do it again. I have everything setup so that the timer keeps going through the restart layout command however the Timer resets. So the user is left with a Timer that doesn't match up with the still running clock from the previous.

  • So you have a Timer running on one of the objects? And when you restart the layout, the Timer also restarts?

    It's likely because all objects are re-created when layout is restarted. You might need to use a Global object, and make sure only one instance of it is created.

  • Thanks for the fast response, negative on the global object. When I debug the layout I can see the timer running and the sound activates on time but when I click restart layout the timer gets reset.

  • You need to post your project file. It's a guess game without it.

  • I made a quick example of my issue. Nothing starts until layout 2 when the timer and the alarm start. At 12 seconds the alarm will go off and every 12 seconds after that. However if you click the sprite to restart the layout the alarm timer is reset and it might not be synced with every 12 seconds anymore.

  • However if you click the sprite to restart the layout the alarm timer is reset and it might not be synced with every 12 seconds anymore.

    It works fine for me. Run the project in Debug Mode and you'll see that the timer properly resets every time the layout is restarted.

    One thing I would suggest fixing is the timer tag - don't leave it empty.

  • No I dont want the alarm to restart. I want the alarm to keep going off every 12 seconds from the start of the layout when its synced with the running timer that starts on the layout. But when you reset layout the alarm will start back over and its no longer synced with the running clock

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ah, terribly sorry, I misunderstood the issue. Here is the way to run the timer continuously:

    .

    But it would be easier to use a global object with Timer behavior.

  • Yes thank you that is exactly what I was looking for. Does it seem to far fetch for the Timer(alarm) to not get reset on the layout. Everything else with that object stays the same but the Timer resets. Can you help me understand how you would do it differently, using a global object? Fairly new to construct and the manual only goes so far and everything online points me to using the Timer behavior...lol a never ending loop. Thanks so much for the help, I wanted to try something different and went with asking the forums.

  • Timer is reset because you are restarting it in "On start of layout" event.

    There are several alternative and easier solutions:

    1. I see you've added Persist behavior to the text object. It will ensure that the Timer continues to run after layout is restarted, but you need to add "Timer is NOT running" condition to the first event, to prevent it from resetting.

    2. Instead of Persist behavior, you can make the text Global. It will have the same effect, but you need to be aware that global objects are not destroyed when you switch to another layout.

    3. You can do this without Timer behavior - add this event:

    int(TimerVariable)%12=0
    Trigger Once 
    ..........Audio Play 
    
  • I've tried the persist path which is when I decided to go to the forums. I got things working, maybe not the most efficient way but been testing all weekend. Question with global objects that text box will take up that space on all layouts and how can I stop the running timer, lets say the user went to a home page?

  • I've tried the persist

    And you were on the right path, but you needed to add "Timer is NOT running" condition to the first event.

    Question with global objects that text box will take up that space on all layouts and how can I stop the running timer, lets say the user went to a home page?

    You will have to destroy this text on all other layouts. I don't like Global objects, but they may be useful sometimes.

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