• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FS2004 How to Conditionally Display String Values

Milton_Shupe

Resource contributor
Messages
331
Country
us-newmexico
I know how to display text and strings, but I have not yet learned how to display strings conditionally.
I have a Sail Management Gauge. One element is to display the Sail Configuration based on a variable.

The display is made up of two parts- a fixed text and a variable conditionally displayed string. (See image at bottom)

For example: Sail Config: Running

The code below shows the fixed text, a range statement, and a variable string that needs to change based on range values.

I need to understand how to connect range value statements to conditionally display the necessary strings.


Code:
<!-- Sail Configuration -->

<!-- Fixed Text -->
   <Element>
     <Position X="320" Y="247"/>
      <Text X="100" Y="25" Length="15" Font="Arial" Color="#00FFFF" >
            <String>Sail Config:</String>
      </Text>
   </Element>

<!-- Conditional Variable Text Displayed based on range values -->


    <Value> 151 210 (A:Trailing edge flaps0 left angle, degrees) rng </Value>


    <Element>
     <Position X="400" Y="277"/>
      <Text X="100" Y="25" Length="15" Font="Arial" Color="#00FFFF" >
            <String>Running</String>
      </Text>
   </Element>

Here's the scoop:

-------- This table below lists the ranges and the associated string values to be displayed.

Based on Sail Arm positions (flap settings covering ranges of degrees of movement shown), display the following text on the gauge.


a. 0- 60 degrees, Display Close Hauled
b. 61-120 degrees, Display Beam Reach
c. 121-150 degrees, Display Broad Reach
d. 151-210 degrees, Display Running
e. 211-240 degrees, Display Broad Reach
f. 241-300 degrees, Display Beam reach
g. 301-359 degrees, Display Close Hauled

I love the FS2X.com site but it does not spend a lot of time explaining conditional statements.

I would appreciate any guidance. Thanks in advance. :)

sailconfig.jpg
 
Last edited:
Hello Milton,

There are a few approaches to this. One is to set up seven separate display elements and use <Visible> tags in each one using 7 different rng expressions like you have posted above. When the expression within <Visible> evaluates to True, the element is displayed, otherwise, it is not.

A second approach is to use the %{case} construct within <String>. The basics of this are covered in this old Microsoft post, but you can add %{case} to the list of %{if} and %{else}. For an example, take a look at lines 1366, 1367, and 1380 in the stock gps_500.xml gauge included with FS2004. You'll still need some rng or a nested if{ } expression to index the {case} selection.

Yet another would be to use %{if} %{else} within <String>.

I'll try to post a working example later tonight unless someone beats me to it.

Hope this helps,

Bob

I would also double check the correct syntax of the flap angle A:Var (A:Trailing edge flaps0 left angle? I'm not aware of this one) and also the range of possible flap movement ... 0 to 360 degrees?

BTW, we don't see too many ships in this forum! Bill Ortiz (lionheart) built an electric plane which was about the most exotic thing in here until your sailing ship
 
Last edited:
Try this:
Code:
<String>%((A:Trailing edge flaps0 left angle, degrees) dnor sp0 151 210 l0 rng)%{if}Running%{else}%(121 240 l0 rng)%{if}Broad Reach%{else}%(61 300 l0 rng)%{if}Beam reach%{else}Close Hauled%{end}%{end}%{end}</String>
 
Bob,

(A:TRAILING EDGE FLAPS0 LEFT ANGLE, ) ? I'm not aware of this one, and also the range of possible flap movement ... 0 to 360 degrees?
It is available from FS9/FSX/ESP sdk, also he could get 360 degrees as long as it is entered correctly in the aircraft.cfg [flaps] section.

Milton,

Oh my! there are many ways to skin this cat.

1. Use nested {if} {else} within the string itself as Luka posted.
2. Use {case} within the string, but this "could" require evaluation in a separate element.
3. My idea, IIRC stores (s12, sp12, l12) are the only user vars (outside XMLTools) where a user can store a string. It also requires evaluation in a separate element.
s12/sp12/l12 = flap angle for eval
s13/sp13/l13 = stored string after eval

Code:
<!-- Sail Configuration -->

<!-- Fixed Text -->
   <Element>
     <Position X="320" Y="247"/>
      <Text X="100" Y="25" Length="15" Font="Arial" Color="#00FFFF" >
            <String>Sail Config:</String>
      </Text>
   </Element>

<!-- Evaluate and Store the string for display -->
    <Element>
      <Select>
        <Value>
(A:Trailing edge flaps0 left angle, degrees) dnor sp12
151 210 l12 rng if{ 'Running' sp13 quit }
0 60 l12 rng 301 359 l12 rng || if{ 'Close Hauled' sp13 quit }
61 120 l12 rng 241 300 l12 rng || if{ 'Beam Reach' sp13 quit }
121 150 l12 rng 211 240 rng || if{ 'Broad Reach' sp13 quit }
        </Value>
      </Select> 
   </Element>

<!-- Display the string -->
    <Element>
     <Position X="400" Y="277"/>
      <Text X="100" Y="25" Length="15" Font="Arial" Color="#00FFFF" >
            <String>%(l13)%!s!%</String>
      </Text>
   </Element>

Mileage may vary, not tested & only 1 cup of coffee consumed :coffee: - not awake yet :confused:

Edit - After the second cup, Luka's looks great! Elegant!
 
Last edited:
Just a side note: floating point values (like (A:Trailing edge flaps0 left angle, degrees) ) compared against a range of interger values might require an integer cast to avoid possible flickers:

... (A:Trailing edge flaps0 left angle, degrees) dnor int sp0 ... etc

Tom
 
Wow! Excellent responses guys. :) As one just getting into xml coding (as I no longer have a gauge programmer on the team), these options are very instructional and helpful.
Although I do have a vast team inventory of xml gauges and some makemdl.parts to reference, I seem to run into things for which I find no examples to provide insight.
Your assistance is therefore greatly appreciated. Although I have been modeling aircraft since 2002, I am just now learning xml and only come for help when research yields no answers.

