• 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 Autopilot button code

Messages
468
Country
ca-ontario
I have been working on converting some working FS9 code found here http://www.aerodynamika.com/cgi-bin/yabb2/YaBB.pl?num=1189954045 so that it will work in FSX. I do intend on updating that thread if/when I get all my changes done so that there will be code available for FSX modellers.

I have currently hit a show stopper with some new code though and I can't seem to find a way around the problem. The original code did not cover buttons for incrementing/decrementing the altitude setting and I couldn't find existing code in the modeldef file despite deep searches. I have also searched in 2D gauges I have for clues.

I tried to solve the issue with the following code but when I export the model the button the code is applied to does not show in game so I am guessing an error in the code is preventing the button from showing in the sim.

Code:
<PartInfo>
     <Name>ap_switch_alt_inc</Name>
     <AnimLength>50</AnimLength>
	 <Animation>
       <Parameter>
          <Sim>
			<Variable>AP ALT VAR INC</Variable>
            <Units>bool</Units>
            <Scale>50</Scale>
          </Sim>
          <Lag>400</Lag>
       </Parameter>
     </Animation>
     <MouseRect>
        <Cursor>Hand</Cursor>
        <EventID>AP_ALT_VAR_INC</EventID>
     </MouseRect>
</PartInfo>

The above code is for the 'UP' button on the autopilot and is supposed to increment the 'target' altitude used by the altitude hold function. I will have to write similar code for the 'DOWN' button to decrement the target altitude.

I also intend to add a 'mousewheel' feature once I get the code working.

Can anyone see why the code is not working and/or why the button doesn't show in sim (animations/scale etc. have all been triple-checked and are OK)?
 
First of all, there's no such A:variable as what you've tried to use...

Second, if you have a pushbutton, then you will need to use separate L:var to control the button.

This example script will send the command for alt increase, and set an L:var to "push" the 3d button.

When releasing the button, the LeftRelease or LeftDrag even will reset the L:var for the button back to 0. I've specified a low <Lag> speed to allow the button to move more slowly.

The +DownRepeat flag will allow you to increase the altitude as long as the button is pressed. Trying to use the wheel for a button is not really possible, because there's no WheelRelease flag...

...the button would just get stuck down and increase forever! :rotfl:
Code:
<Animation name="ap_switch_alt_inc" guid="16d0cf9f-3f1c-4b99-916c-bfe79413e892" typeParam2="ap_switch_alt_inc" length="50" type="Sim" typeParam="AutoPlay" />

<!-- ALTITUDE SET -->
<PartInfo>
  <Name>ap_switch_alt_inc</Name>
  <AnimLength>50</AnimLength>
  <Animation>
    <Parameter>
      <Code>(L:ap_switch_alt_inc,bool) 50 *</Code>
    </Parameter>
    <Lag>30</Lag>
  </Animation>
  <MouseRect>
    <Cursor>Hand</Cursor>
    <MouseFlags>LeftSingle+LeftRelease+LeftDrag+DownRepeat</MouseFlags>
    <CallbackCode>
      (M:Event) 'LeftSingle'  scmi 0 ==
      if{ (>K:AP_ALT_VAR_INC) 1 (>L:ap_switch_alt_inc,bool) }

      (M:Event) 'LeftRelease' scmi 0 ==
      (M:Event) 'LeftDrag'     scmi 0 == or
      if{ 0 (>L:ap_switch_alt_inc,bool) }
    </CallbackCode>
  </MouseRect>
</PartInfo>
 
Last edited:
First of all, there's no such A:variable as what you've tried to use...

I found that line in the SDK under 'Core Utilities Kit/Variables/Event IDs' so assumed (wrongly) that it was a valid variable. :o

Second, if you have a pushbutton, then you will need to use separate L:var to control the button.

Looking at it later I had come to the same conclusion seeing as the base code I used was for a simple on/off type button. :)

Thanks for the code block, I will test it ASAP.

BTW I just searched the SDK for your L:var in an effort to educate myself as to where it hides and couldn't find it at all. Is there a definitive list somewhere of just what variables are available for use in a 3D VC (as opposed to 2D gauge code) because I always seem to be scratching around trying to find suitable data to use?

Finally (yeah right, like I'm ever going to be done asking questions!), is it safe to assume that for the altitude decrease button I can simply switch all of your '_inc' tags to '_dec' tags in a copied block of code?

EDIT:
Answering my own post I found a few things re. the above:

1. I forgot that L:vars are user defined so won't be in a list anywhere but I do see now how they tie into data the sim understands via the K:var.

2. I have a working decrement button now too by simply changing all instances of '_inc' to '_dec'.

3. I had to add a little bit to your code line Bill as the button worked in terms of incrementing the value but didn't animate so it now looks like this:

Code:
<Code>(L:ap_switch_alt_inc,bool) 50 *</Code>
 
Last edited:
I found that line in the SDK under 'Core Utilities Kit/Variables/Event IDs' so assumed (wrongly) that it was a valid variable. :o

Events are commands...

Variables are read only data...

Not all commands have a corresponding variable or variables. ;)

Keep at it Larry and before long all this will begin to make sense, there is a logical pattern to all of this, really!

Note: thanks for the 50 * correction. I've edited my previous post to include this to prevent anyone else from being frustrated by my omission...
 
Back
Top