SimConnect + WASM combined project using VS2019

Chapter 4: Variables

One of the things that confused me most when I was starting with SimConnect are all the different types of variables. This is probably the most difficult chapter for me to explain.

@Umberto67 posted a nice summary of several variables in this post. At the time that I read this (about a month ago), I only understood half of it. But the good thing is that you can bookmark posts in this forum, and re-read them when you have acquired more knowledge. Thanks to a lot of reading, I think I start getting it. But I haven’t experimented with all the possible variable types yet, and might even never need to do so within the scope of my implementation. This means that there are definitely some bits and pieces that I might still be missing, so be a bit cautious with the explanation I’m giving below.

Bottom line is that we have “real variables” which you can give a value and/or you can read the value from (example: “KOHLSMAN SETTING HG”), and some are called “events” which you only trigger and do not necessarily need a value (example: “A32NX.FCU_HDG_INC”).

In the below explanation, I will call them all “variables”, which is including “real variables” and “events”.

We can make a distinction between 2 types of variables:

  1. Variables directly controlled via SimConnect
    I call these variables “native MSFS2020 variables”, because they are found within the simulator. You can find a detailed explanation in the SDK Documentation, where these are called “Simulation Variables” and Events.
    Example of such variable: AUTOPILOT ALTITUDE LOCK VAR.
    The main characteristic of these variables is that we can control them directly with SimConnect.

  2. Variables controlled through a WASM module
    I call these variables “custom variables”, because they are in a lot of (all of the?) cases very specific for a certain object in MSFS2020, example an add-on airplane.
    Example of such variable: A32NX_EFIS_L_OPTION. This is only available for the FlyByWire A32NX, which is a free A320 add-on of very high quality that you can find here. I’m going to use this add-on regularly in this tutorial.
    The main characteristic of these variables is that we can only control them through a WASM module.

If we are going to deal with WASM (see in one of the next chapters), we can use a function called execute_calculator_code. The nice thing is that with this function, you can access all the types of variables, whether they are “native MSFS2020 variables” or “custom variables”. But for this function to know which type of variable we are dealing with, the variables are prefixed with a character and a ‘:’. You can find all these prefixes in the section Variable Types in this part of the SimConnect SDK Documentation. This immediately shows how many different variables do exists (and I only know a few of them so far).

I will use the same type of prefixes in my implementation. At the time of writing this tutorial, the following variable types are used:

  • A: - These are the “native MSFS2020 variables”, which in the FBW documentation are also called “SIMCONNECT VAR”.
  • L: - These are the “custom variables” or also called LVars, which in the FBW documentation are also called “Custom LVAR”.
  • K: - These are EVENTS, and could be “native” or “custom”. With SimConnect, the rule is that if the variable name doesn’t contain a dot ‘.’, it is a “native” one and can be controlled directly via SimConnect. If the name contains a “.”, then it is a custom event and needs to be controlled through WASM. In the FBW documentation these are also called “SIMCONNECT EVENT” or “Custom EVENT”.

Remark: In the FBW documentation, SIMCONNECT VAR or SIMCONNECT EVENT is sometimes written as MSFS VAR or MSFS EVENT - at least, I think that these are the same. If my interpretation is wrong, please don’t hesitate to comment.

The examples we are going to use in my implementation are the following:

  • A:AUTOPILOT ALTITUDE LOCK VAR (native MSFS variable)
  • A:KOHLSMAN SETTING HG (native MSFS variable)
  • A:LIGHT POTENTIOMETER (native MSFS variable)
  • L:A32NX_EFIS_L_OPTION (custom FBW A32NX variable)
  • L:A32NX_EFIS_R_OPTION (custom FBW A32NX variable)
  • K:FUELSYSTEM_PUMP_TOGGLE (native MSFS event - there is no “.” in the name)
  • K:A32NX.FCU_HDG_INC (custom FBW A32NX event - there is a “.” in the name)

One of the challenging things is finding the variable you need to control a certain switch, or read a certain indication in an airplane. Because that’s what you need if you want to interface with your cockpit hardware. I have no common method for this, because it will heavily depend on the airplane you are dealing with. But I will explain some methods that I used with FBW A32NX.

