WASM lookup_var(...); vs. aircraft_varget(...)

it can’t just be me… The WASM SDK seems to include two almost identical but
different methods of reading the same MSFS simvar. Can anyone explain why I
would choose one over the other?

MODULE_VAR attitude_bank = { ATTITUDE_INDICATOR_BANK_DEGREES };
FLOAT64 fBank = lookup_var(&attitude;_bank);


struct sGaugeVars
{
    ENUM UNITS_DEGREES;
    ENUM VAR_BANK_DEG;
};
g_GaugeVars.VAR_BANK_DEG = get_aircraft_var_enum("ATTITUDE INDICATOR BANK DEGREES");
FLOAT64 fBank = aircraft_varget(g_GaugeVars.VAR_BANK_DEG, g_GaugeVars.UNITS_DEGREES, 0);

TBH I’ve somehow missed the point of “Token Variables”.

SDK says the lookup_var function updates the contents of a token variable. And
token variables are not the same as a simulation variables. lookup_var
https://docs.flightsimulator.com/html/Programming_Tools/WASM/Gauge_API/lookup_var.htm?rhhlterm=lookup_var&rhsearch;=lookup_var
token variables
https://docs.flightsimulator.com/html/Programming_Tools/WASM/Gauge_API/Token_Vars/Token_Variables.htm?rhhlterm=token%20variable&rhsearch;=token%20variable
Simulation variables
https://docs.flightsimulator.com/html/Programming_Tools/SimVars/Simulation_Variables.htm
SDK says the aircraft_varget function retrieves the value of an aircraft
simulation variable. And variables are not the same as a token variables.
aircraft_varget
https://docs.flightsimulator.com/html/Programming_Tools/WASM/Gauge_API/aircraft_varget.htm?rhhlterm=aircraft_varget&rhsearch;=aircraft_varget
Answer Either way one receives and the other updates for different types
of variables.

I might not have been clear enough in my question. I do understand completely
“lookup_var” and “aircraft_varget” are not the same (i.e. identical). The docs
often repeat that and it’s clear the names are different and the simple code
structure you use in a WASM gauge to receive e.g. the latitude of the user
aircraft on each update cycle is slightly different. But if a WASM gauge
developer wants to receive PLANE LATITUDE on each update cycle, what’s the
difference in choosing between using the two methods? Given a free choice is
one better e.g. for performance or is maybe the recommended method by Asobo so
adopting it now positions the developer better for future enhancements? If one
method is simply better for PLANE LATITUDE and the other is better for
SIMULATION TIME that would be an odd technical strategy. Currently the
latitude of the plane is obviously a common underlying value that can be
retrieved a variety of ways. It might be the token variables are the new
preferred approach for WASM gauges, but if so that would be useful to know,
rather than simply the methods are similar but different.

I have exactly the same question and nobody answered so I will add to this topic what I believe is the case.

I think the simple answer is that there are two APIs due to organic history. The gauges API and token variables predate Simulation Variables.

My assumption is that aircraft_varget is the correct API to use for all cases except when a specific token variable exists and a simulation variable doesn’t. I’ve never seen that case though, which means Token Variables are basically for backwards compatibility with legacy content.

To be honest, I would consider both functions to be more or less legacy and use SimConnect to access the simvars instead.

1 Like