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

FSXA GMAX Dummy knob code

Messages
468
Country
ca-ontario
I have been trying to code a dummy knob/rotating disc for my model and as usual I've hit problems. :rolleyes:

The part is actually the cabin heat control and consists of a flat disc that protrudes slightly through the panel fascia.

I can get the disc to rotate it but it just jumps from the start point in the animation to the end point. I have searched for code examples and tried adapting existing code I have for knobs but nothing seems to work.

I have posted the current code I am using below, the animation is over 100 frames and it's KF'd at 0, 50 and 100:

Code:
<PartInfo>
  <Name>cabin_temp</Name> 
   <AnimLength>100</AnimLength>
   <Animation>
    <Parameter>
     <Code>
       (L:random_2, enum) 100 *
     </Code> 
     <Lag>100</Lag> 
    </Parameter> 
   </Animation>
     <MouseRect>
	 <Cursor>Hand</Cursor>
	 <TooltipText>Cabin Temp</TooltipText>
	 <CallbackCode> 
               (L:random_2, enum) ! (&gt;L:random_2, enum)
     </CallbackCode> 
      <MouseFlags>LeftSingle+LeftDrag+Wheel</MouseFlags>
              <Variable>RANDOM_2</Variable>
                <Units>percent</Units>
                <Scale>163.84</Scale>
                <YScale>-163.84</YScale>
                <MinValue>-16384</MinValue>
                <MaxValue>16384</MaxValue>
     </MouseRect>
</PartInfo>

The 'Random_2' tag is one I got from some code on FFDS, it could be 'fried bananas' for that matter as it doesn't actually do anything in the sim. I used 'Random_1' in another dummy knob (the cabin heat on/off) and it works fine.

Can anyone see why I cant get a smooth, gradual movement on the part using either the mouse wheel or a left-click/drag operation?
 
Last edited:
You can use this code.

Code:
       <PartInfo>
   <Name>fe_cabin_temp_control_galley</Name>
    <AnimLength>300</AnimLength>
     <Animation>
      <Parameter>
       <Code>	
	   (L:fe cabin temp control regulator galley, enum) 20 *
        </Code>
         <Lag>300</Lag>
        </Parameter>
       </Animation>
	<MouseRect>
	 <Cursor>Hand</Cursor>
	   <MouseFlags>LeftSingle+RightSingle+WheelUp+WheelDown</MouseFlags>
	    <CallbackCode>
			(M:Event) 'LeftSingle' scmp 0 ==
				if{ (L:fe cabin temp control regulator galley, enum) -- 0 max (&gt;L:fe cabin temp control regulator galley, enum) }
			(M:Event) 'RightSingle' scmp 0 ==
				if{ (L:fe cabin temp control regulator galley, enum) ++ 15 min (&gt;L:fe cabin temp control regulator galley, enum) }
					(M:Event) 'WheelDown' scmp 0 ==
				if{ (L:fe cabin temp control regulator galley, enum) -- 0 max (&gt;L:fe cabin temp control regulator galley, enum) }
			(M:Event) 'WheelUp' scmp 0 ==
				if{ (L:fe cabin temp control regulator galley, enum) ++ 15 min (&gt;L:fe cabin temp control regulator galley, enum) }
		</CallbackCode>
	</MouseRect>
   </PartInfo>

Change the animation length to what ever you like, but then take calculation for that in your "new" code.

For instance:

Code:
   <PartInfo>
   <Name>fe_hydraulic_selector_sys1</Name>
    <AnimLength>80</AnimLength>
     <Animation>
      <Parameter>
       <Code>	
	   (L:fe hydraulic system selector 1, enum) 20 *
        </Code>
         <Lag>300</Lag>
        </Parameter>
       </Animation>
	<MouseRect>
	 <Cursor>Hand</Cursor>
	   <MouseFlags>LeftSingle+RightSingle</MouseFlags>
	    <CallbackCode>
			(M:Event) 'LeftSingle' scmp 0 ==
				if{ (L:fe hydraulic system selector 1, enum) -- 0 max (&gt;L:fe hydraulic system selector 1, enum) }
			(M:Event) 'RightSingle' scmp 0 ==
				if{ (L:fe hydraulic system selector 1, enum) ++ 4 min (&gt;L:fe hydraulic system selector 1, enum) }
		</CallbackCode>
	</MouseRect>
   </PartInfo>

