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

Switching MFD buttons ( SOLVED )

Deano1973

Resource contributor
Messages
384
Country
unitedkingdom
Hi folks, another quick XML question. I've searched far and wide on this one and there are many threads and answers, but it's very hard to pick out how things come together from the replies. In brief, I have an MFD with 5 screens. I've got my code together and can select each screen using a mouse click on the surrounding MFD buttons. So far, so "easy peasy". What I can't do is exclude the other four screens when selecting a particular screen - I have to turn off screen 1 in order to not have screen 2 overlay it when screen two is switched on, if that makes sense. I did cheat a bit and include a "background" image to screen 2 to cover screen 1, but I suspect I shouldn't need to do that.

Here's my modeldef button code for the first two switches of five, and my gauge XML below - would an "if" and "els" entry in the gauge code have any effect on Lvars perhaps? I should add that one of the screens has mouse click areas upon it - I'm hoping that they won't show up on other screens as they do at the moment. Will post the solution if I figure it out first.

Code:
<PartInfo>
  <Name>MFD Button 1</Name>
  <MouseRect>
    <Cursor>Hand</Cursor>
    <CallbackCode>(L:MFD Button 1, enum) ! (>L:MFD Button 1, enum)</CallbackCode>
  </MouseRect>
</PartInfo>

<PartInfo>
  <Name>MFD Button 2</Name>
  <MouseRect>
    <Cursor>Hand</Cursor>
    <CallbackCode>(L:MFD Button 2, enum) ! (>L:MFD Button 2, enum)</CallbackCode>
  </MouseRect>
</PartInfo>

Code:
<Gauge Name="DCD F-18 Super Hornet MFD" Version="1.0">

      <!--Checklist Screen-->

<Element>
<Visible>(A:Circuit Avionics on, bool) (L:MFD Button 1, enum) 0 == &amp;&amp;</Visible>
  <Image Name="Checklist.bmp"/>
  </Element>


<Element>
<Position X="190" Y="424"/>
<Select>
<Value>(L:Chains, bool)</Value>
         <Case Value="1">
            <Image Name="Chains.bmp" ImageSizes="153,17"/>
         </Case>
</Select>
</Element>

  <Element>
  <Visible>(A:Circuit Avionics on, bool) (L:MFD Button 1, enum) 0 == &amp;&amp;</Visible>
               <Position X="16" Y="400"/>
<Text X="120" Y="20" Bright="Yes" Length="20" Font="Tahoma" Color="Lime"
Adjust="Left" VerticalAdjust="Center">
<String>ELV TRIM: %((A:ELEVATOR TRIM PCT, PERCENT) 10 / 100 %) %!3d!%</String>
</Text>
</Element>

<Mouse>

<Area Left="215" Top="422" Width="140" Height="30">
<Cursor Type="Hand"/>
<Click Kind="LeftSingle">(L:Chains, bool) ! (>L:Chains, bool)</Click>
<Tooltip>Deck chains</Tooltip>
</Area>

</Mouse>

      <!--HSI Screen-->

<Element>
<Visible>(A:Circuit Avionics on, bool) (L:MFD Button 2, enum) 1 == &amp;&amp;</Visible>
  <Image Name="Background.bmp"/>

   <Element>
<Visible>(A:Circuit Avionics on, bool) (L:MFD Button 2, enum) 1 == &amp;&amp;</Visible>
  <Image Name="DCD_HSI.bmp"/>

xml coding for HSI continues on from here...
 
Last edited:
Just posting this in addition, one of the threads I read about this subject - it makes sense and I've tried to use it, yet it's hard for me to understand how it's correctly applied in the modeldef and gauge files;

Code:
Even easier:Use the single (L:MFDswitch, enum) to determine which "set of Elements" is displayed at any time:
(L:MFDswitch, enum) 0 == ...XML for this screen... 
(L:MFDswitch, enum) 1 == ...XML for this screen... 
(L:MFDswitch, enum) 3 == ...XML for this screen... et cetera...
Then, for each mouse button, simply set the (L:MFDswitch, enum) as needed for that specific screen/page:3 (>L:MFDswitch, enum)
 
Rather than using 5 different variables for each of the 5 buttons to control this logic, it would be much simpler to use a single ENUM variable with values between 1 and 5, just like in your later example. When you push button #1, the code sets the value of this single variable to 1. Button #2 sets it to 2, etc.
 
Rather than using 5 different variables for each of the 5 buttons to control this logic, it would be much simpler to use a single ENUM variable with values between 1 and 5, just like in your later example. When you push button #1, the code sets the value of this single variable to 1. Button #2 sets it to 2, etc.

