Conditions: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
No edit summary
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Stub}}
'''Conditions''' (or '''<code>SGCondition</code>s''') 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 <code>$SGSOURCE/simgear/props/condition.hxx</code> and <code>[[$FG_ROOT]]/Nasal/props.nas</code>). Comparison of string-typed properties involves lexicographic ordering, as specified by the C++ operators <tt>&lt;</tt> and <tt>&gt;</tt>.
'''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 simgear/props/condition.hxx and [[$FG_ROOT]]/Nasal/props.nas). Comparison of string-typed properties involves lexicographic ordering, as specified by the C++ operators <tt>&lt;</tt> and <tt>&gt;</tt>.


== Usage ==
== Usage ==
Line 6: Line 5:
* All [[bindings]], all [[animations]]
* All [[bindings]], all [[animations]]
* State machines
* State machines
* Various parts of [[HUD]]s, 2D panels
* Various parts of [[HUD]]s, 2D panels, [[PUI]]/XML dialogs
And several other places.
* Autopilot / PropertyRule systems
… and several other places.


== Sample Expressions ==
== Sample conditions ==
This is a sample expression for checking if the throttle on the first engine is above half:
This is a sample expression for checking if the throttle on the first engine is above half:
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
Line 21: Line 21:


== Supported elements ==
== Supported elements ==
Each comparison (like less-than or greater-than-equals) requires either two <tt>&lt;property&gt;</tt> elements (the first with index=0 and the second with index=1) or a <tt>&lt;property&gt;</tt> (considered first) and <tt>&lt;value&gt;</tt> (considered second); booleans compare each of their child conditions. A <tt>&lt;condition&gt;</tt> element itself functions as an <tt>&lt;and&gt;</tt> element; that is, it can have several children, all of which must be true to make the whole condition true.
Each comparison (like <code>less-than</code> or <code>greater-than-equals</code>) requires either two <code>&lt;property&gt;</code> elements (the first with index=0 and the second with index=1) or a <code>&lt;property&gt;</code> (considered first) and <code>&lt;value&gt;</code> (considered second); booleans compare each of their child conditions. A <code>&lt;condition&gt;</code> element itself functions as an &lt;and<tt>&gt;</tt> element; that is, it can have several children, all of which must be true to make the whole condition true.
<syntaxhighlight lang="xml" enclose="div">
<syntaxhighlight lang="xml" enclose="div">
<and>
<and>
Line 33: Line 33:
<greater-than-equals>
<greater-than-equals>
<property> <!-- evaluates boolean value of specified property -->
<property> <!-- evaluates boolean value of specified property -->
<false/> <!-- static false value (<value> does NOT work in conditions !)-->
<true/><!-- static true value -->
</syntaxhighlight>
</syntaxhighlight>


Line 44: Line 46:


=== Source code ===
=== Source code ===
* {{repo link
* {{simgear source
| site  = sf
| path  = simgear/props/condition.hxx
| proj  = flightgear/simgear
| path  = next/tree/simgear/props/condition.hxx
| text  = simgear/props/condition.hxx
| text  = simgear/props/condition.hxx
}}
}}
* {{repo link
* {{simgear source
| site  = sf
| path  = simgear/props/condition.cxx
| proj  = flightgear/simgear
| path  = next/tree/simgear/props/condition.cxx
| text  = simgear/props/condition.cxx
| text  = simgear/props/condition.cxx
}}
}}

Latest revision as of 21:28, 7 April 2022

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