Using Token Variables

Gauges have access to Flight Simulator simulation state information. You can access state information though tokenized variables. For a complete list of tokenized variables, see the topic Token Variables.

You can access tokenized variables in one of two different ways, either through drawing elements or the Panel API. The most common method used to access tokenized variables is through drawing elements. In the element structure, you can specify which variable controls the element. For example, you may have a needle (ELEMENT_NEEDLE) that is controlled by the variable VERTICAL_SPEED. As the needle is updated, it will refer to the variable VERTICAL_SPEED to determine the angle at which it will be displayed. For details, see the topic Using Drawing Elements. The other method of accessing tokenized variables is through the Panel API.

To access a tokenized variable through the Panel API

  1. Instantiate a MODULE_VAR variable initializing the GAUGE_TOKEN ID structure member.
    You can set the ID to one of the token variables listed in the topic Token Variables. For example:
    typedef structMODULE_VAR
    {
    GAUGE_TOKENid;
    PVOIDvar_ptr;
    VAR_TYPEvar_type;
    UNIVERSAL_VARvar_value;
    UNIVERSAL_VARvar_old;
    } MODULE_VAR, *PMODULE_VAR, **PPMODULE_VAR;

  2. Initialize the variable by calling the Panel API initialize_var( ).
    After you call initialize_var, the variable is ready to use. To update the contents of the variable from Flight Simulator 98 state information, use lookup_var( ). The following is the syntax for initialize_var and lookup_var( ), respectively:
    initialize_var(PMODULE_VAR module_var)
    lookup_var(PMODULE_VAR module_var )

After the lookup_var( ) function is called, the value of a MODULE_VAR variable is stored in the var_value member of the structure.

Important: Module Variables are read-only. Any attempt to set simulation variables through the var_ptr variable may result in program crashes and incompatibility with future versions of Flight Simulator.

The following code example shows how the MODULE_VAR variable is used:

MODULE_VARgs_var = {VOR1_GS_FLAG};

void install_routine(HINSTANCE resource_file_handle)

{

initialize_var(&gs_var);

'Insert other initialization code.

}

voidupdate_routine()

{

lookup_var(&gs_var);

if(gs_var.var_value.n == 0)

{

HIDE_IMAGE((&gs_slider));

HIDE_IMAGE((&gs_background));

}

else

{

SHOW_IMAGE((&gs_slider));

SHOW_IMAGE((&gs_background));

}

'Insert other code to update drawing elements.

}

The following code example shows how the UNIVERSAL_VAR variable is used.

typedef unionUNIVERSAL_VAR {

FLOAT64n;'You can use any number.

BOOLb;// any boolean

ENUMe;// any enumerated value

FLAGSf;// any flags field

PVOIDp;// any pointer

VAR32d;// any binary coded decimal

VAR32o;// any binary coded octal

} UNIVERSAL_VAR, *PUNIVERSAL_VAR, **PPUNIVERSAL_VAR;

For table of available module variables, see the topic Token Variables. The table lists the module variable name and description and specifies which UNIVERSAL_VAR union member to use with each variable.