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!


For HUDs issues management, please read the article here !

question

CaptMatto avatar image
CaptMatto asked CaptMatto answered

Setting ELECTRICAL MASTER BATTERY:1 to on via js

Hi

I have a blank gauge I am using to set simvars from the dataStore. I so far have got it working and setting the fuel level, but my ulitmate aim to record the state of each of the switches and tanks in the G36 and save these, so when reloading the aircraft it's how you left it.

I am using the code as such

//load the left fuel tank from the dataStore or set full and record in dataStore
    var initLeftFuel = GetStoredData('G36XIP_LEFT_FUEL');
    if (initLeftFuel) {
      SimVar.SetSimVarValue("FUEL TANK LEFT MAIN QUANTITY", "number", Number(initLeftFuel));
    } else {
      SimVar.SetSimVarValue("FUEL TANK LEFT MAIN QUANTITY", "number", 40);
      SetStoredData('G36XIP_LEFT_FUEL', '40');
    }


    //load the right fuel tank from the dataStore or set full and record in dataStore
    var initRightFuel = GetStoredData('G36XIP_RIGHT_FUEL');
    if (initRightFuel) {
      SimVar.SetSimVarValue("FUEL TANK RIGHT MAIN QUANTITY", "number", Number(initRightFuel));
    } else {
      SimVar.SetSimVarValue("FUEL TANK RIGHT MAIN QUANTITY", "number", 40);
      SetStoredData('G36XIP_RIGHT_FUEL', '40');
    }

I'm now trying to set the battery master switch ELECTRICAL MASTER BATTERY:1 via

SimVar.SetSimVarValue("ELECTRICAL MASTER BATTERY:1", "number", 1);

or

SimVar.SetSimVarValue("ELECTRICAL MASTER BATTERY:1", "bool", true);

but this doesn't work. In the SDK it shows it as being settable

ELECTRICAL MASTER BATTERY The battery switch position, true if the switch is ON. Use a battery index when referencing. Bool TYPE_BOOL Y -

the documents also mention electrical keys and I wonder if this is where I am going wrong? There is a key listed as

KEY_TOGGLE_MASTER_BATTERY battery index Toggle battery switch state


Do I need to set this as well?


UPDATE: I've just used the simvarwatcher and I can set (and turn on) the master battery switch via setting the simvar.

I'm running my code in the connectedCallback function. I wonder if I am being over-written before the aircraft loads? Is there a command to check if everything is loaded?

gauges
10 |10000 characters needed characters left characters exceeded

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

1 Answer

· Write an Answer
CaptMatto avatar image
CaptMatto answered

I was on the right track. My switch simvar was being over-written I put the code in onFlightStart() and it turned on the battery switch. As a test this works...

onFlightStart() {
    super.onFlightStart();
    SimVar.SetSimVarValue("ELECTRICAL MASTER BATTERY:1", "number", 1);
  }



10 |10000 characters needed characters left characters exceeded

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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