Countdown Timer

In-game description
The [countdown timer] executes a line or set of lines when the amount of time specified has passed. Immediately after you place [countdown timer], you’ll want to place a number to specify how long the countdown is. The game interprets this number as being in seconds, although you can add a modifier [in frames] afterwards to change that.

Use
It’s important to realize that lines governed by [countdown timer] will run continually after the time specified is elapsed. That means that a simple WHEN [countdown timer] [5] DO [jump] is placed, the brain will wait 5 seconds then jump, jump, jump etc. (continually). You can, however, introduce more interesting behaviors by utilizing the modifiers [hold] and [loop]. Check those tiles out after you've placed [countdown timer] in your line!

You can also use the logic tiles like [started to], [no longer], [until] or [after] with the countdown timers. For example, WHEN [started to] [countdown timer] [number] will only execute once the number of seconds elapse (and only once).

This tile must have a [number] as a parameter. If no number is specified, it defaults to 1. This number is measured in seconds unless the [in frames] tile is present (note that there are 30 frames in a second).

Modifiers

 * Hold_2.png:  Pauses a completed timer for a specified amount of time.


 * Loop_2.png: Tells a timer to start over once it has completed.

Example: Time bomb


This tells the brain: after 3 seconds, destroy self.

Example: Church Bell


This tells the brain: After 3 seconds, play the "bell" sound and then loop. That means that it will play the sound every 3 seconds, starting with a 3 second delay.

Advanced Modifiers

 * In_frames.png the timer to measure in frames of game time instead of seconds. This is particularly useful when you want to count less than a second easily or loop something really fast. Project Spark framerate is 30 frames per second (FPS).


 * Trigger_on_start.pngers the action to run immediately, and then begin the timer.

Example: The Telephone Ring
Taking the Church bell example from above and adding a few more tiles we can create a more complex mechanism that will make the sound of the bell look like a telephone ring. Here is how:

What this will do is tell the brain to play continually the bell sound for one second (30 frames), then wait one second and then loop. The sound will start immediately, because we entered the [trigger on start] tile. So, this will simulate a telephone ring (try it for yourself with different sounds for better results).

Outputs

 * Timer_seconds_remaining.png number of seconds that the timer will remain on or off.


 * The number of seconds that the timer has been on or off.Timer_seconds_complete.png


 * The ratio of time that the timer will remain on or off.Timer_ratio_remaining.png


 * Timer_ratio_complete.png ratio of time that the timer has been on or off.

Output examples
Example: Displaying a countdown timer on screen

Using the outputs will always display the figure with four decimals. To avoid that, simply use the [round] function, as seen in this example. This brain will display on screen a countdown timer from 100. In order to do this, we used a number variable, called "Timer variable" to hold the rounded seconds and then display them..