• 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 Help with a switch animation (Taxi light... again) SOLVED

Messages
1,451
Country
mexico
Hello lads

I hate the limitations made by the FS9's SDK; among them the lack of control for specific events. In this case, the hated K:TOGGLE_TAXI_LIGHTS event.
I would have liked that MS's guys to do something like that K:TAXI_LIGHTS_SET...

With the high risk to receive a kick in the butt :duck:, I will ask for help; I have no idea how to make my switch to work properly.

My plan is:

1.- Set in Gmax the animation as follows:
Key 0: Landing Lights ON (up position).
Key 25: Neutral position: the spring return the switch to center (after it has been used to toggle lights ON or OFF).
Key 50: Landing Lights OFF (down position).
2.- Avoid to all cost, the potential flooding made by the K: event.
3.- Use a control to monitor the switch positions and trigger actions: In this case, (L:407_LandingLT_SwPositionControl, number).
This control, is not implemented in the 2D gauge; instead in the 3D part itself.
4.- Fully Integrate the 2D version with the 3D part.


Here we go...
First, the 2D gauge element to display the switch:
HTML:
      <!-- 2D GAUGE: Graphics for Landing Light On/Off Switch -->
          <Element>
              <Position X="104" Y="28"/>
              <Select>
                  <Value>(L:407_LandingLT_SwPositionControl, number)</Value>
                      <Case Value="1">
                          <Image Name="407_switch_coll_UP.bmp" Luminous="Yes"/>
                      </Case>
                      <Case Value="0">
                          <Image Name="407_switch_coll_MD.bmp" Luminous="Yes"/>
                      </Case>
                      <Case Value="-1">
                          <Image Name="407_switch_coll_DN.bmp" Luminous="Yes"/>
                      </Case>
              </Select>
          </Element>

Now, the mouse area:
HTML:
<!-- 2D GAUGE: Mouse Area for Landing Light On/Off Switch -->
      <!-- Landing Light On/Off Switch -->
            <!-- "Landing lights ON" (UP position) -->
            <Area Left="104" Top="20" Width="25" Height="18">
                  <Cursor Type="Hand"/>
                      <Click Repeat="No" MouseWheelFlip="No">
                          1 (>L:407_LandingLT_SwPositionControl)
                          1 (>L:Bell_407_Click, number)
                      </Click>
            </Area>
            <!-- "Neutral" (MIDDLE position) -->
            <Area Left="104" Top="35" Width="25" Height="18">
                  <Cursor Type="Hand"/>
                      <Click Repeat="No" MouseWheelFlip="No">
                          0 (>L:407_LandingLT_SwPositionControl)
                          1 (>L:Bell_407_Click, number)
                      </Click>
            </Area>
            <!-- "Landing lights OFF" (DOWN position) -->
            <Area Left="104" Top="50" Width="25" Height="18">
                  <Cursor Type="Hand"/>
                      <Click Repeat="No" MouseWheelFlip="No">
                          -1 (>L:407_LandingLT_SwPositionControl)
                           1 (>L:Bell_407_Click, number)
                      </Click>
            </Area>

