Create new variables?

Horst18519

Moderator
Staff member
Resource contributor
#1
As my aircraft should be as real as it gets I want to make all fuses in the panel working. That means that I would need variables for stall warning, flap motor, lights, ADF,... in short: I need to create variables to tell fsx if the system/gauge should work or not. I guess I could use failure variables for some systems, but I cannot find those vars for all systems I have to include.

So could I create new variables and tell fsx somehow that for example the landing light shall not work anymore because the fuse is turned out?
That would mean of course that the switch for the landing light would still "work", but it would have no effect.

Additional question: I find a lot of useful variables in the SDK, but unfortunately most are not settable. Is there a workaround so that I can set them?
 

Horst18519

Moderator
Staff member
Resource contributor
#2
After some thoughts about this I came to this conclusion:

- I have to create a gauge that stores my personal variables (like "ADF_fuse,bool" or "flapmotor_fuse,bool")
- I have to create animation tags with individual variables for all my systems/switches (like "my flap lever")
- If the user switches the flaps the gauge recognizes it and asks itself if the fuse is working, and if it does it will send the value of "my flap lever" to the fsx flap lever variable, meaning the flaps will be set

That would mean the animations of the switches would not be linked to the actual fsx-variables but to "meta-variables". Only if the fuse is active this meta-variable would be assigned to the "real" variable.

Is that the way to go?

Is it possible to create my individual variables and control them with my modeldef-entries anyway?

Any help on this would be appreciated. I think I can do it on my own, but I don't want to waste 10 hours of work only to realise that I cannot deal with variables this way...
 
Last edited:

n4gix

Resource contributor
#3
Additional question: I find a lot of useful variables in the SDK, but unfortunately most are not settable. Is there a workaround so that I can set them?
For all practical purposes, all "sim-variables" are read-only. That is, they simply report the value of that specific token. Those that're labled as "settable" are for use by the multi-player system, and are "set" using the Sim-Connect pipeline.

All "action verbs" are listed in the "Event IDs.htm" file.

For most "subject" sim-variables there are corresponding "verb" key_events.

The first decision you must make though is whether you are going to write XML script "code" for your gauge system or use the C SDK.

There are significant advantages to using strictly XML, since all the "model's internal code" is also XML.

On the other hand, XML is an absolute PITA with regards to complex logic... :eek:
 
Last edited:

Horst18519

Moderator
Staff member
Resource contributor
#4
Unfortunately XML is the only choice for me as I don't know anything about C. :(

Do you think my approach (with personal variables) would be a way to go?
 

n4gix

Resource contributor
#5
It should be fine.

As much as folks hate them, a "logic tree" (aka: "flow chart") is really the only way to design complex logic...
 

Horst18519

Moderator
Staff member
Resource contributor
#6
The logic won't be a problem. I'm used to that. I only have to figure out how the logic works (for example if-clauses within other if-clauses) then I'll be fine.
 

Horst18519

Moderator
Staff member
Resource contributor
#7
Bill (or others),

I tried to do a simple gauge:

<Gauge Name="Fuses" Version="1.0">
<Size X="100" Y="100"/>


<!-- Aux Fuel -->

