• 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 Switch 1-2-3-4-5-4-3-2-1

Messages
59
Country
france
I wish to create a switch with 5 positions:
  • Position 1: nothing happens
  • Position 2 -> action 1
  • Position 3 -> action 2 and action 3
  • Position 4 -> action 4 or action 5
  • Position 5 -> action 6
Left Click to go from position 1 to position 2…. position 5
Right Click to go from position 5 to position 4…. position 1

The switch must remain on the selected position

Questions:
  1. What code to write in modeldef?
  2. What animation to create in 3dsmax?

    Other question :
    • Does exist a tutorial about modeldef ?
Thank you for your help
 

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
1. First thing is that counting begins at zero (0), so this template is designed around that reality.

2. As designed, this template assumes keyframe animation in Max/GMax at frames 0,1,2,3,4. If you wish to expand this to a longer animation, simply multiply the <Code>(L:FivePosSwitch,enum) nn *</Code> by the appropriate value nn, for example 10 for an animation with keys set at 0,10,20,30,40.

3. Logically speaking, left click should DECREASE and right click should INCREASE, so that's how I've laid out the sample template. Simply exchange LeftSingle and RightSingle to reverse the action. I've also included the logic to enable the mouse wheel to be used. Simply omit this if you don't want it included.

4. The min and max numbers are inverted logic in XML Schema! So, the lower limit is set to 0 max, and the upper limit is set to 4 min.

5. Since I have no idea what "actions" you want, I simply used the generic form as stand ins.
Code:
(>K:DoAction[I][COLOR="red"]n[/COLOR][/I])
6. Doing two actions is simple enough by simply stating two things to do. Doing an OR is simply not possible! How would the sim know which to do unless you provide an alternative from which to decide? As a result, note that you need to provide (L:SomeOtherCondition,bool) to help it... :D

7. You would of course have to provide an <Animation> entry with a unique GUID.

8. No, there are unfortunately no tutorials available. We all have to learn this the hard way: "by guess and by God..." :rotfl:

9. Note that this template is easily expanded to support any number of switch positions. For example I have a switch in one model with 32 positions! :eek:
Code:
<Animation name="Five Position Switch" guid="a30d1108-0e02-4e78-a41a-4c072a815e90" length="5" type="Sim" typeParam2="Five Position Switch" typeParam="AutoPlay" />

<PartInfo>
  <Name>Five Position Switch</Name>
  <AnimLength>5</AnimLength>
  <Animation>
    <Parameter>
      <Code>
        (L:FivePosSwitch,enum)
      </Code>
      <Lag>400</Lag>
    </Parameter>
  </Animation>
  <MouseRect>
    <Cursor>Hand</Cursor>
    <MouseFlags>LeftSingle+RightSingle+WheelUp+WheelDown</MouseFlags>
    <CallbackCode>
      [COLOR="red"]<!-- DECREASE -->[/COLOR]
      (M:Event) 'LeftSingle' scmp 0 ==
        if{ (L:FivePosSwitch, enum) -- 0 max (>L:FivePosSwitch, enum) }
      (M:Event) 'WheelDown' scmp 0 ==
        if{ (L:FivePosSwitch, enum) -- 0 max (>L:FivePosSwitch, enum) }
        
      [COLOR="red"]<!-- INCREASE -->[/COLOR]
      (M:Event) 'RightSingle' scmp 0 ==
        if{ (L:FivePosSwitch, enum) ++  4 min (>L:FivePosSwitch, enum) }
      (M:Event) 'WheelUp' scmp 0 ==
        if{ (L:FivePosSwitch, enum) ++  4 min (>L:FivePosSwitch, enum) }
        
      [COLOR="red"]<!-- EVALUATE SWITCH POSITION AND TAKE ACTION -->[/COLOR]

      [COLOR="Red"]<!-- NOTE THE FOLLOWING IS NOT STRICTLY NECESSARY, BUT IT CLEARLY "DOES NOTHING!" -->[/COLOR]
      (L:FivePosSwitch, enum) 0 == if{  }  

      (L:FivePosSwitch, enum) 1 == if{ (>K:DoAction1) }

      (L:FivePosSwitch, enum) 2 == if{ (>K:DoAction2) (>K:DoAction3) }

      (L:FivePosSwitch, enum) 3 == (L:SomeOtherCondition,bool) 0 == and if{ (>K:DoAction4) }
      (L:FivePosSwitch, enum) 3 == (L:SomeOtherCondition,bool) 1 == and if{ (>K:DoAction5) }

      (L:FivePosSwitch, enum) 4 == if{ (>K:DoAction6) }
    </CallbackCode>
  </MouseRect>
