• 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.

HTML5 + JavaScript VarGet/VarSet or LUA

Messages
36
Country
yugoslavia
Hello guys.

As you know P3D v5.1 is now supporting HTML5 with JavaScript just like MSFS2020
I want to try to write and read value from some L var just like an example, but SDK doesn't help much
So below is basic HTML setup for gauge. Does anyone know syntax to use functions VarGet and VarSet inside of script tags?
For instance my variable is: L:TestVar,number

<!DOCTYPE html>
<html>
<body>


<h1>My First JavaScript</h1>

<p>JavaScript can change the content of an HTML element and variable value:</p>

<script>

</script>

</body>
</html>
 
Wouldn't reading the SDK provide the answer to your question? I mean.. I would think it would....
 
As I wrote...
SDK doesn't help much and that's why I come here... To find out what I do wrong...


Even copy/paste example code which reads "indicated altitude" with properly set panel.cfg doesn't work on my P3D v5.1


<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Indicated Altitude</h2>

<p id="altitude"></p>

<script>

function loop(timestamp)
{
var alt = VarGet("Indicated Altitude", "feet");

document.getElementById('altitude').innerHTML = alt;

window.requestAnimationFrame(loop);
}

window.requestAnimationFrame(loop);

</script>

</body>
</html>
 
EDS
Wouldn't reading the SDK provide the answer to your question? I mean.. I would think it would...
Not really Ed. VarSet seems not to work for L:Vars. I posted some questions on their forums
 
A quick read of the SDK tells me it isn't intended to support LVars. From the SDK:
The most familiar, as well as most useful, functions are VarGet and VarSet which allow the developer to access Prepar3D's parameters.
Doesn't say it supports LVars at all.

Inside their example:
Code:
var alt = VarGet("Indicated Altitude", "feet");
 
The whole idea of communication between modules/code units is broken if there is no L:VAR support. How can C code comunicate with the HTML?
I posted this on their forums and awaiting response.
 
Ok guys, little update!
There is a communication with Lvar, definitely I managed to do it! Using XML I set some value for my Lvar and then using function VarGet I printed it on HTML gauge using JavaScript! So communication is present.
However, I managed just to read value using VarGet function.
The problem why previous code didn't work is that HTML gauge didn't have a background so value of altitude was printed black and transparent. After setting up background color the value of indicated altitude was shown well.

Does anyone have idea how to use VarSet ? Here is my example, but didn't work... always printing 0 value.

HTML:
<!DOCTYPE html>
<html>
<body style="background-color:powderblue;">

<h2>JavaScript Variables</h2>

<p>Set/Read a variable and display it:</p>

<p id="value"></p>

<script>
    function loop(timestamp)
    {
        
    VarSet("L:MyVar","number",5); // THIS IS NOT WORKING
        
        var value = VarGet("L:MyVar", "number");
        document.getElementById('value').innerHTML = value;

        window.requestAnimationFrame(loop);
        
    }

    window.requestAnimationFrame(loop);
</script>

</body>
</html>
 
Ok guys, little update!
There is a communication with Lvar, definitely I managed to do it! Using XML I set some value for my Lvar and then using function VarGet I printed it on HTML gauge using JavaScript! So communication is present.
However, I managed just to read value using VarGet function.
The problem why previous code didn't work is that HTML gauge didn't have a background so value of altitude was printed black and transparent. After setting up background color the value of indicated altitude was shown well.

Does anyone have idea how to use VarSet ? Here is my example, but didn't work... always printing 0 value.

HTML:
<!DOCTYPE html>
<html>
<body style="background-color:powderblue;">

<h2>JavaScript Variables</h2>

<p>Set/Read a variable and display it:</p>

<p id="value"></p>

<script>
    function loop(timestamp)
    {
       
    VarSet("L:MyVar","number",5); // THIS IS NOT WORKING
       
        var value = VarGet("L:MyVar", "number");
        document.getElementById('value').innerHTML = value;

        window.requestAnimationFrame(loop);
       
    }

    window.requestAnimationFrame(loop);
</script>

</body>
</html>
I dont think it is possible, for some reason. Regards, Federico
 
Feel free to tell them all about it. :)
I did.
I also asked for varset to local variable and suggested they allow this new HTML5 thing for the Kneeboard in the future.
It would allow for perfect interactive checklist.

Gérard
 
Back
Top