VARS API
The Microsoft Flight Simulator 2024 Vars API allows you to manage simulation variables using WebAssembly. This API is designed to replace the features provided by the deprecated Gauge API. The functions available for this API all listed below.
Units
Functions
| Function | Description |
|---|---|
fsVarsGetUnitId |
Get the ID of a specific unit. |
Types
FsUnitId
The ID of a Unit used by variables.
typedef int FsUnitId;
AVar
AVar are the Simulation Variables. They allow you to get information about - and in some case, control - various things in the simulation.
Functions
| Function | Description |
|---|---|
fsVarsGetAVarId
|
Get the ID of a specific AVar. |
fsVarsAVarGet |
Get the value of a specific AVar. |
fsVarsAVarSet |
Set the value of a specific AVar. |
fsVarsAVarXYZGet |
Get the value of a specific AVar (stored as a three-dimensional vector). |
fsVarsAVarXYZSet |
Set the value of a specific AVar (stored as a three-dimensional vector). |
fsVarsAVarBufferGet |
Get the value of a specific AVar (stored in a buffer). |
fsVarsAVarBufferSet |
Set the value of a specific AVar (stored in a buffer). |
Types
FsAVarId
The ID of an AVar.
typedef int FsAVarId;
BVar
BVar are input event variables (see Input Event XML Properties for more information).
Functions
| Function | Description |
|---|---|
fsVarsGetBVarId |
Get the ID of a specific BVar. |
fsVarsBVarGet |
Get the value of a specific BVar. |
fsVarsBVarStringGet |
Get the value of a specific BVar (stored as a string). |
fsVarsBVarCall |
Call the preset associated with a specific BVar. |
Typedef
FsBVarId
The ID of a BVar.
typedef int FsBVarId;
EVar
EVar are environment variables (see Environment Variables for more information).
Functions
| Function | Description |
|---|---|
fsVarsGetEVarId |
Get the ID of a specific EVar. |
fsVarsEVarGet |
Get the value of a specific EVar. |
Types
FsEVarId
The ID of an EVar.
typedef int FsEVarId;
LVar
LVar are variables local to the currently running simulation. They are shared with all systems.
Functions
| Function | Description |
|---|---|
fsVarsGetLVarId |
Get the ID of an existing LVar. |
fsVarsRegisterLVar |
Get the ID of a specific LVar - if it exists - else create the LVar. |
fsVarsGetLVarName |
Get the name of a specific LVar. |
fsVarsLVarGet |
Get the value of a specific LVar. |
fsVarsLVarSet |
Set the value of a specific LVar. |
Types
FsLVarId
The ID of a LVar.
typedef int FsLVarId;
IVar
IVar are instrument variables. They are local to an instrument of a SimObject, and are accessible to all the components of the instrument's hierarchy.
Functions
| Function | Description |
|---|---|
Get the ID of an existing IVar. |
|
fsVarsRegisterIVar |
Get the ID of a specific IVar - if it exists - else create the IVar. |
fsVarsIVarGet |
Get the value of a specific IVar. |
fsVarsIVarSet |
Set the value of a specific IVar. |
Types
FsIVarId
The ID of an IVar.
typedef int FsIVarId;
OVar
OVar are component variables, which are variables local to a component within a simObject.
Functions
| Function | Description |
|---|---|
Get the ID of an existing OVar. |
|
fsVarsRegisterOVar |
Get the ID of a specific OVar - if it exists - else create the OVar. |
fsVarsOVarGet |
Get the value of a specific OVar. |
fsVarsOVarSet |
Set the value of a specific OVar. |
Types
FsOVarId
The ID of an OVar.
typedef int FsOVarId;
ZVar
ZVar are variables local to a SimObject. They are accessible on all instruments and components of the SimObject
NOTE: OVar can also be referenced as L:1 variables.
Functions
| Function | Description |
|---|---|
Get the ID of an existing ZVar. |
|
fsVarsRegisterZVar |
Get the ID of a specific ZVar - if it exists - else create the ZVar. |
fsVarsZVarGet |
Get the value of a specific ZVar. |
fsVarsZVarSet |
Set the value of a specific ZVar. |
Types
FsZVarId
The ID of an ZVar.
typedef int FsZVarId;
Vars Status Update
The simulation can update all the variables of a certain type - for example to reset all the values, or to remove IDs. When using some WebAssembly modules, it can be important to take this into account.
Functions
| Function | Description |
|---|---|
fsVarsRegisterVarsStatusUpdateHandler |
Register a function to be notified when the status of a variable is changed (ie: deleted or reset). |
fsVarsUnregisterVarsStatusUpdateHandler |
Unregister a previously registered handler with fsVarsRegisterVarsStatusUpdateHandler |
fsVarsUnregisterAllVarsStatusUpdateHandler |
Unregister all previously registered handlers with fsVarsRegisterVarsStatusUpdateHandler |
Types
eFsVarTypeFlag and FsVarTypeFlags
Flags representing one or more types of variables.
enum eFsVarTypeFlag : unsigned int
{
FS_VAR_TYPE_AVAR = 1 << 0,
FS_VAR_TYPE_BVAR = 1 << 1,
FS_VAR_TYPE_EVAR = 1 << 4,
FS_VAR_TYPE_IVAR = 1 << 8,
FS_VAR_TYPE_LVAR = 1 << 11,
FS_VAR_TYPE_OVAR = 1 << 14,
FS_VAR_TYPE_ZVAR = 1 << 25,
};
typedef unsigned int FsVarTypeFlags;
FsVarUpdateOp
Enum containing the different operations that fsVarsRegisterVarsStatusUpdateHandler can receive.
enum FsVarUpdateOp : unsigned char
{
FS_VAR_UPDATE_OP_UNKNOWN,
FS_VAR_UPDATE_OP_REMOVE,
FS_VAR_UPDATE_OP_RESET,
};
FsVarError
With the Vars API, a function can return an error code from the FsVarError enum:
| Error Code | Description |
|---|---|
FS_VAR_ERROR_NONE (0) |
No error occurred during the function execution. |
FS_VAR_ERROR_FAIL (0xFFFFFFFF) |
Something went wrong during the execution, but the reasons are unknown. |
FS_VAR_ERROR_BAD_DATA (0x2) |
Arguments are correct, but the data contained within caused an error during execution. |
FS_VAR_NOT_SUPPORTED (0x3) |
The operation is not supported with the given arguments. |
FS_VAR_ERROR_INVALID_ARGS (0x4) |
One or more given arguments are invalid. |
FS_VAR_ERROR_ALREADY_REGISTER (0x5) |
One or more arguments given to the register function have already been registered and must be unique. |
FS_VAR_ERROR_NOT_REGISTER (0x6) |
The arguments given don't correspond to a registered object. |
Deprecated Functions And Type Definitions
The following functions are deprecated:
| Function | Description |
|---|---|
fsVarsGetAircraftVarId |
Get the ID of a specific SimVar. |
fsVarsAircraftVarGet |
Get the value of a specific SimVar. |
fsVarsAircraftVarSet |
Set the value of a specific SimVar. |
fsVarsRegisterNamedVar |
Create a new NamedVar. |
fsVarsGetRegisteredNamedVarId |
Get the ID of a named variable |
fsVarsNamedVarGet |
Get the value of a specific NamedVar. |
fsVarsNamedVarSet |
Set the value of a specific NamedVar. |
fsVarsRegisterCustomSimVar |
Create a new CustomSimVar. |
fsVarsCustomSimdVarGet |
Get the value of a specific CustomSimVar. |
fsVarsCustomSimVarSet |
Set the value of a specific CustomSimVar. |
fsVarsGetEnvironmentVarId |
Get the ID of an environment variable. |
fsVarsEnvironmentVarGet |
Get the value of a specific environment variable. |
The following type definitions are used by deprecated functions, and are therefor not useful anymore:
FsSimVarId
The ID of a SimVar.
typedef int FsSimVarId;
FsNamedVarId
The ID of a named variable (or L:Var).
typedef int FsNamedVarId;
FsCustomSimVarId
The ID of a custom SimVar. It regroups O, I and L variables.
typedef int FsCustomSimVarId;
eFsSimCustomSimVarScope
Defines the scope of a custom SimVar, where:
enum eFsSimCustomSimVarScope : unsigned char
{
FsSimCustomSimVarScopeSim,
FsSimCustomSimVarScopeComponent,
FsSimCustomSimVarScopeHierarchy
};
FsSimCustomSimVarScopeSim: the Custom SimVar is local to the SimObject.FsSimCustomSimVarScopeComponent: the Custom SimVar is local to a component.FsSimCustomSimVarScopeHierarchy: the Custom SimVar is local to a component and its hierarchy.
FsEnvVarId
The ID of a EnvVar.
typedef int FsSimEnvId;
Sample
The modular WASMAircraft sample project has a preset that can be used as a reference when setting up the Vars API. You can find further details here:
Related Topics