This sounds perfect, but my issue is understanding how that is applied by the code. It sounds like you're suggesting I simply create a single (L:MFD Button, enum) variable in the modeldef, but how do I specify how many values it has? Or does the enum unit signify that it automatically has unlimited values, so I then just crack on with the gauge code? Sorry for my ignorance - I'm very new to XML and coding in general so it's the little details that I'm struggling to get my head around, despite much reading of threads and tutorials etc. I've got the use of LVar bools down okay now and have a screen that allows the user to load / remove weapons in real-time on the aircraft, but enums are a new thing to me.
 
An example for a rotary switch - an excerpt

Code:
<Gauge Name="ElecM_DC_Meter_Rotary.xml" Version="1.0">

<Update Frequency="6"/>

  <Mouse>
  <Area Left="0" Top="0" Right="260" Bottom="220">
    <Cursor Type="Hand"/>
    <Tooltip> L: Knob left %n R: Knob right </Tooltip>
    <Click Kind="LeftSingle+RightSingle">
      (M:Event)
      'LeftSingle' scmp 0 ==
      if{
        (L:ElecM_DC_Meter_RKnob,number) 0 &gt;
        if{
          (L:ElecM_DC_Meter_RKnob,number) -- (&gt;L:ElecM_DC_Meter_RKnob,number)
          }
        }
      (M:Event)
      'RightSingle' scmp 0 ==
      if{
        (L:ElecM_DC_Meter_RKnob,number) 3 &lt;
        if{
          (L:ElecM_DC_Meter_RKnob,number) ++ (&gt;L:ElecM_DC_Meter_RKnob,number)
          }
        }
    </Click>
  </Area>
  </Mouse>

  <Element>
    <Position X="32" Y="39"/>
    <Image Name="ElecM_AC_Rotary_Knob.bmp" Luminous="No">
    <Axis X="32" Y="39" />
    </Image>
    <Rotate>
      <Value Minimum="0" Maximum="3">
       (L:ElecM_DC_Meter_RKnob,number)
      </Value>
      <Nonlinearity>
        <Item Value="0" Degrees="0"/>
        <Item Value="1" Degrees="42"/>
        <Item Value="2" Degrees="83"/>
        <Item Value="3" Degrees="129"/>
      </Nonlinearity>
    </Rotate>
  </Element>

</Gauge>


(L:ElecM_DC_Meter_RKnob,number) has to replaced with your mfd selector variable.
 
Wow, thanks EduHir, I really appreciate you replying but that's a whole lot more code than I think I need, and my MFD has mouse buttons rather than a rotary control. I think I just don't know enough about XML to use your code, and I really need to understand how the values in Lvars are created and called in gauge code so that I can move forward under my own steam in the future. For instance, do all Lvars need to be in the modeldef.xml in the first place, or can they be created within gauges? These things I can't find any real information for, even in the best known tutorials that talk about them.
 
The only Lvars needed in the modeldef are those that are affected by that part of the model, i.e. a MFD button, or weapon visibily.

For your MFDs, you could have something like this in your modeldef, attached to the appropriate buttons:
Code:
<PartInfo>
  <Name>MFD Button 1</Name>
  <MouseRect>
    <Cursor>Hand</Cursor>
    <CallbackCode>1 (>L:MFD Button, enum)</CallbackCode>
  </MouseRect>
</PartInfo>

<PartInfo>
  <Name>MFD Button 2</Name>
  <MouseRect>
    <Cursor>Hand</Cursor>
    <CallbackCode>2 (>L:MFD Button, enum)</CallbackCode>
  </MouseRect>
</PartInfo>

Then something like:

Code:
<Element>
  <Visible>(L:MFD Button, enum) 1 == </Visible>
               page 1 code here
</Element>

<Element>
  <Visible>(L:MFD Button, enum) 2 == </Visible>
               page 2 code here
</Element>

<Element>
  <Visible>(L:MFD Button, enum) 3 == </Visible>
               page 3 code here
</Element>

for your MFD page code. Each page would only be displayed if the Lvar contains the appropriate value.

I should say that XML gauges are not my strong point, so there's probably better ways of doing things!
 
Aha! Thanks @DaveWG !! My error was in the callback code - if I see what you're writing there correctly, I was using an on/off when I didn't need it. So, the enum value is set in the modeldef, then called in the gauge code. I'll give it a whirl, thanks again! :)
 
Confirming that it worked a treat! Define the enum value in the modeldef, then call it as per Dave's example above.

MFD now performing precisely as it should, super chuffed - thanks again everybody! :D
 
Back
Top