Creating timer for game

Hey, I want to create a countdown timer for a level in my game. How can I do it?

If you want to test the timer internally (don’t show it to the user), you can use a “countup” timer instead:

[code]Conditions: At the beginning of the scene
Actions: Pause the timer “MyTimer” // Pausing the timer creates it automatically, and of course pauses it

Conditions: Conitions to start the countdown
Actions: Unpause the timer “MyTimer”

Conditions: Value of “MyTimer” is greater than X seconds // X is the countdown starting value, for example 60 seconds
Actions: Actions when the countodown has finished[/code]

If you want to show it to the user, i.e. you need a real countdown, you can:

1 - Use a countup timer, as above, but when you want to show it to the user, instead showing the current timer value (TimerElapsedTime()), use it:

X - TimerElapsedTime("MyTimer")

With X = The max timer value (it would be the initial time in a countdown), for example you have a countdown of 10 seconds (X = 10), but you start the GD timer at 0, when 3 seconds has been elapsed, the GD timer returns 3, with the expression above you show 10 - 3 = 7 to the player, because the countdown started at 10 but 3 seconds have elapsed :slight_smile:

2 - You can use a variable:

[code]Conditions: At the beginning of the scene
Actions: Do = X to the variable my_timer
Do = 0 to the variable count_down

Conditions: Conitions to start the countdown
Actions: Do = 1 to the variable count_down

Conditions: Variable count_down is = 1
Actions: Do - TimeDelta() to the variable my_timer

Conditions: Variable my_timer is <= 0
Actions: Actions when the countodown has finished[/code]

1 Like