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

FSX XML Syntax Question

Messages
159
Country
us-colorado
I have very little XML experience and am trying to modify some existing XML code to fix a bug that sometimes results in the display of invalid wind headings. The purpose of the first 3 lines below is to calculate magnetic wind direction from true wind direction. If subtracting the magnetic variation from the true wind heading produces a negative result, 360 is added in line 2, and conversely, if the result of subtracting the variation is greater than 360, 360 is subtracted in line 3. Seems simple enough in concept. However, I would greatly appreciate it if someone could tell me why the two if{} statements in lines 2 and 3 that correct for invalid wind headings don't work. The remaining code then either displays the wind direction in degrees or in general headings like N, NE, W, etc depending on the value of DirMode. That part works (probably because I didn't write it).

I realize now that there is a macro dnor that eliminates the need for the if{} statements, but at this point I'm trying to just figure out my coding mistake(s) in lines 2 and 3.

I've asked this question elsewhere, but haven't gotten a response so far.

Thanks much,
Al

Code:
<GaugeString>
%((A:AMBIENT WIND DIRECTION,degrees) (A:MAGVAR,degrees) - (>L:AdjDir,degrees))
%((L:AdjDir,degrees) 0 &lt; if{(L:AdjDir,degrees) 360 + (>L:AdjDir,degrees)})
%((L:AdjDir,degrees) 360 &gt; if{(L:AdjDir,degrees) 360 - (>L:AdjDir,degrees)})

%((L:DirMode,bool) 1 == )
%{if}
%((L:AdjDir,degrees) near)%!03d!
%{else}
%((L:AdjDir,degrees) 22.5 + 45 / int) %{case} %{:0} N%{:1}NE%{:2} E%{:3}SE%{:4} S%{:5}SW%{:6} W%{:7}NW%{:8} N%{end}
%{end}
</GaugeString>
 
Last edited:
First, put your code in [code] tags. It makes the formatting in the forum much more legible.

Second, I think that if{...} and els{...} statements aren't evaluated if you write them like that in formatted text strings. Maybe the code below works better.
Code:
<GaugeString>
%((A:AMBIENT WIND DIRECTION,degrees) (A:MAGVAR,degrees) - (>L:AdjDir,degrees))
%((L:AdjDir,degrees) 0 &lt;)%{if}%((L:AdjDir,degrees) 360 + (>L:AdjDir,degrees))%{end}
%((L:AdjDir,degrees) 0 &lt;)%{if}%((L:AdjDir,degrees) 360 + (>L:AdjDir,degrees))%{end}

%((L:DirMode,bool) 1 == )
%{if}
%((L:AdjDir,degrees) near)%!03d!
%{else}
%((L:AdjDir,degrees) 22.5 + 45 / int) %{case} %{:0} N%{:1}NE%{:2} E%{:3}SE%{:4} S%{:5}SW%{:6} W%{:7}NW%{:8} N%{end}
%{end}
</GaugeString>

If it still won't work, you should remove the string formatting and put the first three lines into a simple <Update> block at the top of the gauge.
 
I also put a space before and after if{ and } Might help? And an Update section is indeed a more logical place for those.
 
This is code for a relative wind indicator which might help.

Code:
<Gauge Name="RelativeWind" Version="1.0">
   <Image Name="WIND_Background.bmp" Luminous="Yes" ImageSizes="118,118"/>
   <Element>
      <Position X="0" Y="0"/>
      <Select>
         <Value>(L:OHP_ILL,bool) 1 == (L:BUS_SWITCH,number) (P:local time, seconds) &lt; and</Value>
         <Case Value="1">
            <Image Name="wind_ring.bmp" Bright="Yes"/>
         </Case>
      </Select>
   </Element>
   <Element>
      <Position X="59" Y="59"/>
      <Image Name="WIND_Needle.bmp" Luminous="Yes" ImageSizes="98,18">
         <Axis X="45" Y="9" PointsTo="East"/>
      </Image>
      <Rotate>
         <Value>(A:Ambient wind direction, radians) (A:Plane heading degrees gyro, radians) - pi 2 / - </Value>
         <Failures>
            <SYSTEM_ELECTRICAL_PANELS Action="Freeze"/>
            <GAUGE_RelativeWind Action="Freeze"/>
         </Failures>
         <Delay DegreesPerSecond="180"/>
      </Rotate>
   </Element>
   <Element>
      <Position X="33" Y="85"/>
      <Text X="65" Y="14" Length="8" Fixed="Yes" Font="Arial" FontHeight="0" FontWeight="500" Charset="Default" Attributes="Normal" Adjust="Center" VerticalAdjust="Center" Multiline="No" Color="#CEC6A5" BackgroundColor="transparent" Bright="Yes" UseTransparency="Yes">
         <String>%((A:AMBIENT WIND DIRECTION,radians) (A:PLANE HEADING DEGREES GYRO,radians) - sin (A:AMBIENT WIND VELOCITY,knots) * )%!3.0f! kts</String>
         <Failures>
            <SYSTEM_ELECTRICAL_PANELS Action="Freeze"/>
         </Failures>
      </Text>
   </Element>
   <Mouse>
      <Tooltip>Relative Wind Indicator
