Timers
A Timer is a function that is scheduled to run at user defined times. Any function may be turned into a timer through one of three Timer Registration Functions described in the next section. When a function has been turned into a timer function, we generally say the function "has been registered as a timer" or "the function IS a timer". Timers are used to create:
-
Constantly running functions (run_at_interval) at user defined intervals.
-
Functions that run only one time after some delay period. (run_after_time)
-
Functions that run periodically at user-defined intervals after an initial delay period (run_timer).
Examples
-
Delay code initializations slightly to allow X-Plane time to finish loading all its data.
-
Delay a one-time event (... press and hold a button for 3 seconds and then a light illuminates after the delay). Many electronic systems are tested by holding buttons for some period of time to initiate a self-test.
-
Delay a recurring event (e.g. electrical power is interrupted and 3 seconds later a warning annunciator begins blinking).
Timer Functions
run_at_interval( func_name, interval)
^ Runs [func_name] every [interval] seconds, beginning [interval] sections from the call.
run_after_time( func_name, delay)
^ Runs [func_name] one time only after [delay] seconds.
run_timer( func_name, delay, interval)
^ Executes [func_name] function, beginning [delay] seconds after being called, and then executed every [interval] seconds after that.
stop_timer( func_name )
^ Stops/Cancels [func_name] timer functionality. Re-schedule with one of the above timer functions.
is_timer_scheduled( func_name )
^ This returns true if [func_name] is scheduled to run at any time in the future. False for all other conditions.
get_timer_remaining( func_name )
^ Returns the seconds remaining until [func_name] will be called next. Returns 0 if the timer is stopped.