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

FS2004 Click mag switch...almost there

Messages
231
Country
us-alabama
Hi Y'all

My editor has been grousing about the drag able nature of the stock DC3 magneto switch part name I have been using for my VC mag switch. So I cobbled up this code to make it left and right click able:
Code:
<part>
    <name>mag_mast</name>
    <animlength>75</animlength>
    <animation>
       <parameter>
            <!-- 0 = Off, 25 = Left, 50 = Right, 75 = Both -->
            <code>(A:Recip eng left magneto:1,bool) 2 * (A:Recip eng right magneto:1,bool) + 25 *</code>
        <Lag>100</Lag>
       </parameter>
    </animation>
<mouserect>
       <cursor>Hand</cursor>
        <tooltip_id>TOOLTIPTEXT_MAGNETO_SWITCH</tooltip_id>
       <mouse_flags>LeftSingle+RightSingle</mouse_flags>
            <callback_code>
            (M:Event) 'LeftSingle' scmp 0 ==
                                                                          if{ 1 (L:mag_mast,enum) ++ 10 min (>L:mag_mast,enum) (>K:MAGNETO_INCR) }
            (M:Event) 'RightSingle' scmp 0 ==
                if{ -1 (L:mag_mast,enum) -- 0 max (>L:mag_mast,enum) (>K:MAGNETO_DECR) }
               1 (&gt;L:XMLSND9,enum)
       </callback_code>
    </mouserect>
</part>

For the most part it works well, starts in the both position, right clicks down thru the right and left positions and shuts down the engine in the 0 position. Then left clicks thru the left, right and both positions as needed.

The problem is when left clicked to return to the both position with the engine off, if you happen to left click an extra time the engine starts. Is there any way to defeat the engine start as this F4u-1 was a shell start system and the magneto switch was not the starter trigger.

Carl
 
Sure. Keep track of the position of the switch (using an L: variable), and do not increment the magneto variable if the switch is left clicked while in the both position.
 
Tom
I am still a newbie with the finer points of .Xml code. Here is my stab in the dark at what you suggest:
Code:
            (M:Event) 'LeftSingle' scmp 0 ==
                if{ 1 (L:mag_mast,enum) ++ 10 min (>L:mag_mast,enum) 0 max 3 min (>K:MAGNETO_INCR) }
It did not work of course, but I am still working to find a code that will.

Carl
 
I would guess something more like:

Code:
(M:Event) 'LeftSingle' scmp 0 ==
                if{ 1 (L:mag_mast,enum) ++ 10 min (>L:mag_mast,enum) } 
           (L:mag_mast,enum) 3 &lt;=
                if{ (>K:MAGNETO_INCR) }
 
Tom
Thank you for the code, it gave me a starting point. Still no success yet, as written the switch will toggle to the right position on right click then fail to respond to further right clicks, but responds to left click to move back to the both position with the engine running. When I shut the engine down manually, the same limited movement is seen, but repeated left clicks no longer engage the starter. At this point right clicks seem to start working again and I can right click down to the off position where the switch hangs again and will not respond to either right or left click.

I have run out of time to work on it this morning, but I will report further progress as I get time to work on it.

Carl
 
The only thing I see now is that this:

