L:vars
pkg/lvars writes local variables (L:vars) on the user aircraft through SimConnect (Windows only). An application uses it to signal other add-ons (the aircraft’s gauges, GSX, FSUIPC, an in-sim package) and to write the variables they document as settable.
An L:var exists once it is written: writing a new name creates it, and every other client reads it. Measured live in MSFS 2024: L:MYCREW_TEST written as 42 by one connection was read as 42 by another.
Writer
w := lvars.NewWriter(client, defBase, 0) // definitions defBase … defBase+63
if err := w.Set("MYCREW_BOARDING", 1); err != nil { // or "L:MYCREW_BOARDING"
log.Println(err)
}
_ = w.Set(gsx.SetPassengers, 111) // a GSX setting
// on a new connection:
w.Reset(newClient)
NewWriter(client, defBase, max):clientis anything withAddToDataDefinitionandSetDataOnSimObject(lvars.Client: anengine.Engineor the manager). Each name gets a data definition of its own, fromdefBasetodefBase+max-1;max0 meansDefaultMax(64). Keep that block clear of your other definition IDs.Set(name, value): writesvalue(afloat64, unitnumber) to the user aircraft. TheL:prefix is optional. The first write of a name defines it on this connection; oncemaxnames are defined, a new name returns an error.Reset(client): forgets the definitions, since a new connection has none; a non-nilclientreplaces the old one. Call it on every reconnect.
A Writer is safe for concurrent use.
Reading
pkg/lvars only writes. To read L:vars, list them in an aircraft profile of pkg/systems (its values land in State.Values by name); GSX’s own are read by pkg/gsx.
See also
- GSX and L:vars: the GSX variables add-ons may write.
- Aircraft Systems Profiles: per-model L:vars, such as the Fenix’s.