plane icon Welcome to Microsoft Flight Simulator’s SDK Q&A Platform!

You have questions regarding the SDK? DevMode Tools? SimConnect? You would like to submit an idea for future improvements, seek help or exchange knowledge? You’re in the right place.


Please take a moment to read the platform’s guidelines before you get started!


question

Mr_LiamT avatar image
Mr_LiamT asked Mr_LiamT answered

How to display mission properties in a custom panel?

How can I get properties of mission objects to show on a custom panel? For example showing the CurrentTime of a TimerTrigger. Like how the HUD for the reno race shows the race time.


Maybe I can pass data trough a calculator variable (X:RacingTimer) and capture it with a listener?

missionhtml
10 |10000

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

1 Answer

Mr_LiamT avatar image
Mr_LiamT answered

You can use the javascript class 'FlightObject' to connect with calculators. Here is an example that connects with a calculator in the asobo taxi tutorial:

Javscript:

class CustomPanel extends UIElement {
    constructor() {
        super(...arguments);

        this.onFlightObjectReady = async () => {
            try {
                //Set the calculator guid and calculatorvalue
                this.m_CalculatorValue = new FlightObjectValue("{830EA1F0-B8A1-4EC9-9626-8E4782C6C067}", "Calculator.CurrentSubgoalIndex");

                let promises = [
                    this.m_CalculatorValue.UpdateValue()
                ];
                await Promise.all(promises);
                this.updatePanel();
            }
            catch (e) {
                console.log(e);
            }
        };

        //Every frame, the panel gets updated with the calculatorvalue
        this.updatePanel = async () => {
            requestAnimationFrame(this.updatePanel);
            await this.m_CalculatorValue.UpdateValue();
            const updatedValue = this.m_CalculatorValue.Value;
            this.m_TestDisplay.innerHTML = updatedValue;
        };
    }

    connectedCallback() {
        super.connectedCallback();

        //Calculator connect
        FlightObject.OnReady(this.onFlightObjectReady);

        //Connect JS to html <p>
        this.m_TestDisplay = this.querySelector("#TestDisplay");
    }

    initialize() {
    }

    disconnectedCallback() {
        super.disconnectedCallback();
    }

    updateImage() {
    }
}
// You can also import the javascript in the html
Include.addImports([
    "/JS/FlightObject.js",
], () => {
    window.customElements.define("custom-panel", CustomPanel);
});

checkAutoload();

HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="/SCSS/common.css" />

        <script type="text/javascript" src="/JS/coherent.js"></script>
        <script type="text/javascript" src="/JS/common.js"></script>
        <script type="text/javascript" src="/JS/dataStorage.js"></script>
        <script type="text/javascript" src="/JS/buttons.js"></script>
        <script type="text/javascript" src="/JS/simvar.js"></script>
        <script type="text/javascript" src="/JS/Services/ToolBarPanels.js"></script>

        <link rel="import" href="/templates/IconStack/IconStack.html" />
        <link rel="import" href="/templates/NewPushButton/NewPushButton.html" />
        <link rel="import" href="/templates/ToggleButton/toggleButton.html" />
        <link rel="import" href="/templates/tabMenu/tabMenu.html" />
        <link rel="import" href="/templates/ingameUi/ingameUi.html" />
        <link rel="import" href="/templates/ingameUiHeader/ingameUiHeader.html" />
        <link rel="import" href="/templates/NewListButton/NewListButton.html" />
        <link rel="import" href="/templates/StatePushButton/StatePushButton.html" />
        <link rel="import" href="/templates/virtualScroll/virtualScroll.html" />
        <link rel="import" href="/templates/InputableRange/InputableRange.html" />
        <script type="text/javascript" src="/JS/FlightObject.js"></script>

        <script type="text/javascript" src="CustomPanel.js"></script>
    </head>

    <body class="border-box">
        <custom-panel>
            <ingame-ui
                id="CustomPanel_Frame"
                panel-id=""
                class="ingameUiFrame panelInvisible condensedPanel"
                title=""
                content-fit="true"
                min-width="50"
                resize="x">
                <section id="MainDisplay" class="">
                    <h2>Current Subgoal Index:</h2>
                    <p id="TestDisplay">Wait for calculator</p>
                </section>
            </ingame-ui>
        </custom-panel>
    </body>
</html>


The FlightObjectValue object has two parts:

FlightObjectValue("{830EA1F0-B8A1-4EC9-9626-8E4782C6C067}", "Calculator.CurrentSubgoalIndex")

The first is the GUID of the calculator. And the second is the parameter you want to track. Standard are these:

Name in javascript
Meaning
"Object.Descr"
The <Descr> tag in the .xml
"Object.ClassName"

"Object.Activated"

"Calculator.dtime"
The frame-time
"Calculator.activated"

"Calculator.break"

"Calculator.result"
The result of the <CalculatorFormula> that is placed directly in the main <Calculator> Element.

To access the calculator's variables/parameters, you have to use the NameInFormula. If the NameInFormula is CurrentSubgoalIndex, you can track it using "Calculator.CurrentSubgoalIndex"

10 |10000

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.