• 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 Decreasing variable

Dutcheeseblend

Resource contributor
Messages
1,541
Country
netherlands
Hi there,

I'm sorry I don't even know how to call this exactly, but anyway: I want a decreasing variable. :D

For my Danish D.21, I'll be adding a kind of oxygen system. This system provides oxygen to the pilot from an onboard pressure vessel, of which the quantity and pressure are displayed in a visual gauge. Of course, after switching on the oxygen supply, the quantity (and pressure) in the vessel decrease. I want to display this using the visual gauge (simple 3D animated needle). How could I create the variable that decreases with time (if and only if the oxygen is switched on)?

Any ideas? I'm only an XML rookie, so... ;)

Kind regards, Daan
 
initialize an L var at value of choice.

Code:
(L:oxy, enum) rate/sec 0.05555 * - (>L:oxy, enum)

rate/sec can be a constant or a variable of your choice. 0.05555 scales it down to fit 18Hz gauge cycle.
 
Thanks! I'll give it a try.

If I use the bool for the oxygen enabling switch as the rate/sec variable, the L:oxy will stop decreasing further, is that true?

Regards, Daan
 
Tried it out, but it didn't work. I am however not sure whether I'm doing it the right way.

This is from my modeldef.xml. I put the code for the decreasing variable in the MouseRect section of the oxygen switch, while displaying this variable in another animation (the quantity needle, FD21_oxygen_quantity).

Code:
<PartInfo>
        <Name>FD21_oxygen_switch</Name>
        <AnimLength>100</AnimLength>
        <Animation>
            <Parameter>
                <Code>
        (L:FD21_oxygen_switch,bool) 100 *
        </Code>
        <Lag>400</Lag>
            </Parameter>
        </Animation>
    <MouseRect>
        <Cursor>Hand</Cursor>
            <TooltipText>Oxygen Regulator (%((L:FD21_oxygen_switch,bool))%{if}Open%{else}Closed%{end})</TooltipText>
            <MouseFlags>LeftSingle</MouseFlags>
           <CallbackCode>
    (L:FD21_oxygen_switch,bool) ! (>L:FD21_oxygen_switch,bool)
    (L:FD21_oxygen_pressure,enum) 10 ==
    (L:FD21_oxygen_quantity,enum) 100 ==
    (L:FD21_oxygen_pressure,enum) (L:FD21_oxygen_switch,bool) 0.05555 * - (>L:FD21_oxygen_pressure,enum)
    (L:FD21_oxygen_quantity,enum) (L:FD21_oxygen_switch,bool) 0.05555 * - (>L:FD21_oxygen_quantity,enum)
            </CallbackCode>
    </MouseRect>
</PartInfo>

<PartInfo>
        <Name>FD21_oxygen_quantity</Name>
        <AnimLength>100</AnimLength>
        <Animation>
            <Parameter>
                <Code>
        (L:FD21_oxygen_quantity,enum)
        </Code>
            </Parameter>
        </Animation>
</PartInfo>

Any clues? The FD21_oxygen_quantity stays at 0...

Regards, Daan
 
It needs to be in a XML gauge not the modeldef. Also, why are you using the switch bool as the rate at which you decrement?
 
You cannot place a 'formula' in a mouse section because it is only 'active' for the duration of the mouse click.

Instead, place the 'formula' in the <Code> section of the needle's script.

Code:
(L:FD21_oxygen_switch,bool)
if{
     (L:FD21_oxygen_quantity,enum) (L:FD21_rate,enum) 0.05555 * - (>L:FD21_oxygen_quantity,enum)
  }
 
It needs to be in a XML gauge not the modeldef. Also, why are you using the switch bool as the rate at which you decrement?

Ok, I see. Well, because it will only decrement if the bool is true. That's my interpretation at least.

Thanks Mr Leaming, I'll try it out!

Daan
 
Maybe try this -

Code:
<PartInfo>
        <Name>FD21_oxygen_switch</Name>
        <AnimLength>100</AnimLength>
        <Animation>
            <Parameter>
                <Code>
        (L:FD21_oxygen_switch,bool) 100 *
        </Code>
        <Lag>400</Lag>
            </Parameter>
        </Animation>
    <MouseRect>
        <Cursor>Hand</Cursor>
            <TooltipText>Oxygen Regulator (%((L:FD21_oxygen_switch,bool))%{if}Open%{else}Closed%{end})</TooltipText>
            <MouseFlags>LeftSingle</MouseFlags>
           <CallbackCode>
    (L:FD21_oxygen_switch,bool) ! (>L:FD21_oxygen_switch,bool)    
            </CallbackCode>
    </MouseRect>
