<condition>#

The <condition> element is used to define logical conditions in FlightGear using XML. A number of child elements can be used inside of an opening <condition> and closing </condition>, and chained together to create complex conditional statements.

Simple Conditions#

Before covering complex condition statements, it is worth discussing the usage of simplistic condition statements can be created using consisting only of the <condition> element, with a <property> element enclosed.

<!-- Evaluates to either true or false based on the value of the property -->
<condition>
    <property>engines/engine[0]/running</property>
</condition>

For those with programming experience, this concept is similar to an expression that is implicitly checking if the value is true, or false

if (engine_running) { // engine_running is true
    // do something
}

These child elements include:

Usage#

<condition>
    <equals>
        <property>/my/p
        <value>my-value</value>
    </equals>
</condition>

Sub-tags#

Examples#

Because conditional logic is such a foundational building block, it can be used in a tremendous number of different ways. Imagine an aircraft developer wants to simulation a failing engine. Part of this engine failure simulation will include a particle effect, so that when the engine is failing, it begins to emit smoke. In order to prevent the engine from smoking all of the time, a conditional statement can be used alongside the particle effect, to ensure that it is only active under the right conditions.

<condition>
    <and>
        <!-- If the engine is smoking.. -->
        <equals>
            <property>engines/engine[0]/running</property>
            <value>1</value>
        </equals>

        <!-- and the engine is running.. -->
        <equals>
            <property>engines/engine[0]/smoking</property>
            <value>1</value>
        </equals>
    </and>
</condition>