And finally, the part code:
HTML:
          <!-- SPRING LOADED VERSION 1-->
            <!-- Landing Light On/Off: Spring Loaded Switch -->
                    <!-- Taxi lights VARIABLE is used instead the landing lights VARIABLE. (which is used to trigger the flood light in all gauges)-->
                    <!--
                            Key   0: Landing Lights ON (up position)
                            Key 25: Neutral position: the spring return the switch to center (after it has been used to toggle lights ON or OFF).
                            Key 50: Landing Lights OFF (down position)
                    -->
     <part>
          <name>bell407_landing_lt_switch</name>
               <animation>
                  <parameter>
                      <code>
                          <!-- Key 25: Neutral position: the spring return the switch to center (after it has been used to toggle lights ON or OFF) -->
                          (A:Light Taxi, bool) ! (L:407_LandingLT_SwPositionControl, number) 1 == and
                          (A:Light Taxi, bool) (L:407_LandingLT_SwPositionControl, number) -1 == and
                          or
                              if{ 0 (>L:407_LandingLT_SwPositionControl, number) }
                          <!-- Key 0: Landing Lights ON (up position) -->
                          (L:407_LandingLT_SwPositionControl, number) 1 ==
                              if{
                                  (A:Electrical Master Battery,bool) (A:Light Taxi, bool) ! and
                                      if{ (>K:TOGGLE_TAXI_LIGHTS) }
                                }
                          <!-- Key 50: Landing Lights OFF (down position) -->
                          (L:407_LandingLT_SwPositionControl, number) -1 ==
                              if{
                                  (A:Electrical Master Battery,bool) (A:Light Taxi, bool) and
                                      if{ (>K:TOGGLE_TAXI_LIGHTS) }
                                }
                          <!-- Switch Position Control: it should drive the animation -->
                          (L:407_LandingLT_SwPositionControl, number) s0 0 &lt; 50 * l0 0 == 25 * +
                      </code>
                      <lag>100</lag>
                  </parameter>
              </animation>
        <mouserect>
              <cursor>Hand</cursor>
              <tooltip_text>ON (LMB)/OFF (RMB)</tooltip_text>
              <mouse_flags>LeftSingle+RightSingle</mouse_flags>
              <callback_code>
                  (M:Event) 'LeftSingle' scmp 0 ==
                      if{
                          (L:407_LandingLT_SwPositionControl, number) ++ 1 min (>L:407_LandingLT_SwPositionControl, number)
                          <!-- Click Sound Effect -->
                          1 (>L:Bell_407_Click,number)
                        }
                  (M:Event) 'RightSingle' scmp 0 ==
                      if{
                          (L:407_LandingLT_SwPositionControl, number) -- -1 max (>L:407_LandingLT_SwPositionControl, number)
                          <!-- Click Sound Effect -->
                          1 (>L:Bell_407_Click,number)
                        }
              </callback_code>
        </mouserect>
      </part>

The problem is that the switch is never going to its ON position (key 0), the "spring" doesn't do its job and the lights do nothing...
Any hint?

In advance, thank you.
Sergio.
:oops:
 
Last edited:

Heretic

Resource contributor
Messages
6,830
Country
germany
Use the "LeftRelease" and "RightRelease" for spring loaded switches, i.e. return the switch contol variable to zero when any mouse button is released.

This...
Code:
(L:407_LandingLT_SwPositionControl, number) 25 * 25 +
...is all it takes for the switch animation. -1 * 25 + 25 = 0, 0 * 25 + 25 = 25 and 1 * 25+25 = 50.

Do not use the master battery switch, but main bus voltage to control electrically powered systems.

And do not do interactions with non-refresh rate critical MSFS systems functions (such as toggling lights) in 3D model code. Use a 2D background gauge as it's way easier to debug.
 
Messages
1,451
Country
mexico
...is all it takes for the switch animation. -1 * 25 + 25 = 0, 0 * 25 + 25 = 25 and 1 * 25+25 = 50.

Do not use the master battery switch, but main bus voltage to control electrically powered systems.

And do not do interactions with non-refresh rate critical MSFS systems functions (such as toggling lights) in 3D model code. Use a 2D background gauge as it's way easier to debug.
I will try to implement what you teached me and test it in the code.

Many thanks, my friend!
Sergio.
:)
 
Messages
1,451
Country
mexico
Hi Bjoern!

I don't know why I have the horrible tendency to overlook the simplest things and make them complicated... :mad:
Finally I got it right; following your instructions now the switch does what it is supposed to do!
Furthermore, it prevents event flooding in both versions and that's because I checked (A:Light Taxi, bool) before to trigger the
(>K:TOGGLE_TAXI_LIGHTS) event.

Now, the final versions, begining with the 2D gauge element to display the switch in its three states:
HTML:
      <!-- Landing Light On/Off Switch -->
          <Element>
              <Position X="104" Y="28"/>
              <Select>
                  <Value>(L:407_LandingLT_SwPositionControl, number)</Value>
                      <Case Value="1">
                          <Image Name="407_switch_coll_UP.bmp" Luminous="Yes"/>
                      </Case>
                      <Case Value="0">
                          <Image Name="407_switch_coll_MD.bmp" Luminous="Yes"/>
                      </Case>
                      <Case Value="-1">
                          <Image Name="407_switch_coll_DN.bmp" Luminous="Yes"/>
                      </Case>
              </Select>
          </Element>

