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 are all listed below.

Units

Functions

FunctionDescription
fsVarsGetUnitIdGet 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

FunctionDescription
fsVarsGetAVarIdGet the ID of a specific AVar.
fsVarsAVarGetGet the value of a specific AVar.
fsVarsAVarSetSet the value of a specific AVar.
fsVarsAVarXYZGetGet the value of a specific AVar (stored as a three-dimensional vector).
fsVarsAVarXYZSetSet the value of a specific AVar (stored as a three-dimensional vector).
fsVarsAVarBufferGetGet the value of a specific AVar (stored in a buffer).
fsVarsAVarBufferSetSet 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

FunctionDescription
fsVarsGetBVarIdGet the ID of a specific BVar.
fsVarsBVarGetGet the value of a specific BVar.
fsVarsBVarStringGetGet the value of a specific BVar (stored as a string).
fsVarsBVarCallCall the preset associated with a specific BVar.

Types

FsBVarId

The ID of a BVar.

typedef int FsBVarId;

EVar

EVar are environment variables (see Environment Variables for more information).

Functions

FunctionDescription
fsVarsGetEVarIdGet the ID of a specific EVar.
fsVarsEVarGetGet 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

FunctionDescription
fsVarsGetLVarIdGet the ID of an existing LVar.
fsVarsRegisterLVarGet the ID of a specific LVar - if it exists - else create the LVar.
fsVarsGetLVarNameGet the name of a specific LVar.
fsVarsLVarGetGet the value of a specific LVar.
fsVarsLVarSetSet the value of a specific LVar.

Types

FsLVarId

The ID of an 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

FunctionDescription
fsVarsGetIVarIdGet the ID of an existing IVar.
fsVarsRegisterIVarGet the ID of a specific IVar - if it exists - else create the IVar.
fsVarsIVarGetGet the value of a specific IVar.
fsVarsIVarSetSet 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

FunctionDescription
fsVarsGetOVarIdGet the ID of an existing OVar.
fsVarsRegisterOVarGet the ID of a specific OVar - if it exists - else create the OVar.
fsVarsOVarGetGet the value of a specific OVar.
fsVarsOVarSetSet 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

ZVar can also be referenced as L:1 variables.

Functions

FunctionDescription
fsVarsGetZVarIdGet the ID of an existing ZVar.
fsVarsRegisterZVarGet the ID of a specific ZVar - if it exists - else create the ZVar.
fsVarsZVarGetGet the value of a specific ZVar.
fsVarsZVarSetSet the value of a specific ZVar.

Types

FsZVarId

The ID of a 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

FunctionDescription
fsVarsRegisterVarsStatusUpdateHandlerRegister a function to be notified when the status of a variable is changed (i.e. deleted or reset).
fsVarsUnregisterVarsStatusUpdateHandlerUnregister a previously registered handler with fsVarsRegisterVarsStatusUpdateHandler.
fsVarsUnregisterAllVarsStatusUpdateHandlerUnregister 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,
};

Constants

ConstantValueDescription
FS_VAR_INVALID_ID-1Returned by the functions that get or register an IVar, LVar, OVar, ZVar or BVar ID when the variable could not be found or created.
FS_VAR_AVAR_NONE0Returned by fsVarsGetAVarId when the AVar could not be found.
FS_VAR_EVAR_NONE0Returned by fsVarsGetEVarId when the EVar could not be found.
FS_INVALID_UNIT-1Returned by fsVarsGetUnitId when the unit could not be found.

FsVarError

With the Vars API, a function can return an error code from the FsVarError enum:

Error CodeDescription
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_ERROR_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:

FunctionDescription
fsVarsGetAircraftVarIdGet the ID of a specific SimVar.
fsVarsAircraftVarGetGet the value of a specific SimVar.
fsVarsAircraftVarSetSet the value of a specific SimVar.
fsVarsRegisterNamedVarCreate a new NamedVar.
fsVarsGetRegisteredNamedVarIdGet the ID of a named variable.
fsVarsNamedVarGetGet the value of a specific NamedVar.
fsVarsNamedVarSetSet the value of a specific NamedVar.
fsVarsRegisterCustomSimVarCreate a new CustomSimVar.
fsVarsCustomSimVarGetGet the value of a specific CustomSimVar.
fsVarsCustomSimVarSetSet the value of a specific CustomSimVar.
fsVarsGetEnvironmentVarIdGet the ID of an environment variable.
fsVarsEnvironmentVarGetGet the value of a specific environment variable.

The following type definitions are used by the deprecated functions, and are therefore no longer useful:

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 an environment variable (EnvVar).

typedef int FsEnvVarId;

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:

0/255