1 CONDITIONS IN FLIGHTGEAR PROPERTY FILES
3 Written by David Megginson, david@megginson.com
6 This document is in the Public Domain and comes with NO WARRANTY!
12 Some FlightGear property files contain conditions, affecting whether
13 bindings or animations are applied. For example, the following
14 binding will apply only when the /sim/input/selected/engine[0]
19 <property>/sim/input/selected/engine[0]</property>
21 <command>property-assign</command>
22 <property>/controls/starter[0]</property>
23 <value type="bool">true</value>
26 Conditions always occur within a property subtree named "condition",
27 which is equivalent to an "and" condition.
30 2. Comparison Operators
31 -----------------------
33 The simplest condition is "property". It resolves as true when the
34 specified property has a boolean value of true (i.e. non-zero, etc.)
35 and false otherwise. Here is an example:
38 <property>/sim/input/selected/engine[0]</property>
41 For more sophisticated tests, you can use the "less-than",
42 "less-than-equals", "greater-than", "greater-than-equals", "equals",
43 and "not-equals" comparison operators. These all take two operands,
44 either two "property" operands or one "property" and one "value"
45 operand, and return true or false depending on the result of the
46 comparison. The value of the second operand is always forced to the
47 type of the first; for example, if you compare a string and a double,
48 the double will be forced to a string and lexically compared. If one
49 of the operands is a property, it is always assumed to be first. Here
50 is an example of a comparison that is true only if the RPM of the
51 engine is less than 1500:
55 <property>/engines/engine[0]/rpm</property>
64 Finally, there are the regular boolean operators "and", "or", and
65 "not". Each one surrounds a group of other conditions, and these can
66 be nested to arbitrary depths. Here is an example:
72 <property>/engines/engine[0]/rpm</property>
76 <property>/engines/engine[0]/rpm</property>
80 <property>/engines/engine[0]/running</property>
84 The top-level "condition" is an implicit "and".
87 4. Approximating if...else
88 --------------------------
90 There is no equivalent to the regular programming 'else' statement in
91 FlightGear conditions; instead, each condition separately must take
92 the others into account. For example, the equivalent of
94 if (x == 3) ... else if (y == 5) ... else ...
96 in FlightGear conditions is
100 <property>/x</property>
105 <property>/y</property>
114 <property>/y</property>
119 <property>/x</property>
129 <property>/x</property>
135 <property>/y</property>
140 It's verbose, but it works nicely within existing property-based
141 formats and provides a lot of flexiblity.
147 Here's a quick syntax summary:
151 Contains one or more subconditions, all of which must be true.
153 * <condition>...</condition>
155 The top-level container for conditions, equivalent to an "and" group
157 * <equals>...</equals>
159 Contains two properties or a property and value, and is true if the
160 properties have equivalent values.
162 * <greater-than>...</greater-than>
164 Contains two properties or a property and a value, and is true if
165 the second property or the value has a value greater than the first
168 * <greater-than-equals>...</greater-than-equals>
170 Contains two properties or a property and a value, and is true if
171 the second property or the value has a value greater than or equal
172 to the first property.
174 * <less-than>...</less-than>
176 Contains two properties or a property and a value, and is true if
177 the second property or the value has a value less than the first
180 * <less-than-equals>...</less-than-equals>
182 Contains two properties or a property and a value, and is true if
183 the second property or the value has a value less than or equal
184 to the first property.
188 Contains one subcondition, which must not be true.
190 * <not-equals>...</not-equals>
192 Contains two properties or a property and value, and is true if the
193 properties do not have equivalent values.
197 Contains one or more subconditions, at least one of which must be
200 * <property>...</property>
202 The name of a property to test.
206 A literal value in a comparison.