As for the flaps degrees question, the sails are animated over 99 degrees, 11 degrees for each stop, 0-9 in the flaps.0 section.
Thanks for questioning the 360 as it woke me up :) The table should have read more as follows:

Pos. --Degrees-------------Display
0. 0-0 degrees, Display Close Hauled
1. 1-11 degrees, Display Close Hauled
2. 12-22 degrees, Display Beam Reach
3. 23-33 degrees, Display Broad Reach
4. 34-44 degrees, Display Running
5. 45-55 degrees, Display Running
6. 56-66 degrees, Display Broad Reach
7. 67-77 degrees, Display Beam reach
8. 78-88 degrees, Display Close Hauled
9. 89-99 degrees, Display Close Hauled

Now I will go implement a solution. :) Thanks a bunch!

EDIT: Ahhh Gentlemen; it works beautifully. :) Thank you very much! Now, on to the next xml challenge, limiting speed over the water by controlling throttle inputs. Not an AP, just a speed limiter. It takes a lot of power to get her moving depending on wind direction but in "running" or "Broad Reach" sails, she wants to scoot.
 
Last edited:
Bob,
It is available from FS9/FSX/ESP sdk, also he could get 360 degrees as long as it is entered correctly in the aircraft.cfg [flaps] section.
Well, whaddayaknow. I see that it's a valid variable, but I never saw it in the FS9 or ESP versions of the SDK. Apparently, I don't dig deep enuf. Lazy guy!

Do you know the difference between (A:TRAILING EDGE FLAPS LEFT ANGLE, degrees) and (A:TRAILING EDGE FLAPS0 LEFT ANGLE, degrees)? That is, when would you use one versus the other? Aircraft and aircraft.cfg specific?

Bob
 
Last edited:
I actually use it quite often (up to 3 flap sets) as I use multiple flaps sets to have better control over lift, drag, and pitch for various flap settings. It is especially useful for a fowler flap setup or non-standard flap types

As shown below for the Lockheed Harpoon, Ventura, or Lodestars:

Code:
[flaps.0]       //Trailing Edge Flaps
type = 1
span-outboard = 0.5
extending-time = 7
flaps-position.0 = 0
flaps-position.1 = 5, 131
flaps-position.2 = 15, 125
flaps-position.3 = 25, 119
damaging-speed = 131
blowout-speed =  142
system_type = 1
lift_scalar = 0
drag_scalar = 0
pitch_scalar = 1


[flaps.1]       //Leading Edge Flaps
type = 2
span-outboard = 0.5
extending-time = 7
flaps-position.0 = 0
flaps-position.1 = 12.5
flaps-position.2 = 25
flaps-position.3 = 25
damaging-speed = 131
blowout-speed =  142
system_type = 1
lift_scalar = 1
drag_scalar = 0
pitch_scalar = 0

[flaps.2]       //Leading Edge Flaps
type = 2
span-outboard = 0.5
extending-time = 7
flaps-position.0 = 0
flaps-position.1 = 2
flaps-position.2 = 3
flaps-position.3 = 25
damaging-speed = 131
blowout-speed =  142
system_type = 1
lift_scalar = 0
drag_scalar = 1
pitch_scalar = 0
 
Ah, ok, now I get it. I always fly a Cessna 421 which has only simple flaps. Thanks
 
Back
Top