• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

MSFS GetGameVarValue

As I was digging into the JavaScript code, I found call to the GetGameVarValue function, something like:

let cruiseMach = SimVar.GetGameVarValue("AIRCRAFT CRUISE MACH", "mach");

It looks similar to the well known GetSimVarValue, but I don't know the difference. And "AIRCRAFT CRUISE MACH" is not part of the sim vars, so what is it? Is it a specific variable created for this instrument? In that case, why not using an L: var that can be get/set with GetSimVarValue/SetSimVarValue?
Needless to say, not a single word about this in the SDK...

Any information is welcome :)

Thanks,
Eric
 
Well cruise_mach is set in flight_model.cfg under [REFERENCE SPEEDS] so I am guessing it lets you access .cfg variables. You'd have to test this to confirm as like you say, it's undocumented.

There's also

SimVar.GetGlobalVarValue("ZULU TIME", "seconds");

which looks like it is used for E: vars . Environment data which is mostly just time and date variables.

Another use of simvarvalue is using E: or L: to get variables that are not A: vars. I include this only for reference in case someone doesn't know it yet.

SimVar.GetSimVarValue("E:ABSOLUTE TIME", "seconds");

Notice how A: vars do not need have the A: prefix when using GetSimVarValue

SimVar.GetSimVarValue("ELECTRICAL MAIN BUS VOLTAGE", "volts");

I imagine you could use GetGlobalVarValue to get absolute time as it is an E: var but the M803 clock js uses both examples so, yeah, consistency eh?
 
Any information is welcome :)
Maybe content of simvars.js and TestSimVar.js files that lives inside C:\PROGRAM FILES\WINDOWSAPPS\MICROSOFT.FLIGHTSIMULATOR_1.15.8.0_X64__8WEKYB3D8BBWE\Packages\fs-base-ui\html_ui\JS will help you.
As I can understand, that simvar, globalvar, gamevar are parts of window and have some methods to get values of different types (look at GetSimVarValue implementation) and all except globalvar can be set values using Coherent.call("setValue_Number", ...). The function setValue_Number is like a callback that implemented in C++ and binded with CoherentGT using BindCall so C++ code can work with JavaScript like in that sample.
Never mind, I may be wrong, cause know nothing.
 
Last edited:
Well cruise_mach is set in flight_model.cfg under [REFERENCE SPEEDS] so I am guessing it lets you access .cfg variables. You'd have to test this to confirm as like you say, it's undocumented.

There's also

SimVar.GetGlobalVarValue("ZULU TIME", "seconds");

which looks like it is used for E: vars . Environment data which is mostly just time and date variables.

Another use of simvarvalue is using E: or L: to get variables that are not A: vars. I include this only for reference in case someone doesn't know it yet.

SimVar.GetSimVarValue("E:ABSOLUTE TIME", "seconds");

Notice how A: vars do not need have the A: prefix when using GetSimVarValue

SimVar.GetSimVarValue("ELECTRICAL MAIN BUS VOLTAGE", "volts");

I imagine you could use GetGlobalVarValue to get absolute time as it is an E: var but the M803 clock js uses both examples so, yeah, consistency eh?
Yes, you're probably right, I also saw GetGameVarValue used to read the crossover speed, which is also defined in a cfg. Now I wonder what SetGameVarValue does, maybe it writes information in a file, that would be interesting too.
Thanks for letting me know about GetGlobalVarValue, I didn't know this so I was using SimVar.GetSimVarValue("E:ABSOLUTE TIME", "seconds"); to read time. If it is the same, I am sure we should use GetGlobalVarValue instead, which is the "modern" way of reading variables.

Thanks for your answer.
 