%((A:AMBIENT WIND DIRECTION,degrees))%!3.0f!&#176;% %((A:AMBIENT WIND DIRECTION,radians) (A:PLANE HEADING DEGREES GYRO,radians) - sin (A:AMBIENT WIND VELOCITY,knots) * abs )%!3.0f!kts</Tooltip>
   </Mouse>
</Gauge>
 
In the OP example, there are two different and valid conditional constructions -one is the classical if{} used in text scripts, an the other is the string's {if} evaluator.

The first one is used in lines 2 and 3 but is not working because it needs a space after the opening bracket and before the closing one , as tgibson stated.

Example: if{ a b c } els{ d e f }

The second one is properly used, was reported as working fine by the OP and takes the form:

{if} {else} {end}

without embedded spaces ({end} NOT being mandatory but recommendable)

Tom
 
It is painful to think of how many frustrating hours those missing spaces cost me! :(

Thanks all for teaching me something. I won't make that mistake again. :)

Al
 
So the actual problem was the missing spaces?

Well, that is what the experts are telling me. I'm currently using the dnor function in place of the IF statements, but since there is interest I will go back and change the code to see if the IF statements now work with the spaces, and report back.
Al
 
I went back and changed the coding to try the IF statements as listed in Post#1 above EXCEPT I added in the spaces as tgibson and Tom suggested, and the code worked just fine. So I've confirmed the missing spaces were the problem.

I'd like to ask a related question. I understand the % symbol is used in string syntax, but I don't know quite how to interpret it, such as used in Post#2 above. Do you see it as a concatenation symbol, do you expect to see it used in pairs like parentheses, do you see it as an operator of some type, or what? In other words, how do you "read" it or characterize its use with strings?

Thx again for all the help,
Al
 
I just regard it as a delimiter to distinguish a string from gauge code.

P.S: To print "%" in formatted strings, you have to use "%%".
 
My understanding (limited as it is!) is that the "%" indicates that what follows is not part of the string to be shown, but a statement to be evaluated (so essentially, code), or formatting information (%!3.1d!).
 
My understanding (limited as it is!) is that the "%" indicates that what follows is not part of the string to be shown, but a statement to be evaluated (so essentially, code), or formatting information (%!3.1d!).

Your understanding is absolutely correct.

Tom
 
Again, thanks all for the information, extremely helpful.

I've been a bit frustrated because I can't seem to find a document the defines/provides the type of XML information you have helped me with. For example, while I know what !3.1d! means (I think), I'm sure there are variations but I can't seem to locate the appropriate "manual". Has XML, or at least the type of XML used in flight simulation, evolved in kind of an ad hoc manner so the type of detailed syntax documentation I'm looking for doesn't exist as it does for other computer languages, or is it I'm just not looking/searching in the right places?

Al
 
A good part of the knowledge is stored here on FSDev (most of it in the forums), some can be found by googling and there's always the SDK's reference documentation.
I exclusively use the online version, which can be found here:
https://msdn.microsoft.com/en-us/library/cc526948.aspx

A reference sheet for XML is here:
https://msdn.microsoft.com/en-us/library/cc526953.aspx

It deals mostly with the very basics and operations. Markup (gauge structure and tags) is best learned by dissecting and studying existing gauges.
 
A good part of the knowledge is stored here on FSDev (most of it in the forums), some can be found by googling and there's always the SDK's reference documentation.
I exclusively use the online version, which can be found here:
https://msdn.microsoft.com/en-us/library/cc526948.aspx

A reference sheet for XML is here:
https://msdn.microsoft.com/en-us/library/cc526953.aspx

It deals mostly with the very basics and operations. Markup (gauge structure and tags) is best learned by dissecting and studying existing gauges.

Yes, thanks, I've been reading those documents and they are certainly very helpful, but don't have a lot of XML syntax details. I feel fortunate to have found this site -- good resources and helpful folks.
Al
 
Where can I read about the difference between the <Value> and <Script> tags, and also about the <Select> tag?

What is the scope (availability) of a variable determined in an element with respect to other elements in the program?

Al
 
Hi,

For custom variables, the G: variables are available only within that gauge, and are reset to 0 any time the gauge loads. The L: variables are shared between all gauges in the panel/VC, and are reset only when the plane is reloaded. (I believe that is the reset difference - there is a difference). A: and E: (FS) variables are always available to all gauges/VC.

Hope this helps,
 
G: variables are for use within a gauge only, L: variables are used across gauges and by custom animations and visibilities in the model file. The values of both types of variable are not retained across FSX sessions or aircraft/panel reloads and will reset to 0. There are, however, possibilities to store the value of L: variables in an external file and load said values when the plane is initialized in a new session or after a reload.
 
OK, so it seems that within a particular XML file variable scope is not an issue.
Good info, thanks.
Al
 
Back
Top