XML Gauge Text, Part III: Mind your %'s and ('s

It looks like a common mistake made by people creating XML gauges is to use too many percent signs (%).  For example, I saw this in a 3rd-party gauge recently:

%{if} % (On)%{else} % (Off)%{end}

The underlined percent signs are unnecessary, and the parser will try to translate the "On" and "Off" as an expression that can be calculated.  Recall that "%( )" is used to calculate expressions; for example:

%((A:Eng1 Oil Pressure, PSF) 20 <)

would equate to TRUE or FALSE and could be used with the %{if} conditional above to conditionally display text.

Thus, the 3rd-party gauge should have used:

%{if}(On)%{else}(Off)%{end}

This above information is also covered in the SDK, an excerpt of which is pasted below:

Conditional Gauge Strings

The format of conditions (if, then, else, and case statements) in gauge strings is different from that in other scripts. In gauge strings use the %{if} , %{else} , and %{end} constructs to choose which text to display.  Note that these keywords are case-sensitive and must be typed in lowercase. Also, there must not be a space between the ‘ % ’ and the ‘ { ‘. An if statement can be used without a corresponding else, in which case nothing is displayed if the result of the condition is false. The syntax for usage is one of the following:

  • %(CONDITIONAL)%{if}TEXT TO DISPLAY IF TRUE%{else}TEXT TO DISPLAY IF FALSE%{end}
  • %(CONDITIONAL)%{if}TEXT TO DISPLAY IF TRUE%{end}