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...
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..."
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!
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>