Because FBW A32NX is a custom add on, you won’t find any information in MSFS2020 or SimConnect SDK. You need to look into the documentation of the creators of the add-on. Luckily, FBW A32NX is free and open source, which means that all information is available on the web.

Let’s give a few examples.

Example 1:

I want to read the value of altitude on the FCU (Flight Control Unit) of the A32NX.
image
In the FBW A32NX documentation there is a section for the FCU panel. If you scroll down to the “ALT knob”, you find that you can use the variable “AUTOPILOT ALTITUDE LOCK VAR:3”. This is an “MSFS VAR”, which in my terminology means a “native variable”. You will indeed also find this variable in the SDK Documentation here, where you can read that the value is given in “feet”, and that you can both read from and write to it.

In my implementation, this variable will be entered as “A:AUTOPILOT ALTITUDE LOCK VAR:3,feet,FLOAT64”. Don’t worry too much about the syntax I’m using, and the word FLOAT64. We will see that in some later chapters.

Example 2:

I want to control the 5 buttons on the EFIS (Electronic Flight Instrument System) panel of the A32NX.
image
In the FBW A32NX documentation there is a section for the EFIS control panel. If you scroll down to the “ND Filter”, you find that you can use the variable “A32NX_EFIS_L_OPTION” and “A32NX_EFIS_R_OPTION”. These are “Custom LVAR”, which in my terminology means “custom variables”. You won’t find these in the SDK Documentation. The variable is “R/W” and can take 6 values: 0=none, 1=CSTR, 2=VOR, 3=WPT, 4=NDB, 5=ARPT.

In my implementation, this variable will be entered as “L:A32NX_EFIS_L_OPTION,enum” and “L:A32NX_EFIS_R_OPTION,enum”.

Some more ways to find variables

1. The behaviors window

If you have enabled “Developer Mode” in MSFS2020 (which you probably have to install the SimConnect SDK), then you can also use the “Behaviors” window:

image

This is (at least for me :laughing:) a very complex tool, but it can help revealing some last pieces of the puzzle in finding the correct variables. Hover over a button until it gets the blue focus:

image

Now press “CTRL-G” while the behaviors window is open. The behaviors window will now show a lot of information for the control you selected. I have no clue about most of the information presented here, but if you open a few of the entries, you might find some hints on what variables to use.

Edit 06DEC2022: For some reason, the CTRL-G trick seems not to work anymore. I still haven’t found a way to get it working again. Maybe this feature is depreciated (but I wouldn’t know why Asobo would do that). Or I must be doing something wrong after several MSFS updated? If somebody knows, please send me a PM. Thanks!

image

The above shows again the usage of variable “L:A32NX_EFIS_L_OPTION, enum”, which is the one we showed before. The code is written using RPN (Reverse Polish Notation) that is explained in the SDK Documentation. I’m not going in much more detail here, because it’s not really in the scope of this tutorial.

2. Some interesting websites

We are obviously not the only ones that are looking for variables. In an attempt to avoid to reinvent the wheel, some flightsim enthousiasts have created a website Hubhop that is consolidating the research of many people in finding the right variables. The information found on this website might be shown as “presets” which can be used by other tools like MobiFlight. But it does reveal some useful information as you can see in the below screenshot, where we again see the usage of the variable “L:A32NX_EFIS_L_OPTION” (and if you understand the RPN code, you will see that the preset is toggling the WPT button).

Just be careful with the information found on this website. Everybody can enter information in it, so it is good practice to double check the information. But it is still a great source!

Conclusion on variables

As you can see, it is not easy to find the correct variables. There is no simple method that will work in all cases, but will depend on what you are looking for, and whether you are dealing with an add-on or native MSFS2020. But with the tool that we are making in this tutorial, you will at least have the possibility to experiment by trying out several variables and see the results, until you find the correct ones that you can then use for your own project.

Goto Chapter 5: Variable housekeeping using object VarData

5 Likes