Code:
if{ 1 (L:mag_mast,enum) ++

Should be this:

Code:
if{ (L:mag_mast,enum) ++

the 1 is not necessary.

I would create something that will display the value of L:mag_mast,enum and check to see it increases by one with each left click and decreases by one with each right click. It also doesn't need to get any larger than 3, since that is the number of switch positions (0=off, 1=left, 2=right, 3= both), so the code could be changed to something like:

Code:
(M:Event) 'LeftSingle' scmp 0 ==
if{ (L:mag_mast,enum) ++ 3 min (>L:mag_mast,enum) }
(L:mag_mast,enum) 3 &lt;=
if{ (>K:MAGNETO_INCR) }
 
The aircraft always loads with magnetos on both so most normal coding would be out of sink.
I have written many different types of coding for fuel selectors and magnetos and it's always a challenge without knowing a few things.
This code uses left and right mouse clicks just as you wanted. I prefer clicking over drag!

This code starts with mags on both by starting on animation key 75 automatically.
It has a tool tip to confirm it is in sink and since it's a custom var it needs to stay in sink no matter how you click it.


Code:
  <PartInfo>
    <Name>MAGNETO_L_ENG1</Name>
    <AnimLength>75</AnimLength>
    <Animation>
      <Parameter>
        <Code>(L:MAGNETO_L_ENG1,bool) 25 * 75 +</Code>
    <Lag>100</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
     <TooltipID>TOOLTIPTEXT_ENG1_MAGNETO_SWITCH</TooltipID>
      <MouseFlags>LeftSingle+RightSingle+WheelUp+WheelDown+DownRepeat</MouseFlags>
      <CallbackCode>
        (M:Event) 'LeftSingle' scmp 0 == if{ (L:MAGNETO_L_ENG1,bool) -- -3 max (>L:MAGNETO_L_ENG1,bool) }
        (M:Event) 'RightSingle' scmp 0 == if{ (L:MAGNETO_L_ENG1,bool) ++ 0 min (>L:MAGNETO_L_ENG1,bool) }
    (L:MAGNETO_L_ENG1,bool) -3 == if{ 0 (>K:MAGNETO1_SET) }
    (L:MAGNETO_L_ENG1,bool) -2 == if{ 2 (>K:MAGNETO1_SET) }
    (L:MAGNETO_L_ENG1,bool) -1 == if{ 1 (>K:MAGNETO1_SET) }
    (L:MAGNETO_L_ENG1,bool)  0 == if{ 3 (>K:MAGNETO1_SET) }
      </CallbackCode>
    </MouseRect>
  </PartInfo>

  <PartInfo>
    <Name>MAGNETO_R_ENG1</Name>
    <AnimLength>75</AnimLength>
    <Animation>
      <Parameter>
        <Code>(L:MAGNETO_R_ENG1,bool) 25 * 75 +</Code>
    <Lag>100</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
     <TooltipID>TOOLTIPTEXT_ENG1_MAGNETO_SWITCH</TooltipID>
      <MouseFlags>LeftSingle+RightSingle+WheelUp+WheelDown+DownRepeat</MouseFlags>
      <CallbackCode>
        (M:Event) 'LeftSingle' scmp 0 == if{ (L:MAGNETO_R_ENG1,bool) -- -3 max (>L:MAGNETO_R_ENG1,bool) }
        (M:Event) 'RightSingle' scmp 0 == if{ (L:MAGNETO_R_ENG1,bool) ++ 0 min (>L:MAGNETO_R_ENG1,bool) }
    (L:MAGNETO_R_ENG1,bool) -3 == if{ 0 (>K:MAGNETO2_SET) }
    (L:MAGNETO_R_ENG1,bool) -2 == if{ 2 (>K:MAGNETO2_SET) }
    (L:MAGNETO_R_ENG1,bool) -1 == if{ 1 (>K:MAGNETO2_SET) }
    (L:MAGNETO_R_ENG1,bool)  0 == if{ 3 (>K:MAGNETO2_SET) }
      </CallbackCode>
    </MouseRect>
  </PartInfo>
 
Morning Guys!

Once again I find my work time for the morning drawing to a close.

Tom
I tried your suggested change, with pretty much the same results as reported yesterday.

delivery guy

As I mentioned earlier I am not great at the finer points of .xml coding. Below is my attempt to combine the 2 codes you provided with my L:variable for the one mag switch.

Code:
<part>
    <name>mag_mast</name>
    <animlength>75</animlength>
    <animation>
       <parameter>
            <!-- 0 = Off, 25 = Left, 50 = Right, 75 = Both -->
            <code>(L:mag_mast,bool) 25 * 75 +</code>
        <Lag>100</Lag>
       </parameter>
    </animation>
<mouserect>
      <Cursor>Hand</Cursor>
     <TooltipID>TOOLTIPTEXT_ENG1_MAGNETO_SWITCH</TooltipID>
      <MouseFlags>LeftSingle+RightSingle+WheelUp+WheelDown+DownRepeat</MouseFlags>
      <CallbackCode>
        (M:Event) 'LeftSingle' scmp 0 == if{ (L:mag_mast,bool) -- -3 max (>L:mag_mast,bool) }
        (M:Event) 'RightSingle' scmp 0 == if{ (L:mag_mast,bool) ++ 0 min (>L:mag_mast,bool) }
    (L:mag_mast,bool) -3 == if{ 0 (>K:MAGNETO1_SET) (>K:MAGNETO2_SET) }
    (L:mag_mast,bool) -2 == if{ 2 (>K:MAGNETO1_SET) (>K:MAGNETO2_SET) }
    (L:mag_mast,bool) -1 == if{ 1 (>K:MAGNETO1_SET) (>K:MAGNETO2_SET) }
    (L:mag_mast,bool)  0 == if{ 3 (>K:MAGNETO1_SET) (>K:MAGNETO2_SET) }
               1 (&gt;L:XMLSND9,enum)
       </callback_code>
    </mouserect>
</part>

The results: the switch seemed locked at the zero position displaying no tool tip or cursor and failing to respond to any click.

So I changed the part name to match your L:variable and tried a conversion using just the first code:

<part>
<name>MAGNETO_L_ENG1</name>
<animlength>75</animlength>
<animation>
<parameter>
<code>(L:MAGNETO_L_ENG1,bool) 25 * 75 +</code>
<Lag>100</Lag>
</parameter>
</animation>
<mouserect>
<Cursor>Hand</Cursor>
<TooltipID>TOOLTIPTEXT_ENG1_MAGNETO_SWITCH</TooltipID>
<MouseFlags>LeftSingle+RightSingle+WheelUp+WheelDown+DownRepeat</MouseFlags>
<CallbackCode>
(M:Event) 'LeftSingle' scmp 0 == if{ (L:MAGNETO_L_ENG1,bool) -- -3 max (>L:MAGNETO_L_ENG1,bool) }
(M:Event) 'RightSingle' scmp 0 == if{ (L:MAGNETO_L_ENG1,bool) ++ 0 min (>L:MAGNETO_L_ENG1,bool) }
(L:MAGNETO_L_ENG1,bool) -3 == if{ 0 (>K:MAGNETO1_SET) }
(L:MAGNETO_L_ENG1,bool) -2 == if{ 2 (>K:MAGNETO1_SET) }
(L:MAGNETO_L_ENG1,bool) -1 == if{ 1 (>K:MAGNETO1_SET) }
(L:MAGNETO_L_ENG1,bool) 0 == if{ 3 (>K:MAGNETO1_SET) }
1 (&gt;L:XMLSND9,enum)
</callback_code>
</mouserect>
</part>

The results were the same as the previous attempt. I have to leave for my day job now but will work on it more tonight and post results as I get them

Carl
 
Um, Carl... you seem to be mixing-and-matching two different XML schemas, with a predictable result of failure...

Note especially your mouse callback where you begin the section with <CallbackCode> (FSX schema) and close the section with <callback_code> (FS9 schema).
 
If you are going to use an L: variable for this, then you also need to have some code to sync the A: magneto variables to your L: variable upon aircraft loading. This is usually easiest in a transparent gauge, listed in the VCockpit section (so it always loads).

I have my L: variables constantly be synced to the relevant A: variables, so they are never misaligned. I use this code in my FS9 gauge for a 4 engine aircraft - probably horrible, but it works:

Code:
<Element>
  <Select>
  <Value>
  (A:Recip eng left magneto:1,bool) 2 * (A:Recip eng right magneto:1,bool) + (&gt;L:magkey1, enum)
  (A:Recip eng left magneto:2,bool) 2 * (A:Recip eng right magneto:2,bool) + (&gt;L:magkey2, enum)
  (A:Recip eng left magneto:3,bool) 2 * (A:Recip eng right magneto:3,bool) + (&gt;L:magkey3, enum)
  (A:Recip eng left magneto:4,bool) 2 * (A:Recip eng right magneto:4,bool) + (&gt;L:magkey4, enum)
  (L:magkey1, enum) (L:mag1, enum) !=  if{ (L:magkey1, enum) (&gt;L:mag1, enum) }
  (L:magkey2, enum) (L:mag2, enum) !=  if{ (L:magkey2, enum) (&gt;L:mag2, enum) }
  (L:magkey3, enum) (L:mag3, enum) !=  if{ (L:magkey3, enum) (&gt;L:mag3, enum) }
  (L:magkey4, enum) (L:mag4, enum) !=  if{ (L:magkey4, enum) (&gt;L:mag4, enum) }
  </Value>
  </Select>
  </Element>

I use the L:mag1, etc. variable to rotate the visible magneto lever. Just using the magkey variables didn't work properly, for some odd reason.
 
Well Bill you are of course right as usual. I will correct the problem, retest and report the outcome in a while. These 3am wake ups to work are making me sloppy.

Carl
 
Last edited:
Guys!

Running out of time again, but with mostly success today! Fixing the schema problem my sloppiness created allowed the switch part to move thru the correct range of movements and display the correct tool tip for each movement. Repeated clicks in the both position failed to start the engine as needed. Here is the code I used:
Code:
<part>
    <name>mag_mast</name>
    <animlength>75</animlength>
    <animation>
       <parameter>
            <!-- 0 = Off, 25 = Left, 50 = Right, 75 = Both -->
            <code>(L:mag_mast,bool) 25 * 75 +</code>
        <Lag>100</Lag>
       </parameter>
    </animation>
<mouserect>
      <cursor>Hand</cursor>
     <tooltip_id>TOOLTIPTEXT_ENG1_MAGNETO_SWITCH</tooltip_id>
      <mouse_flags>LeftSingle+RightSingle+WheelUp+WheelDown+DownRepeat</mouse_flags>
      <callback_code>
        (M:Event) 'LeftSingle' scmp 0 == if{ (L:mag_mast,bool) -- -3 max (>L:mag_mast,bool) }
        (M:Event) 'RightSingle' scmp 0 == if{ (L:mag_mast,bool) ++ 0 min (>L:mag_mast,bool) }
    (L:mag_mast,bool) -3 == if{ 0 (>K:MAGNETO1_SET) (>K:MAGNETO2_SET) }
    (L:mag_mast,bool) -2 == if{ 2 (>K:MAGNETO1_SET) (>K:MAGNETO2_SET) }
    (L:mag_mast,bool) -1 == if{ 1 (>K:MAGNETO1_SET) (>K:MAGNETO2_SET) }
    (L:mag_mast,bool)  0 == if{ 3 (>K:MAGNETO1_SET) (>K:MAGNETO2_SET) }
               1 (&gt;L:XMLSND9,enum)
       </callback_code>
    </mouserect>
</part>

I had a problem when I used the engine auto start, key combination with the switch in the off position. The switch did not return to the both position as the mag switch usually does. Not surprising as the animation is not for a sim mag switch. I fixed this by adding:

Code:
<Keys>
    <On Event="ENGINE_AUTO_START">1 (>L:mag_mast,enum)</On>
</Keys>

To a gauge I keep for such uses. When auto started with the key combination the switch rotates to the both position perfectly, however. This throws the timing of the switch off a little and an extra right click is required to get the switch to "reset"? And it functions correctly again.

Tom

Could you explain a little more about transparent gauges? I have seen them mentioned in forum posts and never really understood where and how the should be used.

By the way Thank You All for your help with this. Gotta go time to leave for day job.

Carl
 
Carl, any gauge you want to be "invisible" (aka: transparent) you can simply set the gauge entry in the panel.cfg to use these coordinates, sizes:

gaugenn=MyGauge!MyLogic, 0,0,1,1
 
Ahh... Make it too small to be seen and put it in the corner of the screen. As far as function goes I guess it can be any special function code that gets the job done, right?

I want to thank you Bill, Tom and especially delivery guy again for the help with this.

My editor was happy with the original code even with the extra click starting the engine. He is usually stressing complete and total historical accuracy. I wonder if he is ill?

Anyway Thank you guys again!

Carl
 
Back
Top