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

How to create a variable in XML?

Messages
57
Country
sweden
I'm new to using XML for gauge development in FSX / P3D, and I am stuck. How can I store the value result of an expression in a custom variable so it can be used in other parts of the XML? This value will be calculated once when the panel is opened. (I come from a Java background!).
 
Messages
57
Country
sweden
Thanks. I was trying to implement Tom Aguilo's random number generator, which gives a pseudo random number from between 1 and 10, as shown here: https://www.fsdeveloper.com/wiki/index.php?title=XML:_Random_Number_Generators

From what I can so far understand, the result seems to be stored in an "L:type variable", and this is in a macro tag. So how can I use that stored value later? For example, let's just say I wanted to output the value in some gaugetext? I've been trying to get this to work but I keep seeing zero:
Code:
<GaugeString>Rand: %(L:INSRandFact31,number)%!d!\n
</GaugeString>
 
Messages
440
Country
us-wisconsin
It might be better if you post all the code. ( from <Gauge> to </Gauge> )
Do you have an <Update>section so that the macro is called and the value stored in the L:Var?
Also the output is between 0 & 1, not sure the print code %!d!% will work, try a float instead.
And finally the string is wrong, you need to enclose the L:Var in parentheses in order for the string to evaluate it.

ex.
XML:
<GaugeString>Rand: %((L:INSRandFact31,number))%!8.7f!%\n</GaugeString>

Roman
 
Last edited:
Messages
840
Country
indonesia
Here's an example that I use;

XML:
<Gauge Name="Vertical Speed Indicator" Version="1.0">
<Image Name="Vertical_Speed_Background.bmp" />

<Macro Name="XMLRandom">
  (L:RandomSeed1,number) 0 == (L:RandomSeed2,number) 0 == ||
    if{
     (P:Absolute Time,seconds) abs d 2147483563 % (>L:RandomSeed1,number)
     sqrt d d * * abs 2147483599 % (>L:RandomSeed2,number)
    }
  (L:RandomSeed1,number) 40014 * 2147483563 % (>L:RandomSeed1,number)
  (L:RandomSeed2,number) 40692 * 2147483399 % (>L:RandomSeed2,number)
  (L:RandomSeed1,number) (L:RandomSeed2,number) - 2147483563 / s1
  l1 0 &lt; if{ l1 ++ s1 } l1
</Macro>

<!-- Random Sticky Needle -->
<Element>
  <Select>
    <Value>(L:RanLatch,Bool) ! if{ @XMLRandom (>L:RandomNumber,number) 1 (&gt;L:RanLatch,Bool) }</Value>
  </Select>
</Element>

<!-- Initialise offset if sticky -->
<Element>
  <Select>
    <Value>(L:VSI Adj Latch,Bool) ! if{ 1 (&gt;L:VSI Adj Latch,Bool) (L:RandomNumber,number) 0.8 &gt; if{ 100 (&gt;L:VSI Adj,Feet per minute) } }</Value>
  </Select>
</Element>

<Element>
  <Position X="82" Y="76" />
  <Image Name="Vertical_Speed_Needle.bmp">
    <Axis X="24" Y="5.5" PointsTo="East" />
  </Image>
  <Rotate>
    <Value Minimum="-20" Maximum="20">(L:VSI Adjusted, feet per minute) 100 /</Value>
      <Nonlinearity>
        <Item Value="-20" X="143" Y="85" />
        <Item Value="-15" X="122" Y="126" />
        <Item Value="-10" X="69" Y="142" />
        <Item Value="-5" X="26" Y="115" />
        <Item Value="0" X="14" Y="76" />
        <Item Value="5" X="26" Y="39" />
        <Item Value="10" X="69" Y="12" />
        <Item Value="15" X="122" Y="28" />
        <Item Value="20" X="144" Y="69" />
      </Nonlinearity>
      <Delay DegreesPerSecond="30" />
      <Failures>
        <GAUGE_VERTICAL_SPEED Action="Freeze" />
      </Failures>
  </Rotate>
</Element>

<Element>
  <Select>
    <Value>(A:VERTICAL SPEED,Feet per minute) (L:VSI Adj,Feet per minute) + (&gt;L:VSI Adjusted,Feet per minute)</Value>
  </Select>
</Element>

<Mouse>
  <Tooltip ID="TOOLTIPTEXT_VSI_FEET_PER_MIN" MetricID="TOOLTIPTEXT_VSI_METERS_PER_SEC" />
    <Area Left="26" Right="134" Top="22" Bottom="131">
  <Cursor Type="Hand"/>
  <Click>(L:VSI Adj,Feet per minute) 49 &gt; if{ (L:VSI Adj,Feet per minute) 50 - (&gt;L:VSI Adj,Feet per minute) }</Click>
  </Area>
 </Mouse>

</Gauge>
 
Messages
57
Country
sweden
Thanks guys. That's starting to make more sense. Chris, is the exclamation in the 'Sticky Needle' element is a NOT operand?
 

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
Yes, the ! in this instance is a "not equal to"...
 
Messages
840
Country
indonesia
Since L:RanLatch is a bool, it's either true or it isn't. The ! just means I want to know if it isn't true. i.e. I haven't ran this line of code yet. do what follows.
 
Top