Then, the mouse areas:
HTML:
     <!-- BEGIN: Landing Light On/Off Switch -->
           <!-- "Landing lights ON" (Switch UP, toggles lights to ON and spring back to middle position) -->
            <Area Left="104" Top="14" Width="25" Height="18">
                  <Cursor Type="Hand"/>
                  <Tooltip>ON (LMB)</Tooltip>
                      <Click Repeat="No" MouseWheelFlip="No" Kind="LeftSingle+LeftRelease">
                          (M:Event) 'LeftSingle' scmp 0 ==
                              if{
                                  1 (>L:407_LandingLT_SwPositionControl, number)
                                  (A:Light Taxi, bool) !
                                      if{ (>K:TOGGLE_TAXI_LIGHTS) }
                                  <!-- Click Sound Effect -->
                                  1 (>L:Bell_407_Click,number)
                                }
                          (M:Event) 'LeftRelease' scmp 0 ==
                              if{
                                  0 (>L:407_LandingLT_SwPositionControl, number)
                                  1 (>L:Bell_407_Click,number)
                                }
                      </Click>
            </Area>
       
            <!-- "Landing lights OFF" (Switch DOWN, toggle lights to OFF and spring back to middle position) -->
            <Area Left="104" Top="43" Width="25" Height="18">
                  <Cursor Type="Hand"/>
                  <Tooltip>OFF (RMB)</Tooltip>
                      <Click Repeat="No" MouseWheelFlip="No" Kind="RightSingle+RightRelease">
                          (M:Event) 'RightSingle' scmp 0 ==
                              if{
                                  -1 (>L:407_LandingLT_SwPositionControl, number)
                                  (A:Light Taxi, bool)
                                      if{ (>K:TOGGLE_TAXI_LIGHTS) }
                                  <!-- Click Sound Effect -->
                                  1 (>L:Bell_407_Click,number)
                                }
                          (M:Event) 'RightRelease' scmp 0 ==
                              if{
                                  0 (>L:407_LandingLT_SwPositionControl, number)
                                  1 (>L:Bell_407_Click,number)
                                }
                      </Click>
            </Area>
      <!-- END: Landing Light On/Off Switch -->

And finally, the 3D part code:
HTML:
            <!-- Landing Light On/Off: Spring Loaded Switch -->
                    <!-- Taxi lights VARIABLE is used instead the landing lights VARIABLE. (which is used to trigger the flood light in all gauges)-->
                    <!--
                            Key   0: Landing lights ON: Switch UP, toggles lights to ON and spring back to middle position.
                            Key 25: Neutral position: the spring return the switch to center AFTER the landing lights were toggled ON or OFF.
                            Key 50: Landing lights OFF: Switch DN, toggles lights to OFF and spring back to middle position.
                    -->
     <part>
          <name>bell407_landing_lt_switch</name>
               <animation>
                  <parameter>
                      <code>
                          <!-- Switch Position Control: it drives the animation -->
                          (L:407_LandingLT_SwPositionControl, number) s0 0 &lt; 50 * l0 0 == 25 * +
                      </code>
                      <lag>100</lag>
                  </parameter>
              </animation>
        <mouserect>
              <cursor>Hand</cursor>
              <tooltip_text>ON (LMB)/OFF (RMB)</tooltip_text>
              <mouse_flags>LeftSingle+RightSingle+LeftRelease+RightRelease</mouse_flags>
              <callback_code>
                  (M:Event) 'LeftSingle' scmp 0 ==
                      if{
                          1 (>L:407_LandingLT_SwPositionControl, number)
                          (A:Light Taxi, bool) !
                              if{ (>K:TOGGLE_TAXI_LIGHTS) }
                          <!-- Click Sound Effect -->
                          1 (>L:Bell_407_Click,number)
                        }
                  (M:Event) 'RightSingle' scmp 0 ==
                      if{
                          -1 (>L:407_LandingLT_SwPositionControl, number)
                          (A:Light Taxi, bool)
                              if{ (>K:TOGGLE_TAXI_LIGHTS) }
                          <!-- Click Sound Effect -->
                          1 (>L:Bell_407_Click,number)
                       }
                  (M:Event) 'LeftRelease' scmp 0 == (M:Event) 'RightRelease' scmp 0 == or
                      if{
                          0 (>L:407_LandingLT_SwPositionControl, number)
                          <!-- Click Sound Effect -->
                          1 (>L:Bell_407_Click,number)
                        }
              </callback_code>
        </mouserect>
      </part>

EDIT 1:
I don't know why but your code snippet didn't worked; I used the one I wrote instead. :oops:
(L:407_LandingLT_SwPositionControl, number) 25 * 25 + (yours)
(L:407_LandingLT_SwPositionControl, number) s0 0 &lt; 50 * l0 0 == 25 * + (mine)

Thank you very much!
All the best,
Sergio.
:)
 
Last edited:

Heretic

Resource contributor
Messages
6,830
Country
germany
I don't know why but your code snippet didn't worked; I used the one I wrote instead. :oops:
(L:407_LandingLT_SwPositionControl, number) 25 * 25 + (yours)

