How to create a variable in XML?

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!).
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:

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:
<GaugeString>Rand: %(L:INSRandFact31,number)%!d!\n
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.

<GaugeString>Rand: %((L:INSRandFact31,number))%!8.7f!%\n</GaugeString>
Last edited:
Here's an example that I use;

<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 == ||
     (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

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

<!-- Initialise offset if sticky -->
    <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>

  <Position X="82" Y="76" />
  <Image Name="Vertical_Speed_Needle.bmp">
    <Axis X="24" Y="5.5" PointsTo="East" />
    <Value Minimum="-20" Maximum="20">(L:VSI Adjusted, feet per minute) 100 /</Value>
        <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" />
      <Delay DegreesPerSecond="30" />
        <GAUGE_VERTICAL_SPEED Action="Freeze" />

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

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

Thanks guys. That's starting to make more sense. Chris, is the exclamation in the 'Sticky Needle' element is a NOT operand?
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.