Skip to main content

Timers

Loading...

This application introduces timers. When a timer is preloaded with a value greater than zero, it counts down at the rate of one count per second. Once the timer reaches zero, it generates an event.

In this application, a timer event causes the timer to be reloaded with the same value, causing it to count down again, and so on.

Times are defined on the Timers page of the Features tab:

timer

Adding a timer automatically creates a variable of the same name.

The type of such timer-linked variables is a dword, which is a 32-bit integer value. In Variables and Arithmetic, we already explained that variable types other than the four types explicitly available to the user exist in "certain parts" of the system. This is one such case. You cannot directly declare a variable of the dword type, but you can create a timer, which will be assigned the dword type automatically.

timer_variable

You can use timer variables anywhere in the application, just as you would use plain variables. The only difference is that when a timer runs, its value automatically decrements with each passing second until it hits zero. Once a timer reaches zero, the On Timer event is generated. This application relies on this event to reload the timer.

Your application may have multiple timers and multiple On Timer event blocks. The properties sheet of the On Timer block allows you to select which timer this block belongs to. However, It is impossible to have multiple On Timer blocks for the same timer.

timer_block

This kind of timer is often referred to as a one-shot timer. It is thus called because the timer stops once the countdown reaches zero. AppBlocks also has periodic timers -- introduced later in this Tutorial -- that keep auto-reloading with the same initial value.

Back to the application now. So, every time the timer expires, it is reloaded by the value stored in the timer_reload_value variable... but where does that variable get its value? The answer: Each variable has a default value property. You can edit default values on the Variables page of the Features tab:

timer_variable_default_value