Conditions: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(→‎Related content: Readme and source code links)
m (→‎Supported elements: rephrase/grammar/code-language mix)
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>s (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 <tt>&lt;conditions&gt;</tt>. A <tt>&lt;condition&gt;</tt> node itself functions as an <tt>&lt;and&gt;</tt>.
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.
<syntaxhighlight lang="xml" enclose="div">
<syntaxhighlight lang="xml" enclose="div">
<and>
<and>

Revision as of 04:17, 21 May 2015

This article is a stub. You can help the wiki by expanding it.

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).

Usage

Conditions are supported in

And several other places.

Sample Expressions

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 -->

Related content

Readme file

Source code