PROGRAMMING APIs
The Microsoft Flight Simulator SDK gives you a great deal of flexibility when creating add-ons for the sim, starting with the tools available to you in Developer Mode and then going though all the different CFG and XML files that you can tweak and edit to create great content! However, sometimes you need even more control or depth to create that perfect add-on, which is where the programming tools available to you through the SDK come into play.
In this section we have information for those of you that have either created add-ons for previous versions of the flight sim, or that have experience programming, in particular using C#, C++ or JavaScript. The tools listed below permit you to have a more direct interaction with Microsoft Flight Simulator:
SimVars And Keys
When creating add-ons for aircraft - primarily Instruments - you will need to be able to access Simulation Variables and change them based on user input in the form of Key Events. Both using SimVar values and using input key events is done using operations written in RPN, as explained below. Note that you can also find many use-cases and examples in the different ModelBehavior templates.
SimVars
SimVars permit you to get the state of a component, or the state of something in the simulation, and they are generally accesed using the following RPN format:
(A:[simvar_name]:[simvar_index], [units])
Note that the "index" value is only required by a few SimVars. Here are some simple examples:
(A:SIM ON GROUND, Bool)
(A:AIRSPEED TRUE, Knots)
(A:TURB ENG IGNITION SWITCH EX1:1, Enum)
Sometimes a SimVar will require two additional index values, for example the SimVar CIRCUIT CONNECTION ON
requires a circuit index and a bus index. Normally this would be written like this:
2 (>A:BUS LOOKUP INDEX, Number) (A:CIRCUIT CONNECTION ON:45, Bool)
However, some SimVars will permit an alterative "shorthand" method of using the two indices, like this:
2 (A:1:CIRCUIT CONNECTION ON:45, Bool)
Here, the 1:
after the A:
is used to tell the sim to send the top value on the stack to the SimVar. This shorthand method is ONLY applicable to the following SimVars:
BUS CONNECTION ON
BATTERY CONNECTION ON
ALTERNATOR CONNECTION ON
CIRCUIT CONNECTION ON
EXTERNAL POWER CONNECTION ON
BUS BREAKER PULLED
BATTERY BREAKER PULLED
ALTERNATOR BREAKER PULLED
CIRCUIT BREAKER PULLED
EXTERNAL POWER BREAKER PULLED
Finally it should be noted that sometimes you will see simulation variables written using snake case, and prefixed with SIMVAR_
, as that is how they appear in the simulation code itself. However when using them in RPN, you should omit the SIMVAR
part as well as the _
. For example:
SIMVAR_CIRCUIT_ON -> (A:CIRCUIT ON:1, Bool)
Keys
Key events permit you to change the state of a component or other aspect of the simulation based on some form of input. When checking for a key event, you would use the following RPN format:
[0] (>K:[key_event_name])
[1] [0] (>K:2:[key_event_name])
There are two formats showing for accessing key events because many of them require not just one but two parameters, and so the formatting above shows how this is achieved. Below are two "real world" examples, one with a single parameter and the other with 2 parameters:
1 (>K:TOGGLE_EXTERNAL_POWER)
50 1 (>K:2:PANEL_LIGHTS_POWER_SETTING_SET)
Environment Variables
You can access the following environment variables using the E:
identifier in RPN, and also through the SimConnect SDK. Note that most of these variables are all read-only and cannot be set unless otherwise specified:
Variable | Units | Description |
---|---|---|
ABSOLUTE TIME |
Seconds | This returns the seconds since 12:00 am 1/1/1AD Zulu Time See the Note On Zulu Time for more information. |
ZULU TIME |
Seconds | This returns the seconds since midnight (00:00 Zulu Time) on the current day. |
ZULU DAY OF WEEK |
Number | This returns the current Zulu Time day of the week as an integer value between 0 and 6 (inclusive), where 0 is Sunday and 6 is Saturday. See the Note On Zulu Time for more information. |
ZULU DAY OF MONTH |
Number | This returns the current Zulu Time day of the month as an integer value between 1 and 31 (inclusive). See the Note On Zulu Time for more information. |
ZULU MONTH OF YEAR |
Number | This returns the current Zulu Time month of the year as an integer value between 1 and 12 (inclusive), where 1 is January and 12 is December. See the Note On Zulu Time for more information. |
ZULU DAY OF YEAR |
Number | This returns the current Zulu Time day of the year as an integer value between 0 and 365 (365 only on a leap year). See the Note On Zulu Time for more information. |
ZULU YEAR |
Number | This returns the current Zulu Time year as an integer value. See the Note On Zulu Time for more information. |
ZULU SUNRISE TIME |
Seconds | This returns the seconds since midnight until the sunrise based on Zulu Time. See the Note On Zulu Time for more information. |
ZULU SUNSET TIME |
Seconds | This returns the seconds since midnight until the sunset based on Zulu Time. See the Note On Zulu Time for more information. |
LOCAL TIME |
Seconds | This returns the seconds since midnight (00:00 local time) on the current day. |
LOCAL DAY OF WEEK |
Number | This returns the current day of the week as an integer value between 0 and 6 (inclusive), where 0 is Monday and 6 is Sunday, within the local time reference. |
LOCAL DAY OF MONTH |
Number | This returns the current day of the month as an integer value between 1 and 31 (inclusive), within the local time reference. |
LOCAL MONTH OF YEAR |
Number | This returns the current month of the year as an integer value between 1 and 12 (inclusive), where 1 is January and 12 is December, within the local time reference. |
LOCAL DAY OF YEAR |
Number | This returns the current day of the year as an integer value between 0 and 365 (365 only on a leap year), within the local time reference. |
LOCAL YEAR |
Number | This returns the current year (local time) as an integer value. |
TIME ZONE OFFSET |
Seconds | This returns the offset between the local time and Zulu Time. See the Note On Zulu Time for more information. |
TIME OF DAY |
Enum (Number) |
This will return an integer value representing the approximate time of day where:
|
TOOLTIP UNITS |
Enum (Number) |
This will return an integer value representing the current units used to display tooltip information, where:
|
UNITS OF MEASURE |
Enum (Number) |
This indicates the units used to express measurements and will return an integer value representing the following:
|
SIMULATION RATE |
Number | This is used to get/set the internal rate of passing time within the simulation(independently of the visual frame rate). The value will be clamped between 0.0625 and 128, and a value of 1 means that 1 second of game time is the same as 1 second of "real" time, and lower values will make the game time slower, and higher values will make the game time faster. Values are always multiples of two starting at 0.0625, so you can have: 0.0625, 0.125, 0.25, 0.5, 1, 2, 4, ... 128 |
SIMULATION TIME |
Seconds | This returns a value for the seconds since the simulation has been started. |
SIMULATION DELTA TIME |
Number | This returns a value for the time passed between the last simulation frame and the current one. |
IS IN VR |
Boolean | This returns either 1 (TRUE) ir 0 (FALSE) to indicate whether the simulation is in VR mode or not. |
Note On Zulu Time
It should be be noted that Zulu Time is calculated off of the local time using a table of time-zones. For example, if the simulation is in a timezone that is +9 hours, then Zulu Time will be considered as current time - 9h.