As you can see the animation lenght is only 80 in the 2. code and increments is also 20.
Code:
(L:fe hydraulic system selector 1, enum) 20 *

Therefore:
First code:
300 <- Keyframes / 20 <-Increments = ++ 15 min.
300/20=15

Second code:
80 <- Keyframes / 20 <-Increments = ++ 4 min.
80/20=4
 
Last edited:
Thanks for that Zeiten, I think I am starting to see the light at the end of the tunnel. :scratchch

I can see key things I got wrong in my code when I compare it to yours. I will make some changes and test.
 
I just modified my code and spent some time testing and the results are rather baffling to say the least.

This is the current code:

Code:
<PartInfo>
  <Name>cabin_temp</Name> 
   <AnimLength>300</AnimLength>
   <Animation>
    <Parameter>
     <Code>
       (L:random_2, enum) 30 *
     </Code> 
     <Lag>100</Lag> 
    </Parameter> 
   </Animation>
     <MouseRect>
	 <Cursor>Hand</Cursor>
	 <TooltipText>Cabin Temp</TooltipText>
     <MouseFlags>LeftSingle+RightSingle+Wheel</MouseFlags>
	 <CallbackCode> 
         (M:Event) 'LeftSingle' scmp 0 == if{ (L:random_2, enum) -- 0 max (&gt;L:random_2, enum) }
		 (M:Event) 'RightSingle' scmp 0 == if{ (L:random_2, enum) ++ 30 max (&gt;L:random_2, enum) }
		(M:Event) 'WheelDown' scmp 0 == if{ (L:random_2, enum) -- 0 max (&gt;L:random_2, enum) }
		(M:Event) 'WheelUp' scmp 0 == if{ (L:random_2, enum) ++ 30 min (&gt;L:random_2, enum) }
	 </CallbackCode>
     </MouseRect>
</PartInfo>

When I check it in FSX the mouse wheel will work (rotating the wheel/dial left/right). However, the right-click button advances the animation all the way to the end instead of going in steps and the left-click button will reverse the direction in the correct 30 frame steps but only if the animation is not at the frame 300 position. In addition using either the left or right mouse button will then prevent the mouse wheel animation from working and the only way to get that back is to re-load the aircraft.

So, the mouse wheel will work provided you don't click a mouse button while hovering over the part in the VC, the left button decreases the animation in the correct steps provided that the animation is not at frame 300 and the right button advances the animation to frame 300 directly without stopping at each KF as required.

HELP!!!!!!!!!!!!!!!! I think I am going crazy! :rotfl:
 
Check your mouseflags.

Use WheelUp and WheelDown instead of just wheel.

And 300 \ 30 is not 30, but 10.
 
Check your mouseflags.

Use WheelUp and WheelDown instead of just wheel.

And 300 \ 30 is not 30, but 10.
DOH!!!!!!!!!!! :eek:

I fixed the mouse wheel and I must have had a brain-fart when I did the math, what I meant was 10 increments of 30 frames from KF 0 to KF 300. :rolleyes:

I am getting much closer, the mouse wheel now works perfectly, the left-click works to move the dial by 1 KF (i.e. 30 frames) with each click but the right-click still sends the part to KF 300 directly with a single click.

Hmmmmm. :confused:

Here's the current block of pertinent code.