Huh? This is my standard way of doing three position switches and works perfectly for me.
 

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
I use a somewhat simpler method for 3 position, center off spring back switches:
Code:
  <PartInfo>
    <Name>C310_switch_FuelTankGauge</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          25 (L:FuelTankSwitch, number) 25 * +
        </Code>
        <Lag>400</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <TooltipText>Fuel Level Select</TooltipText>
      <MouseFlags>LeftSingle+LeftRelease+RightSingle+RightRelease</MouseFlags>
      <CallbackCode>
        (M:Event) 'LeftSingle' scmp 0 == if{ -1 (>L:FuelTankSwitch, number) }
        (M:Event) 'RightSingle' scmp 0 == if{ 1 (>L:FuelTankSwitch, number) }
        (M:Event) 'LeftRelease' scmp 0 ==
        (M:Event) 'RightRelease' scmp 0 ==  or if{ 0 (>L:FuelTankSwitch, number) }
        1 (>L:XMLSND1,bool)
      </CallbackCode>
    </MouseRect>
  </PartInfo>
 
Messages
10,088
Country
us-arizona
I have the worlds most longest 3 position spring back (one side only spring back) animation... Perhaps even in the entire galaxy, as aliens have marvelled at this animation coding, asking me... 'Bill of Earth, how were you able to make this this long???'


Code:
<PartInfo>
        <Name>learjet24_gen_left</Name>
        <AnimLength>50</AnimLength>
        <Animation>
            <Parameter>
              <Code>
                 (L:LEFT_GEN_SELECT_POS,number)
              </Code>
            </Parameter>
        </Animation>
        <MouseRect>
            <Cursor>Hand</Cursor>
            <TooltipText>Left Generator Starter Selector</TooltipText>
    <MouseFlags>LeftSingle+LeftRelease+LeftDrag+Wheel</MouseFlags>
    <CallbackCode>
      (M:Event) 'LeftSingle' scmp 0 ==
      if{
        (M:Y) (&gt;L:LEFT_GEN_MOUSEPOS,number)
                 1 (&gt;L:XMLSND1,enum)
        quit
      }
      
      (M:Event) 'LeftDrag' scmp 0 ==
      if{
        (M:Y) (L:LEFT_GEN_MOUSEPOS,number) - -1.0 * (L:LEFT_GEN_SELECT_POS,number) + 0 max 50 min (&gt;L:LEFT_GEN_SELECT_POS,number)
        (M:Y) (&gt;L:LEFT_GEN_MOUSEPOS,number)
                   quit
            (M:Y) (L:LEFT_GEN_SELECT_POS,number) 3 &lt;
                    if{ (A:GENERAL ENG STARTER:1, bool) 0 ==
                      if{ (>K:TOGGLE_STARTER1) } }
      }
      
      (M:Event) 'LeftRelease' scmp 0 ==
      if{
            (M:Y) (L:LEFT_GEN_SELECT_POS,number) 5 &lt;
        if{
                25 (&gt;L:LEFT_GEN_SELECT_POS,number)
                 1 (&gt;L:XMLSND1,enum)

        }
        (M:Y) 6 45 (L:LEFT_GEN_SELECT_POS,number) rng
        if{
                25 (&gt;L:LEFT_GEN_SELECT_POS,number)
                   (A:GENERAL ENG GENERATOR SWITCH:1, bool) 1 ==
                     if{ (>K:TOGGLE_ALTERNATOR1) }
                   (A:GENERAL ENG STARTER:1, bool) 1 ==
                     if{ (>K:TOGGLE_STARTER1) }

        }
        (M:Y) (L:LEFT_GEN_SELECT_POS,number) 46 &gt;
        if{
                50 (&gt;L:LEFT_GEN_SELECT_POS,number)
                   (>K:TOGGLE_ALTERNATOR1)
        }
      }
            </CallbackCode>
        </MouseRect>
    </PartInfo>
 
Messages
1,451
Country
mexico
Huh? This is my standard way of doing three position switches and works perfectly for me
Hi Bjoern!

I am sure it's nothing wrong, the problem resides in another place; another gauge (which I don't fully understand where on hearth the problem is) . It is for the electrical system and is on the way to be revised. The same with a nice piece of code logic which also is out of my current skills (engine control). I managed to make it "share" some of its secrets with me; but its not cooperating very well... :banghead:

I use a somewhat simpler method for 3 position, center off spring back switches:
Dear Sr. , thank you kindly. For sure it will be used in this helicopter!