</PartInfo>
 
Last edited:
Messages
59
Country
france
Help

I wish to make visible a light when the switche is on the positons 1,2,3,and 4

I've modified your code... and mine doesn't work.

<PartInfo>
<Name>000-NORATLAS_Sélecteur Magnéto_G</Name>
<AnimLength>50</AnimLength>
<Animation>
<Parameter>
<Code> (L:Magneto_G,enum) 10 *
</Code>
<Lag>400</Lag>
</Parameter>
</Animation>

<MouseRect>
<Cursor>Hand</Cursor>
<MouseFlags>LeftSingle+RightSingle</MouseFlags> <TooltipText>Selecteur Magnetos Moteur Gauche</TooltipText>
<CallbackCode>
<!-- DECREASE -->
(M:Event) 'LeftSingle' scmp 0 ==
if{ (L:Magneto_G,enum) -- 0 max (&gt;L:Magneto_G,enum) }
<!-- INCREASE -->
(M:Event) 'RightSingle' scmp 0 ==
if{ (L:Magneto_G,enum) ++ 5 min (&gt;L:Magneto_G,enum) }


<!-- EVALUATE SWITCH POSITION AND TAKE ACTION -->

<!-- NOTE THE FOLLOWING IS NOT STRICTLY NECESSARY, BUT IT CLEARLY "DOES NOTHING!" -->

(L:Magneto_G,enum) 0 == if{ }
(L:Magneto_G,enum) 1 == if{ (L:Lampe_Magneto_G_Visible,bool) 1 == }
(L:Magneto_G,enum) 2 == if{ (L:Lampe_Magneto_G_Visible,bool) 1 == } (L:Magneto_G,enum) 3 == if{ (L:Lampe_Magneto_G_Visible,bool) 1 == }
(L:Magneto_G,enum) 4 == if{ (L:Lampe_Magneto_G_Visible,bool) 1 == } (L:Magneto_G,enum) 5 == if{ }
</CallbackCode>
</MouseRect>

</PartInfo>

the switch moves normally , and L:Magneto_G,enum gives the values: 0,1,2,3,4 and 5

but L:Lampe_Magneto_G_Visible,bool gives always 0

Light is associated to this code:

<PartInfo>
<Name>000-NORATLAS_Voyant_H_G_Allumé</Name>
<Visibility>
<Parameter>
<Code>
(L:Lampe_Magneto_G_Visible,bool) 1 == if{ 1 } els{ 0 }
</Code>
</Parameter>

</Visibility>

</PartInfo>

Thank you for your help.
 

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
First off, you need 4, not 5 for the script. Remember, 0 = position 1!
You asked for a five position switch. If you use 5 min instead of 4 min, you will have a SIX position switch...

It should be:

Code:
(M:Event) 'RightSingle' scmp 0 == 
if{ (L:Magneto_G,enum) ++ [COLOR="Red"]4[/COLOR] min (&gt;L:Magneto_G,enum) }
Code:
XML = position
0   =   1
1   =   2
2   =   3
3   =   4
4   =   5
Second, you have the script for setting the L:var wrong:

Code:
(L:Magneto_G,enum) 1 == if{ (L:Lampe_Magneto_G_Visible,bool) 1 == } 
 
should be:

(L:Magneto_G,enum) 1 == if{ [COLOR="Red"]1[/COLOR] ([COLOR="red"]>[/COLOR]L:Lampe_Magneto_G_Visible,bool) }

I provided you with a template for the exact XML script required. Why change it so it won't work??? :eek:
 
Last edited:

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
I'm learning, Teacher, I'm learning ! :)

If it helps, think of the right-arrow ">" as meaning "put into..."

IOW: 1 (>L:Lampe_Magneto_G_Visible,bool) means "put 1 into this L:variable..."
 
Messages
10,088
Country
us-arizona
Bill,

Could this code be used as a manual for selecting pages? Another words, bringing up pages into visibility?


Bill O
 
Top