<Element>
<Position X="0" Y="0"/>
<Element>
<Select>
<Value>
(L:fw_Switch_AuxFuel,bool) == 1 (L:fw_Fuse_AuxFuel,bool) == 1 AND
if{ (A:Fuel_Pump, bool) 0 ==
if{ (>K:FUEL_PUMP) }
els{ (A:Fuel_Pump, bool) 1 ==
if{ (>K:FUEL_PUMP) }
}
</Value>
</Select>
</Element>
</Element>


</Gauge>
It should read out the states of the fuse and the switch for the aux fuel pump and eventually start the pump. Both (switch and fuse) are animated with two entries in the modeldef.xml. That works perfectly well (without the gauge).

But unfortunately this simple gauge doesn't work properly.
FSX now switches the fuel pump on and off all the time, and both switch and fuse won't react on my clicks anymore.

I guess I didn't get the idea what to do within the gauge. :eek:

All I want is that the gauges checks if the switch is triggered or the fuse (or what else there will come as additional parameters). And if both are "1" the pump should start. :confused:
 

n4gix

Resource contributor
#8
Let's take a few baby steps at first.

Syntax is critical. The schema for XML is:

(X:variable) constant condition if{ (>K:action) }

So, your first condition would be:

(L:fw_Switch_AuxFuel,bool) 1 == // equal to one

For simplicity however, when working with "bool" type variables, you can omit the 1 == entirely, as it's assumed that you are looking for a "TRUE" condition, hence:

(L:fw_Switch_AuxFuel,bool) // equal to one

has effectively the same meaning as the longer form above.

Similarly, these are equivalent checks for a "FALSE" condition:

(L:fw_Switch_AuxFuel,bool) 0 == // not equal to zero
(L:fw_Switch_AuxFuel,bool) ! // the exclamation point means NOT equal to one

The code segment below translates in pseudo-code to:

if (L:fw_Switch_AuxFuel) AND (L:fw_Fuse_AuxFuel) are TRUE, AND if (A:Fuel_Pump) is FALSE, then toggle ON FUEL_PUMP.

Code:
<Value>
      (L:fw_Switch_AuxFuel,bool)
      (L:fw_Fuse_AuxFuel,bool)
      and
      if{ (A:Fuel_Pump, bool) !
          if{ (>K:FUEL_PUMP) }
</Value>
I'll leave the remainder for you to figure out what XML to write to turn OFF the fuel pump if either the fuse or switch is set to FALSE... ;)
 

Horst18519

Moderator
Staff member
Resource contributor
#9
Bill, thanks again for patience and knowledge you share with me. :)

I guess I'll figure the rest, only wanted to be sure if my approach generally would be working.
 

Horst18519

Moderator
Staff member
Resource contributor
#10
I guess this would make sense:

Code:
  <Element>
     <Position X="0" Y="0"/>
     <Element>
        <Select>
           <Value>
              (L:fw_Switch_AuxFuel,bool)
              (L:fw_Fuse_AuxFuel,bool)
              and
              if{ (A:Fuel_Pump, bool) !
                  if{ (>K:FUEL_PUMP) }

              (L:fw_Switch_AuxFuel,bool) !
              (L:fw_Fuse_AuxFuel,bool) !
              or
              if{ (A:Fuel_Pump, bool)
                  if{ (>K:FUEL_PUMP) }
           </Value>
        </Select>
     </Element>
  </Element>
Unfortunately it's not doing what I expected. The switch is now not going on and off all the time (quite a relief :D ), but I still cannot work the switches.
Why does the gauge prevent me working the switches?
(guess I'm more stupid in that than I thought... :eek: )
 

n4gix

Resource contributor
#11
That code simply turns the fuel pump on/off based on the condition of your two L:variables. It does not affect the condition of the two L:variables...

What is the code you use to control those two L:variables?

Presumably it is something like:

<Click>(L:fw_Switch_AuxFuel,bool) ! (>L:fw_Switch_AuxFuel,bool)</Click>

<Click>(L:fw_Fuse_AuxFuel,bool) ! (>L:fw_Fuse_AuxFuel,bool)</Click>
 
Last edited:

Horst18519

Moderator
Staff member
Resource contributor
#12
I use this entry in the modeldef:

Code:
    <PartInfo>
        <Name>fw_Switch_AuxFuel</Name>
        <AnimLength>50</AnimLength>
        <Animation>
            <Parameter>
                <Code>(L:fw_Switch_AuxFuel,bool) 100 *</Code>
            <Lag>100</Lag>
            </Parameter>
        </Animation>
        <MouseRect>
            <Cursor>Hand</Cursor>
            <MouseFlags>LeftSingle</MouseFlags>
             <TooltipText>Aux Fuel Pump</TooltipText>
            <CallbackCode>
               (M:Event) 'LeftSingle' scmp 0 ==
                  if{ (>L:fw_Switch_AuxFuel,bool) }
            </CallbackCode>
        </MouseRect>
    </PartInfo>


    <PartInfo>
       <Name>fw_Fuse_AuxFuel</Name>
       <AnimLength>100</AnimLength>
       <Animation>
            <Parameter>
                <Code>(L:fw_Fuses_AuxFuel,bool) 100 *</Code>
            <Lag>200</Lag>
            </Parameter>
        </Animation>
        <MouseRect>
            <Cursor>Hand</Cursor>
            <MouseFlags>LeftSingle</MouseFlags>
             <TooltipText>Fuel Pump Fuse</TooltipText>
            <CallbackCode>
               (M:Event) 'LeftSingle' scmp 0 ==
                  if{ (>L:fw_Fuse_AuxFuel,bool) }
            </CallbackCode>
        </MouseRect>
     </PartInfo>
 

n4gix

Resource contributor
#13
That is only turning the switch ON. You need to write the code to "toggle" your custom L:variable, using this template:

(L:variable,bool) ! (>L:variable,bool)

The above is a form of an "if statement" that is used in a mouse callback. In pseudo-code it would read like this:

if (L:variable) is FALSE, then set L:variable equal to TRUE
or
if (L:variable) is TRUE, then set L:variable equal to FALSE


Code:
    <PartInfo>

            <CallbackCode>
               (M:Event) 'LeftSingle' scmp 0 ==
                  if{ (L:fw_Switch_AuxFuel,bool) ! (>L:fw_Switch_AuxFuel,bool)
            </CallbackCode>
        </MouseRect>
    </PartInfo>
Also, unless there's some burning need to designate a specific mouse button, it is much simpler to use this form:

Code:
    <PartInfo>

            <CallbackCode>
               (L:fw_Switch_AuxFuel,bool) ! (>L:fw_Switch_AuxFuel,bool)
            </CallbackCode>
        </MouseRect>
    </PartInfo>
 
Last edited:

Horst18519

Moderator
Staff member
Resource contributor
#14
Bill, isn't there a possibility to simply toggle a bool var (no matter in which state it is) instead of asking if it's TRUE and then set it to FALSE or the other way round?
 

n4gix

Resource contributor
#15
Bill, isn't there a possibility to simply toggle a bool var (no matter in which state it is) instead of asking if it's TRUE and then set it to FALSE or the other way round?
No, there is not. There are some (but not all) key_events predefined in flight sim as "toggles" that do not require this type of check...

...but all custom variables require this format.
 

Horst18519

Moderator
Staff member
Resource contributor
#16
Thanks, that ist just what I needed to know (even if it's not what I wanted to hear :D ).

I'd really start paying you soon. ;)
 

Horst18519

Moderator
Staff member
Resource contributor
#17
I still got it wrong. :(

Gauge:
Code:
  <Element>
     <Position X="0" Y="0"/>
     <Element>
        <Select>
           <Value>
              (L:fw_Switch_AuxFuel,bool)
              (L:fw_Fuse_AuxFuel,bool)
              and
              if{ (A:Fuel_Pump, bool) !
                  if{ (>K:FUEL_PUMP) }
                }
              (L:fw_Switch_AuxFuel,bool) !
              (L:fw_Fuse_AuxFuel,bool) !
              or
              if{ (A:Fuel_Pump, bool)
                  if{ (>K:FUEL_PUMP) }
                }
           </Value>
        </Select>
     </Element>
  </Element>
Modeldef:
Code:
    <PartInfo>
        <Name>fw_Switch_AuxFuel</Name>
        <AnimLength>50</AnimLength>
        <Animation>
            <Parameter>
                <Code>(L:fw_Switch_AuxFuel,bool) 50 *</Code>
            <Lag>100</Lag>
            </Parameter>
        </Animation>
        <MouseRect>
            <Cursor>Hand</Cursor>
            <TooltipText>Aux Fuel Pump</TooltipText>
            <CallbackCode>
               (L:fw_Switch_AuxFuel,bool) ! (>L:fw_Switch_AuxFuel,bool)
            </CallbackCode>
        </MouseRect>
    </PartInfo>


    <PartInfo>
       <Name>fw_Fuse_AuxFuel</Name>
       <AnimLength>100</AnimLength>
       <Animation>
            <Parameter>
                <Code>(L:fw_Fuses_AuxFuel,bool) 100 *</Code>
            <Lag>100</Lag>
            </Parameter>
        </Animation>
        <MouseRect>
            <Cursor>Hand</Cursor>
            <TooltipText>Fuse Fuel Pump</TooltipText>
            <CallbackCode>
               (L:fw_Fuse_AuxFuel,bool) ! (>L:fw_Fuse_AuxFuel,bool)
            </CallbackCode>
        </MouseRect>
     </PartInfo>
The fuse doesn't move and if I switch on both switch and fuse the pump again goes wild. :confused:

Maybe it is stupidity...
 
Top