Maybe content of simvars.js and TestSimVar.js files that lives inside C:\PROGRAM FILES\WINDOWSAPPS\MICROSOFT.FLIGHTSIMULATOR_1.15.8.0_X64__8WEKYB3D8BBWE\Packages\fs-base-ui\html_ui\JS will help you.
As I can understand, that simvar, globalvar, gamevar are parts of window and have some methods to get values of different types (look at GetSimVarValue implementation) and all except globalvar can be set values using Coherent.call("setValue_Number", ...). The function setValue_Number is like a callback that implemented in C++ and binded with CoherentGT using BindCall so C++ code can work with JavaScript like in that sample.
Never mind, I may be wrong, cause know nothing.
Thanks for this info, I will look closely into the implementation of these function. I also thank you for your explanations about Coherent.call because I was also wondering what it was.
I saw it used like this:
Coherent.call("AP_SPD_VAR_SET", 1, knots);
I will have to find out what the 2nd parameter is, but I'm happy to know it is designed to call C++ code. I had a quick look at your sample that explains communication between JavaScript and C++, but in the specific case of MSFS, I guess it is used only to communicate with existing C++ code developed by Asobo. Or can we also use this to communicate between JS and WASM?

Thanks,
Eric
 
Prepare3DGuy nailed it.

One advantage of GetGameVarValue() is that it returns values of any JS data type, where 'FSX' simvars weren't originally designed for this. Asobo has used this to provide values that can be read from the aircraft config files, and some new vars that weren't available in FSX.

Further to Prepare3DGuy's comments, fs-base-ui/html/JS/SimPlane.js (which provide the 'Simplane' interface used in many Asobo gauges) makes extensive use of GetGameVarValue to return sim values.
e.g.
Code:
    function getStallSpeed() {
        return SimVar.GetGameVarValue("AIRCRAFT STALL SPEED", "knots");
    }
    Simplane.getStallSpeed = getStallSpeed;

If I was to guess, I think Asobo have the Simplane.XXX methods as a more 'strategic' way of getting sim data into html/js gauges, as they're using them to access existing 'traditional' FSX simvars, e.g. using Simplane.getWindDirection() rather than SimVar.GetSimVarValue("AMBIENT WIND DIRECTION"...) in their gauges. in some cases the Simplane function isn't a simple 1:1 mapping to a simvar.

Code:
    function getWindDirection() {
        var angle = SimVar.GetSimVarValue("AMBIENT WIND DIRECTION", "Degrees");
        return angle;
    }
    Simplane.getWindDirection = getWindDirection;