</PartInfo>

<PartInfo>
        <Name>FD21_oxygen_quantity</Name>
        <AnimLength>100</AnimLength>
        <Animation>
            <Parameter>
                <Code>
        <!-- INI SECTION, FILL TANKS ON AIRCRAFT RESET -->
        (L:FD21_oxy_ini,bool) ! if{ 1 (>L:FD21_oxy_ini,bool) 10  (>L:FD21_oxygen_pressure,enum) 100 (>L:FD21_oxygen_quantity,enum)  }
        <!-- DECREASE PRESS/QUANT IF OXY ON, BOTH RATES ARE SET AT 0.015, ADJUST ACCORDINGLY -->
        (L:FD21_oxygen_switch,bool) if{ 
        (L:FD21_oxygen_pressure,enum) 0.015 0.05555 * - (>L:FD21_oxygen_pressure,enum)
        (L:FD21_oxygen_quantity,enum) 0.015 0.05555 * - (>L:FD21_oxygen_quantity,enum)
         } 
       <!-- READ OXY QTY -->   
        (L:FD21_oxygen_quantity,enum)
        </Code>
            </Parameter>
        </Animation>
</PartInfo>
 
No, it will not work that way.

What does any number times zero equal?
98 * 0 = ?

Not quite....His script would actually evaluate to (L:FD21_oxygen_quantity,enum) 0 - so it simply wouldn't decrement. Its a handy and valid idea...except for 2 gotchas. First of all, L var bools aren't necessarily going to be 1 when true. They might be -1. Hence his oxygen value would actually increase with that formula. Secondly, even if the bool was 1, his counter would then decrement at a rate of 1 per second. He may want to slow it down.....Or speed up as he sees fit.
 
I could help you but the coding for the oxygen and depressurisation systems is vast and a bit complex. However,
I'll have a go.
Code:
<Gauge Name="OxyGauge">
   <Image Name="OX_PRESS2.bmp" Luminous="Yes"/>
   <Update Frequency="9"/>

  <!-- Oxygen Tank Replenish (135000 = 4 hours and ten minutes) -->
  <Element>
  <Select>
    <Value>(A:SIM ON GROUND, bool) 1 == (A:GROUND VELOCITY, knots) 1 &lt; and if{ 135000 (&gt;L:OxyLevel,number) }</Value>
  </Select>
</Element>

<!-- Oxygen Flow -->
<Element>
  <Select>
    <Value>(A:ELECTRICAL MASTER BATTERY, bool) 1 == (L:Oxy_On,bool) 1 == (L:OxyLevel,number) 0 &gt; &amp;&amp; &amp;&amp;
if{ (L:OxyFlow,number) }</Value>
  </Select>
</Element>


<!-- Low Level (2700 = 5 minutes)-->
   <Element>
      <Select>
         <Value>(L:OxyLevel,number) 2700 &lt; if{ 1 (&gt;L:OxyLow,bool) } els{ 0 (&gt;L:OxyLow,bool) }</Value>
      </Select>
   </Element>


   <Element>
      <Position X="227" Y="227"/>
      <Image Name="OX_NEEDLE2.bmp" Luminous="1" PointsTo="North">
         <Axis X="43" Y="192"/>
      </Image>
      <Rotate>
         <Value>(L:OxyLevel,number)</Value>

         <Nonlinearity>
            <Item Value="-10" X="95" Y="342"/>
            <Item Value="0" X="95" Y="342"/>
            <Item Value="33750" X="43" Y="173"/>
            <Item Value="67500" X="192" Y="48"/>
            <Item Value="135000" X="401" Y="309"/>
         </Nonlinearity>
         <Delay DegreesPerSecond="60"/>
      </Rotate>
   </Element>

   <Mouse>
      <Tooltip>Mains Oxygen Supply %( (L:OxyLevel,number) 0.000741 *)%!3.1f!%% - %( (L:oxy_mains,number) )%!3.1f!% p.s.i %</Tooltip>
   </Mouse>