I have the worlds most longest 3 position spring back (one side only spring back) animation... Perhaps even in the entire galaxy, as aliens have marvelled at this animation coding, asking me... 'Bill of Earth, how were you able to make this this long???'
I will ask you then: 'Bill of Earth, how were you able to make this this long???' :rotfl:

For sure, I will read and try to understand the best I can every line of code you've shared with me.
Thank you all for helping me every time I need it.
Sergio.
:)
 
Messages
1,451
Country
mexico
I'm the "other Bill" but yes, that is what that means. :wizard:
LOL, I know... Perhaps the confusion was due because I always write "Fr. Leaming" when I am referring to you dear Sr. and "Bill" to Lionheart.
I'd should have a pint of beer behalf of you both! :scratchch

Cheers!
Sergio.
;)
 

Heretic

Resource contributor
Messages
6,830
Country
germany
Just stick to "Bill L." and "Bill O.". Fits the bill just nicely*.



*I'm absolutely not sorry for that pun.
 
Messages
10,088
Country
us-arizona
Yep... and yep... or you can refer to me by what my poor Mom calls me.. wacky..


Here is the 2D flat version of this overly exotic single click tripple position switch. Much easier. The above is for the model part in the XML. This is the gauge version.


Code:
    <Element>
        <Select>
            <Value>(L:LEFT_GEN_SELECT_POS,number)</Value>
            <Case Value="0">
                <Image Name="Lear24BToggleOff.bmp" />
            </Case>
            <Case Value="25">
                <Image Name="Lear24BToggleMid.bmp" />
            </Case>
            <Case Value="50">
                <Image Name="Lear24BToggleOn.bmp" />
            </Case>
        </Select>
    </Element>


<Mouse>
      <Area Left="0" Right="51" Top="-20" Bottom="50">
       <Tooltip>Starter Generator Switch LH</Tooltip>
            <Cursor Type="Grab"/>
             <Click Kind="LeftSingle">

                 50 (&gt;L:LEFT_GEN_SELECT_POS,number)
                  1 (&gt;L:XMLSND1,enum)
                    (A:GENERAL ENG GENERATOR SWITCH:1, bool) 0 ==
                     if{ (>K:TOGGLE_ALTERNATOR1) }
            </Click>
      </Area>


      <Area Left="0" Right="51" Top="52" Bottom="130">
       <Tooltip>Starter Generator Switch LH</Tooltip>
            <Cursor Type="Grab"/>

             <Click Kind="LeftSingle">
                 25 (&gt;L:LEFT_GEN_SELECT_POS,number)
                  1 (&gt;L:XMLSND1,enum)
                    (A:GENERAL ENG GENERATOR SWITCH:1, bool) 1 ==
                     if{ (>K:TOGGLE_ALTERNATOR1) }
            </Click>
      </Area>

      <Area Left="0" Right="51" Top="131" Bottom="220">
       <Tooltip>Starter Generator Switch LH</Tooltip>
            <Cursor Type="Grab"/>

             <Click Kind="LeftDrag+Leave">
                (M:Event) 'LeftDrag' scmp 0 ==
                 if{
                  0 (&gt;L:LEFT_GEN_SELECT_POS,number)
                  1 (&gt;L:XMLSND1,enum)
                    (A:GENERAL ENG STARTER:1, bool) 0 ==
                     if{ (>K:TOGGLE_STARTER1) }
                   }
                (M:Event) 'Leave' scmp 0 ==
                 if{
                 25 (&gt;L:LEFT_GEN_SELECT_POS,number)
                  1 (&gt;L:XMLSND1,enum)
                    (A:GENERAL ENG STARTER:1, bool) 1 ==
                     if{ (>K:TOGGLE_STARTER1) }
                   }
            </Click>
      </Area>



</Mouse>



Note that there is a left and right on these and only one side shown.
 
Messages
1,451
Country
mexico
Yep... and yep... or you can refer to me by what my poor Mom calls me.. wacky..
Very kind of you, my friend. :)

On the other hand, thank you! The entire post is very interesting with lines of code; I like that!. Each new gauge I write, I appreciate a thousand times more the time all lovely people spend answering my questions.

A sincere acknowledge and my entire respect to all of you.
Sergio.
:wave:
 
Messages
10,088
Country
us-arizona
I remember trying to come to grips with basic logic. Poor Bill Leaming having to try to explain to me, my inability to understand code. Finally, it happened.. the light came on.. and it all made sense. I was so grateful.
 
Top