Here's a straight 'grep' of the references to GetGameVarValue() in SimPlane.js:
Code:
        speeds.VS0 = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VS0", "knots");
        speeds.VS1 = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VS1", "knots");
        speeds.VFe = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VFE", "knots");
        speeds.VNe = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VNE", "knots");
        speeds.VNo = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VNO", "knots");
        speeds.VMin = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VMIN", "knots");
        speeds.VMax = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VMAX", "knots");
        speeds.Vr = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VR", "knots");
        speeds.Vx = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VX", "knots");
        speeds.Vy = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VY", "knots");
        speeds.Vapp = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VAPP", "knots");
        speeds.BestGlide = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED BEST GLIDE", "knots");
        return SimVar.GetGameVarValue("AIRCRAFT GREEN DOT SPEED", "Knots");
            return SimVar.GetGameVarValue("AIRCRAFT CROSSOVER SPEED FACTOR", "Number", _cas, _mach);
        let maxSpeed = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VNO", "knots");
            let limit = SimVar.GetGameVarValue("AIRCRAFT FLAPS SPEED LIMIT", "Knots", _flapIndex);
        let maxSpeed = SimVar.GetGameVarValue("AIRCRAFT DESIGN SPEED VNO", "knots");
            let gearSpeed = SimVar.GetGameVarValue("AIRCRAFT MAX GEAR EXTENDED", "knots");
        return SimVar.GetGameVarValue("AIRCRAFT LOWEST SELECTABLE SPEED", "knots");
        return SimVar.GetGameVarValue("AIRCRAFT STALL PROTECTION SPEED MIN", "knots");
        return SimVar.GetGameVarValue("AIRCRAFT STALL PROTECTION SPEED MAX", "knots");
        return SimVar.GetGameVarValue("AIRCRAFT STALL SPEED", "knots");
        return SimVar.GetGameVarValue("AIRCRAFT STALL SPEED PREDICTED", "knots", _flapIndex);
        return SimVar.GetGameVarValue("AIRCRAFT AUTOPILOT AVAILABLE", "Bool");
        var usePropRpm = SimVar.GetGameVarValue("AIRCRAFT USE PROPELLER RPM", "bool");
            var maxHP = SimVar.GetGameVarValue("AIRCRAFT MAX RATED HP", "ft lb per second") / 550;
        return SimVar.GetGameVarValue("AIRCRAFT MIN CRUISE RPM", "rpm");
        return SimVar.GetGameVarValue("AIRCRAFT MAX CRUISE RPM", "rpm");
        return SimVar.GetGameVarValue("AIRCRAFT MAX INDICATED RPM", "rpm");
        return SimVar.GetGameVarValue("AIRCRAFT MAX RATED RPM", "rpm");
        var type = SimVar.GetGameVarValue("AIRCRAFT PROPELLER TYPE", "Enum");
        var type = SimVar.GetGameVarValue("AIRCRAFT NB PROPELLERS", "Enum");
        return SimVar.GetGameVarValue("AIRCRAFT AOA ANGLE", _unit);
        return SimVar.GetGameVarValue("AIRCRAFT ORIENTATION AXIS", "XYZ");
        return SimVar.GetGameVarValue("AIRCRAFT CROSSOVER ALTITUDE", "feet", _cas, _mach);
        return SimVar.GetGameVarValue("AIRCRAFT FLAPS HANDLE ANGLE", "Degree", _flapIndex);
        if (SimVar.GetGameVarValue("AIRCRAFT ELEVATOR TRIM LIMIT", "number") > 0)
        return SimVar.GetGameVarValue("AIRCRAFT ELEVATOR TRIM NEUTRAL", "percent over 100");
        return SimVar.GetGameVarValue("AIRCRAFT HAS GLASSCOCKPIT", "boolean");
        return SimVar.GetGameVarValue("GAME UNIT IS METRIC", "boolean");
 
Thanks for your good explanations.
What I read here is that SimPlane not only returns constant values defined in the cfg files, it also returns variables that vary according to the aircraft configuration. For example, the stall speed and green dot speed are in that case. It means we can get fixed values like max_mach, which never changes, and variable values that change according to the flight.
Do you confirm my understanding?

Thanks,
Eric
 
Thanks for your good explanations.
What I read here is that SimPlane not only returns constant values defined in the cfg files, it also returns variables that vary according to the aircraft configuration. For example, the stall speed and green dot speed are in that case. It means we can get fixed values like max_mach, which never changes, and variable values that change according to the flight.
Do you confirm my understanding?

Thanks,
Eric
yes, that is essentially correct, :

So we have

SimVar.GetSimVarValue("FSX var name"...) - returns 'traditional' single-value results, e.g. airspeed.

SimVar.GetGameVarValue("var name"...) - can return new data values which may be read from config files, OR new values generated live in the sim, and may be more 'composite' JS values.

Simplane.<function call> - calls either of the above, returning JS values of any type, plus may have additional code in the implementation to improve the functionality without 'breaking' the underlying simvars.

An example is Simplane.getOrientationAxis() which returns { "pitch": .., "bank": .., "yaw": ..} (from memory - "yaw" name might be wrong)

Another example Simplane.getIsGrounded() which has a lot more code in it than simply looking at the "SIM ON GROUND" 'FSX' simvar (in fact it doesn't use that at all).

The Asobo gauges extensively use Simplane calls and I'm guessing that means they can extend the 'Simplane' interface while leaving the FSX simvars 'frozen'. I think people locked into C++ WASM gauge development have limited experience of what is going on with the Asobo html/js gauge developments but html/js seems more likely to be the strategic direction.
 
Top