</Gauge>

This is just a tiny part of all the code and relates to the main oxygen tanks pressure gauge.
(L:OxyFlow,number) relates to the type of emergency or whether the emergency or therapeutic knob has been pulled. It is either a 2 or a 4. The tank is always replenished simply by being on the ground. How much is in the tank is another element
Code:
<Element>
      <Select>
         <Value>(L:OxyLevel,number) 72.97297 / (>L:oxy_mains,number) ++</Value>
      </Select>
   </Element>
(>L:oxy_mains,number) is the conversion into psi. The actual countdown while in use is in
Code:
<!-- Oxygen Tank  -->
<Element>
  <Select>
    <Value>(A:ELECTRICAL MASTER BATTERY, bool) 1 == (L:Oxy_On,bool) 1 == (L:OxyLevel,number) 0 &gt; &amp;&amp; &amp;&amp;
if{ (L:OxyLevel,number) (L:OxyFlow,number) 1 * (P:SIMULATION RATE,Number) * - (&gt;L:OxyLevel,number) }</Value>
  </Select>
</Element>
135000 represents the number to be initally started on counting down 9 times a second instead of 18.
Here is "just" the oxygen panel. In addition there is also the cabin pressurisation system plus --
<!-- Cabin Pressure Events --> x 5
<!-- Cabin Pressure Aural Warning -->
<!-- Aural Warning Cancel -->
<!-- Oxygen Mask donned -->
<!-- Crew Oxygen and Panel Supply Pressure Reduction Valve-->
<!-- Main Tanks Oxygen Supply Pressure -->
<!-- Cabin Oxygen Supply cutoff when remaining pressure sufficient for crew only -->
<!-- Emergency Oxygen Available above 14000ft -->
<!-- Emergency Oxygen Available above 17000ft -->
<!-- Oxygen Mask not Pulled in time -->
<!-- Hypoxia settings--> x 4
<!-- Hypoxia recovery-->

In all enough coding to fill a novel. Hope you find this useful.
oxy1.jpg
 
Now it's getting a bit too difficult for me...:confused:

Thanks for the replies, I'll try the advices soon. @vololiberista I won't make it as dedicated as that. It should merely be a visual decoration.

Regards, DCB
 
Why not do it the other way around and simply increase a variable?
That way, you won't have to worry about initializing a "supply remaining" variable after every loading of the aircraft.
You, of course, also need to animate the supply indicator gauge the wrong way around, but that's easily doable.

The code berlow uses a tried and trusted variation of a timer to increase a variable every 10 seconds. After 30 Minutes (6*10*30), the pilot will be dead due to oxygen deprivation.

Code:
(P:ABSOLUTE TIME, seconds) (L:START TIME, seconds) - 10 &gt;
  if{ (P:ABSOLUTE TIME, seconds) (&gt;L:START TIME, seconds)
(L:Oxygen Supply, number) ++ (&gt;L:Oxygen Supply, number)
}

(L:Oxygen Supply, number) 180 &gt;
(L:Pilot Dead, bool) !
and
if{ 1 (&gt;L:Pilot Dead, bool) }
 
Thanks for the heretic insight ;)

Some questions I still have (more applicable to FSX XML in general)...
Codes like these, I better put them in a 2D-gauge rather than in the modeldef.xml? And then let the modeldef.xml pick the correct variables to run the animation, is that true?

Regards!
 
Honestly, from the sim's perspective it makes no difference at all. XML script will run just as well whether it's embedded in a model or run as a panel "gauge."

From a human perspective however, I've found that it is far easier to have all of the "logic" contained in a single panel "gauge" and only have the display variables embedded in the model.

Now, once your project is finished and the "logic" is finalized, you could then copy/paste the "logic scripts" into modeldef.xml and compile it all into the model, but that's your decision to make. It's not necessary; only neat.
 
You can also drive the 3D needle with an L: var and do the calculations for that variable in a 2D gauge, provided that you can live with the 18 Hz refresh rate limit.

I prefer this approach as it offers users the chance to easily fix or improve the calculation method.
 
XML gauges run at 18Hz. Animation/visibility scripts run at sim frame rate.
 
Back
Top