by LadylexUK (adapted from tutorial by Team Dakota)
Basics
There are 2 kinds of timers.
Countdown Timer – triggers something after an amount of time
Duration Timer – triggers something for an amount of time and then turns off
If you don’t specify, a timer will last for 1 second. Consider the following lines of Kode.
WHEN [duration timer] [20] DO [play VFX] [smoke] //plays smoke for 20 seconds then turns off
Modifier Tiles
There are a number of useful modifiers to change how a timer works.
Loop
The timer repeats forever when this modifier is used. Unless hold is used (explained below), the loop tile generally causes the end of the timer to trigger for a single CPU frame.
WHEN [duration timer] [20] [loop] DO [play VFX] [smoke] //plays smoke for 20 seconds, turns off for a frame and then repeats
Hold
The hold modifier sustains the end of a timer for an amount of time
This modifier is only compatible with a duration timer when it is looping.
WHEN [duration timer] [20] [loop] [hold] [2] DO [play VFX] [smoke] //plays smoke for 20 seconds then turns off for 2 seconds then repeats
Trigger on Start
Tells the countdown timer to trigger the event at the start of the timer then countdown then loop. This modifier is only compatible with looping countdown timers.
In Frames
This modifier converts the value of the timer from seconds to frames. It’s not commonly needed but there if you like to think of time like a computer does.
Output Tiles
You can access a number of output tiles when using a sensor. These can be used whenever a number value is legal. These tiles work the same between a countdown timer and a duration timer. However, it’s worth noting that countdown timers don’t run their events until the timer reaches its goal so you need to use the “else” tile to make the best use of output parameters with the countdown tile.
Timer Seconds Remaining
Describes the number of seconds remaining before the timer completes.
….WHEN [else] DO [display] [timer seconds remaining] [screen center] //prints a 10 second countdown to the middle of the screen
Ladylex Tip:
The countdown does not display whole numbers, it shows 3 decimal places. To get a countdown that shows 10..9..8 etc
…WHEN [else] DO [display][ceiling] [timer seconds remaining] [screen center]
The ceiling tile is found in the Math segment of the Kode Wheel. Timer seconds remaining is in Modifiers/Outputs
Timer Seconds Complete
Describes how many seconds have passed as a timer runs.
….WHEN [else] DO [display] [timer seconds complete] [screen center] //counts to 10 and prints it to the center of the screen
Ladylex Tip:
Use floor this time to get a whole number
…WHEN [else] DO [display][floor] [timer seconds complete] [screen center]
Timer Ratio Remaining
Describes the ratio of time remaining before the timer completes. A value of 1 is the full amount of the timer. A value of 0 describes a completed timer.
….WHEN [else] DO [display] [timer ratio remaining] [screen center] //prints a value from 1 to 0 representing the progress of the timer towards completion
Timer Ratio Complete
Describes the ratio of time that has completed as a timer runs. A value of 0 represents no progress. A value of 1 describes a completed timer.
….WHEN [else] DO [display] [timer ratio complete] [screen center] // prints a value from 0 to 1 representing the progress of the timer towards completion