Event-Driven Programming

Event-driven programming means that a subroutine can be called when an event is triggered, without the APL code explicitly calling the subroutine. When a specific event is triggered, the subroutine that is executed is called the event handler.

The most important advantage of event-driven programming is that you don't have to code a loop that repeatedly tests conditions and calls subroutines. Instead, the system tests conditions and calls subroutines automatically in response to events. When several conditions must be checked simultaneously (for example, checking to determine whether or not the plane is on the right heading, maintaining the correct altitude, holding position, and so on), conventional code can become unmanageable. In APL, event-driven programming is much more responsive than conventional programming methods because event triggering is tightly synchronized with the internal state of Flight Simulator, and because event handlers are special subroutines.

Three APL commands associate an event trigger condition with an event handler: Onexp_True, Onexp_Bool_Change, and Onexp_Change. See the Help topic for each of these commands for a definition of the event triggers each command defines. When one of these commands is encountered, the event information is added to the event list. Every time Flight Simulator calls the APL interpreter and the interpreter is not suspended, the event list is evaluated once and each event trigger condition is tested. If an event is triggered, the appropriate event handler is called as a special subroutine.

You can remove events from the event list when they are no longer needed by using the Onexp_Clear command.