Code:
<Parameter>
     <Code>
       (L:random_2, enum) 10 *
     </Code> 
     <Lag>100</Lag> 
    </Parameter> 
   </Animation>
     <MouseRect>
	 <Cursor>Hand</Cursor>
	 <TooltipText>Cabin Temp</TooltipText>
     <MouseFlags>LeftSingle+RightSingle+WheelUp+WheelDown</MouseFlags>
	 <CallbackCode> 
         (M:Event) 'LeftSingle' scmp 0 == if{ (L:random_2, enum) -- 0 max (&gt;L:random_2, enum) }
		 (M:Event) 'RightSingle' scmp 0 == if{ (L:random_2, enum) ++ 30 max (&gt;L:random_2, enum) }
		(M:Event) 'WheelDown' scmp 0 == if{ (L:random_2, enum) -- 0 max (&gt;L:random_2, enum) }
		(M:Event) 'WheelUp' scmp 0 == if{ (L:random_2, enum) ++ 30 min (&gt;L:random_2, enum) }
	 </CallbackCode>
 
Off course.

Check you min max on RightSingle.

-- 0 max
++ 30 max?

Try ++ 30 min instead:)
 
You can also save yourself some typing (and less chance of typos!) by combining the mouse events:
Code:
<CallbackCode>
  (M:Event) 'LeftSingle' scmp 0 ==
  (M:Event) 'WheelDown' scmp 0 == or
  if{ (L:random_2, enum) -- 0 max (&gt;L:random_2, enum) }
  
  (M:Event) 'RightSingle' scmp 0 == 
  (M:Event) 'WheelUp' scmp 0 == or
  if{ (L:random_2, enum) ++ 30 min (&gt;L:random_2, enum) }
</CallbackCode>
In the above script 'LeftSingle' OR 'WheelDown' will decrement the L:variable.

Likewise, 'RightSingle' OR 'WheelUp' will increment the L:variable.
 
Off course.

Check you min max on RightSingle.

-- 0 max
++ 30 max?

Try ++ 30 min instead:)
Thank you Zeiten that fixed the problem and I now have a fully working cabin temperature control. :) I even added a 'repeat' function to the mouse click so you can click and hold and the disc rotates.

Here is the final working code in case anyone comes along later and wants to use it.

Code:
<PartInfo>
  <Name>cabin_temp</Name> 
   <AnimLength>300</AnimLength>
   <Animation>
    <Parameter>
     <Code>
       (L:cabin_temp, enum) 10 *
     </Code> 
     <Lag>100</Lag> 
    </Parameter> 
   </Animation>
     <MouseRect>
	 <Cursor>Hand</Cursor>
	 <TooltipText>Cabin Temp</TooltipText>
     <MouseFlags>LeftSingle+RightSingle+DownRepeat+WheelUp+WheelDown</MouseFlags>
	 <CallbackCode> 
         (M:Event) 'RightSingle' scmp 0 == if{ (L:cabin_temp, enum) -- 0 max (&gt;L:cabin_temp, enum) }
		 (M:Event) 'LeftSingle' scmp 0 == if{ (L:cabin_temp, enum) ++ 30 min (&gt;L:cabin_temp, enum) }
		(M:Event) 'WheelDown' scmp 0 == if{ (L:cabin_temp, enum) -- 0 max (&gt;L:cabin_temp, enum) }
		(M:Event) 'WheelUp' scmp 0 == if{ (L:cabin_temp, enum) ++ 30 min (&gt;L:cabin_temp, enum) }
	 </CallbackCode>
     </MouseRect>
</PartInfo>
 
You can also save yourself some typing (and less chance of typos!) by combining the mouse events:

Code snipped for brevity.

In the above script 'LeftSingle' OR 'WheelDown' will decrement the L:variable.

Likewise, 'RightSingle' OR 'WheelUp' will increment the L:variable.

Thanks Bill, I may try that but at the moment it's working and I can always refer to the above if/when I need to write something similar.

Just for reference for anyone reading later I switched the code around in the final version (posted above) as the original animation was working backwards on the mouse clicks when viewed in FSX, now when you left-click the disc moves to the left and vice versa.
 
Back
Top