How do you trigger a countdown mid game?

Everyone who has played literally any Metroid game (even the pinball one) knows that there is at least one awesome escape scene. Alarms begin to go off, explosions start going off, your heart rapidly beats as intense music starts to play, and finally the timer that’s counting down to your possible demise. The timer is arguably one of the greatest parts of a game as it can do so much. It creates stress, urgency, optimism, anticipation, and so much more.

So why all the talk about timers? I want to know if there’s a way to create a timer that gets triggered by an action/ event. I want to make parts of my game world have timed puzzles, a Metriod-esque escape sequence. This means that I need to have multiple timers that get triggered by different things and last for differing amounts of time. I tried to make a simple diagram that resemble logic bricks for a possible solution. Would this work?

No won’t work.

Well it does, but it’s not accurate, what if i get 40 fps, counting with property/tics at a fixed value of 60 is not wise and not accurate (at 30 fps the timer would be twice as long). You should instead use the timer property. This timer always counts up, so for 60 seconds you set it to -60 then at 0 the game ends or whatever.

if you want to show the timer i suggest a bit of python

def show_timer(cont):
    
    own = cont.owner
    timer = abs(own['timer']) #removes the minus(-)
    
    own['new_timer'] = timer

always true -> python module -> scriptname.show_timer
(scriptname in text editor should end with .py (so for example script.py))

property called timer set to timer value of choice
property called new_timer set to int

now you have a countdown timer that is accurate.

#edit
Oh and to activate it mid game, set the time to the seconds you like whenever you want it to run, also use a property to activate it, like run_timer boolean, if it’s true run the count down else set it to 0 or something.

Thank you for the response. I will try this out when the next chance I get.

However, I feel that if a game running at 60 fps drops to 30 fps and you’re in a timed escape scene, you would want the timer to take half as long. If the timer maintained its normal speed when the game’s fps drops, then you would be losing time to lag. For that reason I’m not worried if the timer is tied to fps, I would actually prefer it was.

Huh? a timer should take the same time at 1 fps or at 1000 fps.

60 seconds should be 60 seconds not 120. If you do this then if i would play your game i just limit my frames to 24 to get the longest possible time out of it while still playable. (called cheating/ glitch abusing)

Never thought of that. But the game will have no online interaction so if someone tampers with the final version I wouldn’t be upset. But I do see how that could be a big problem. If I were to export the game as a .exe would this still be possible?

Yes, because anyone can limit their frames by using their driver software.

I suggest the timer property too. It is in seconds (rather than in frames).
Timer%20Property
It is quite simple to implement in logic bricks and in python.

To start you set a defined value.

Then you let a property sensor detect when the limit is reached.


You can have as many timers as you like.

This is just one option to implement a timeout (start with negative limit and check when it gets above zero). Make sure to avoid measuring a time out right at the beginning of the game (the timer property never stopps).

There are other implementation solutions too.