次の方法で共有


Displaying text in XML gauges

Since this topic isn't covered at all in the FS 2004 SDK documentation, here's some info that I haven't yet seen covered online anywhere:

Displaying Text in Gauges

Formatting numbers

To display the value of a sim variable in text, use the following syntax:

<String>%(VARIABLE NAME)%!XY!</String>

Where:

VARIABLE NAME is any of the variables listed in parameters.doc. Be sure to include parentheses around the variable name in addition to the parentheses included with the %’s. (see example below) Note that there must not be a space between the ‘%’ and the ‘!’.

Y (required, case-sensitive) is the formatting of the variable, where:

  • s = string.
  • d = number (integer). If the number is not an integer, it is rounded to the nearest integer. Note that rounding, not truncation occurs.
  • f = number (floating point)

X is the minimum number of digits to display (optional)

If Y=’d’, the following rules apply:

  • If X is preceded by the digit ‘0’, then leading zeros are added if necessary.

  • If X is preceded by ‘-‘, text is left-aligned

  • If X is preceded by ‘+’, a ‘+’ is indicated in front of the number when the number is greater than 0 (a ‘-‘ is always used to indicate numbers less than 0)

  • If X is preceded by ‘ ‘ (space), leading spaces are added if necessary.

If Y=’f’, the following rule applies:

  • If a decimal point is used in the number X, the digit after the decimal point specifies the number of digits to display after the decimal point. See examples below,

 

Script

Result

%( 12.34 )%!4.3f!

12.340

%( 12.34 )%!04.3f!

12.340 (Leading ‘0’s not added to floating point numbers)

%( 12345.6789 )%!4.3f!

12345.679 (Number before decimal point does not limit the number of digits displayed before decimal point)

%( 34.56 )%!+d!

+35 (Note that rounding, not truncation, occurs)

%(234)%!5d!

  234 (note 2 leading spaces)

%( ‘foo’ )%!5s!

   foo (note 2 leading spaces)

%( 234 )%!3s!

234

Using Sim variables and expressions in text

For example:

<String>%((A:Indicated Altitude, feet))%!05f!</String>

Any of the operators described above (Boolean, string, arithmetic, etc.) may be used within the %() to create the intended expression. In other words,

<String>%(EXPRESSION)%!XY!</String>

Is valid, where EXPRESSION is any combination of valid sim variables and operators.

For example, the following string will display the current altitude in hundreds of feet or hundreds of meters, depending on the current international settings,

<String>
%( (P:Units of measure, enum) 2 ==
if{ (A:Indicated Altitude, meters) }
els{ (A:Indicated Altitude, feet) }
100 / )%!5d!
</String>

Keep in mind that the <String> element must be a child of a <Text> element, for example:

<Element>

    <Position X="0" Y="175"/>

    <Text

        X="80" Y="20"

        Bright="Yes"

        Length="10"

        Font="Quartz"

        Color="#E0E0E0" >

        String>05d: %((P:Local time,hours) flr)%!02d!</String>

    </Text>

</Element>

--------------------

Stay tuned for more info on this topic in a future post!

Comments

  • Anonymous
    November 09, 2005
    Hi,

    Wow, that's great. I've printed it out for reference. Thanks so much and I'm looking forward to the next installment.

    Thanks again,
  • Anonymous
    November 11, 2005
    Thanks! Actually, there was NO "documentation" worth much of anything in the SDK.

    This is a perfect example of the type of "SDK Content" so much needed... ;)
  • Anonymous
    December 14, 2005
    When displaying Mach number, I have typically 0.55. Is it possible to display this without the leading zero, that is, .55?
    cheers,
    nick