Debian Codegraph @

Docs/README.conditions

raw
1 CONDITIONS IN FLIGHTGEAR PROPERTY FILES
2
3 Written by David Megginson, [email protected]
4 Last modified: $Date$
5
6 This document is in the Public Domain and comes with NO WARRANTY!
7
8
9 1. Introduction
10 ---------------
11
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]
15 property is true:
16
17 <binding>
18 <condition>
19 <property>/sim/input/selected/engine[0]</property>
20 </condition>
21 <command>property-assign</command>
22 <property>/controls/starter[0]</property>
23 <value type="bool">true</value>
24 </binding>
25
26 Conditions always occur within a property subtree named "condition",
27 which is equivalent to an "and" condition.
28
29
30 2. Comparison Operators
31 -----------------------
32
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:
36
37 <condition>
38 <property>/sim/input/selected/engine[0]</property>
39 </condition>
40
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:
52
53 <condition>
54 <less-than>
55 <property>/engines/engine[0]/rpm</property>
56 <value>1500</value>
57 </less-than>
58 </condition>
59
60
61 3. Boolean Operators
62 --------------------
63
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:
67
68 <condition>
69 <and>
70 <or>
71 <less-than>
72 <property>/engines/engine[0]/rpm</property>
73 <value>1500</value>
74 </less-than>
75 <greater-than>
76 <property>/engines/engine[0]/rpm</property>
77 <value>2500</value>
78 </greater-than>
79 </or>
80 <property>/engines/engine[0]/running</property>
81 </and>
82 </condition>
83
84 The top-level "condition" is an implicit "and".
85
86
87 4. Approximating if...else
88 --------------------------
89
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
93
94 if (x == 3) ... else if (y == 5) ... else ...
95
96 in FlightGear conditions is
97
98 <condition>
99 <equals>
100 <property>/x</property>
101 <value>3</value>
102 </equals>
103 <not>
104 <equals>
105 <property>/y</property>
106 <value>5</value>
107 </equals>
108 </not>
109 </condition>
110
111 and then
112
113 <condition>
114 <equals>
115 <property>/y</property>
116 <value>5</value>
117 </equals>
118 <not>
119 <equals>
120 <property>/x</property>
121 <value>3</value>
122 </equals>
123 </not>
124 </condition>
125
126 and then
127
128 <condition>
129 <not>
130 <equals>
131 <property>/x</property>
132 <value>3</value>
133 </equals>
134 </not>
135 <not>
136 <equals>
137 <property>/y</property>
138 <value>5</value>
139 </equals>
140 </not>
141 </condition>
142
143 It's verbose, but it works nicely within existing property-based
144 formats and provides a lot of flexiblity.
145
146
147 5. Syntax Summary
148 -----------------
149
150 Here's a quick syntax summary:
151
152 * <and>...</and>
153
154 Contains one or more subconditions, all of which must be true.
155
156 * <condition>...</condition>
157
158 The top-level container for conditions, equivalent to an "and" group
159
160 * <equals>...</equals>
161
162 Contains two properties or a property and value, and is true if the
163 properties have equivalent values.
164
165 * <not-equals>...</not-equals>
166
167 Contains two properties or a property and value, and is true if the
168 properties have different values.
169
170 * <greater-than>...</greater-than>
171
172 Contains two properties or a property and a value, and is true if
173 the second property or the value has a value greater than the first
174 property.
175
176 * <greater-than-equals>...</greater-than-equals>
177
178 Contains two properties or a property and a value, and is true if
179 the second property or the value has a value greater than or equal
180 to the first property.
181
182 * <less-than>...</less-than>
183
184 Contains two properties or a property and a value, and is true if
185 the second property or the value has a value less than the first
186 property.
187
188 * <less-than-equals>...</less-than-equals>
189
190 Contains two properties or a property and a value, and is true if
191 the second property or the value has a value less than or equal
192 to the first property.
193
194 * <not>...</not>
195
196 Contains one subcondition, which must not be true.
197
198 * <not-equals>...</not-equals>
199
200 Contains two properties or a property and value, and is true if the
201 properties do not have equivalent values.
202
203 * <or>...</or>
204
205 Contains one or more subconditions, at least one of which must be
206 true.
207
208 * <property>...</property>
209
210 The name of a property to test.
211
212 * <value>...</value>
213
214 A literal value in a comparison.