Conditions

From FlightGear wiki
Jump to navigation Jump to search

Conditions (or SGConditions) in the SimGear library are a property-based representation of custom conditions based on comparing property values. They can be evaluated from both C++ and Nasal (see $SGSOURCE/simgear/props/condition.hxx and $FG_ROOT/Nasal/props.nas). Comparison of string-typed properties involves lexicographic ordering, as specified by the C++ operators < and >.

Usage

Conditions are supported in

  • All bindings, all animations
  • State machines
  • Various parts of HUDs, 2D panels, PUI/XML dialogs
  • Autopilot / PropertyRule systems

… and several other places.

Sample conditions

This is a sample expression for checking if the throttle on the first engine is above half:

<condition>
  <greater-than>
    <property>/controls/engines/engine[0]/throttle</property>
    <value type="double">0.5</value>
  </greater-than>
</condition>

Supported elements

Each comparison (like less-than or greater-than-equals) requires either two <property> elements (the first with index=0 and the second with index=1) or a <property> (considered first) and <value> (considered second); booleans compare each of their child conditions. A <condition> element itself functions as an <and> element; that is, it can have several children, all of which must be true to make the whole condition true.

<and>
<or>
<not> <!-- acts like logical inverse of <and>, i.e. accepts child conditions -->
<equals>
<not-equals>
<less-than>
<greater-than>
<less-than-equals>
<greater-than-equals>
<property> <!-- evaluates boolean value of specified property -->
<false/> <!-- static false value (<value> does NOT work in conditions !)-->
<true/><!-- static true value -->

Related content

Wiki articles

Readme file

Source code