• 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 Aircraft Persistence

Messages
20
Country
unitedkingdom
Hey All

One of my goals for our G36 Improvement Project is in bringing aircraft persistence to the mod.

I've been reading across all the forums that using DataStore is the way to go - both FBW & WT are using very similar code to make this happen.

What I can't seem to fathom is how to pull it together and make it work for our mod. Is there anyone here that may be able to give me some pointers? (or even joining our team to help with this? ;-) )

It looks like in the FBW they have html_ui/pages/A32nx_utils/nxdatastore.js but how is this loaded? I have written some code that is similar to both FBW & WT's but not sure if it's loading in the sim or not?
 
Messages
1,185
Country
canada
You need to add to your project xml - what's called a copy asset.

an example for html_ui is:

<AssetGroup Name="HtmlGauges">
<Type>Copy</Type>
<Flags>
<FSXCompatibility>false</FSXCompatibility>
</Flags>
<AssetDir>PackageSources\html_ui\</AssetDir>
<OutputDir>html_ui\</OutputDir>
</AssetGroup>

this goes in the assetgroup area like simobjects
Now you need to structure your folders and NOT be like ASOBO or any other company like FBW or WT.

so html_ui\my_company\pages\VCockpit\instruments\my_new_system

is a possible.

Then all your js code and panel.xml and panel.cfg code need to reflect your folder structure.

DA40CGDFQ_October 2, 2021_03.png


For a real complicated one download the garmin NGx and see if you follow what WT did.
 
Messages
20
Country
unitedkingdom
Thanks for your reply!

Ok, that makes sense, however in our mod we're not making a new aircraft, we're modifying the existing G36 by loading our mod files in the community directory. Would we need to create a new plane???

Or have I just lost the plot entirely?

UPDATE: Ok so I built the sample aircraft project in the SDK samples and included the copy asset. Looking at the built project it looks like the html_ui part is only loaded through layout.json? So I am assuming I can just create the folder structure mentioned by @ronh and load it via layout.json in our existing mod...
 
Last edited:
Messages
1,185
Country
canada
Ah yes sorry forgot a mod is a bit different. do you manually make a separate folder for the g36. How do you add a mod? You would use the same folder structure and put it in the community folder under your mod folder name, I would assume you use the same G36 simobject , so the html_UI will still be at the same level as sim object like I showed in the pic.
 
Messages
1,185
Country
canada
Ok reviewed the FBW A23nx - all js files have to be loaded from an html file, so you need to modify the G36 html file to load that js. The A32nx is a beast unto it's own. There and all sorts of build routines to rebuild the A320

add a line like
<script type="text/html" import-script="/Pages/A32NX_Utils/NXDataStore.js"></script>

However this is for the FBW A32nx so you will have to make your own folder structure. CAUTION - you will mess things up if you just copy FBW code.

maybe you do
<script type="text/html" import-script="/Pages/G36Mod_Utils/NXDataStore.js"></script>

This js file may need other js files. You are now in a hunt for all the base classes of this file and add them the same.

Learn how to use the CoherentGT debugger, this will show you if things are loading.

There are only three html files in the G36 that you can add to. so maybe the PFD. Again you have to ensure you don't mess other aircraft that use the AS1000 PFD, so folder structure is key. A less complicated but still complicated is how WT did the G1000Nxi.

They took the AS1000 folder and redirected to WTG1000

DA40CGDFQ_October 2, 2021_07.png


EDIT:
Looking at your git development project, I see you have modelbehaviors with ASOBO code, you are modifying the ASOBO exterior.xml file for all people for ALL aircraft that download your G36 mod. That's how the VFS - Virtual file system works, last one in is the one they use. I suggest you change this so that if your G36 needs these changes you make your own exterior.xml and change the G36 exterior model.xml to load your update one. That would mean copying it to your G36X folder and make the change:

<--! Include ModelBehaviorFile="Asobo\Exterior.xml"/ -->
<Include ModelBehaviorFile="G36X\Exterior.xml"/>
 
Last edited:
Messages
20
Country
unitedkingdom
Ok reviewed the FBW A23nx - all js files have to be loaded from an html file, so you need to modify the G36 html file to load that js. The A32nx is a beast unto it's own. There and all sorts of build routines to rebuild the A320

add a line like
<script type="text/html" import-script="/Pages/A32NX_Utils/NXDataStore.js"></script>

However this is for the FBW A32nx so you will have to make your own folder structure. CAUTION - you will mess things up if you just copy FBW code.

maybe you do
<script type="text/html" import-script="/Pages/G36Mod_Utils/NXDataStore.js"></script>

This js file may need other js files. You are now in a hunt for all the base classes of this file and add them the same.

Learn how to use the CoherentGT debugger, this will show you if things are loading.

There are only three html files in the G36 that you can add to. so maybe the PFD. Again you have to ensure you don't mess other aircraft that use the AS1000 PFD, so folder structure is key. A less complicated but still complicated is how WT did the G1000Nxi.

They took the AS1000 folder and redirected to WTG1000

View attachment 77313

EDIT:
Looking at your git development project, I see you have modelbehaviors with ASOBO code, you are modifying the ASOBO exterior.xml file for all people for ALL aircraft that download your G36 mod. That's how the VFS - Virtual file system works, last one in is the one they use. I suggest you change this so that if your G36 needs these changes you make your own exterior.xml and change the G36 exterior model.xml to load your update one. That would mean copying it to your G36X folder and make the change:

<--! Include ModelBehaviorFile="Asobo\Exterior.xml"/ -->
<Include ModelBehaviorFile="G36X\Exterior.xml"/>


Thanks so much! And for spotting the exterior.xml! That had snuck back into the repo somehow during the testing. We had removed it a while ago.

I'll get reading on the CoherentGT debugger and trace some of the concepts that WT & FBW are using for saving states. All I really want to do is save fuel and switch position between flights for the time being.
 
Messages
20
Country
unitedkingdom
Ok, so hopefully I am on the right tack here. @ronh could I use your knowledge again?

So as I understand so far, to use the DataStore.js I need to use this in a glass cockpit gauge. The only gauges available in the G36 are the NXi.

I have added the folder structure to the G36 Improvement Project

1633370923243.png


In AS1000_PFD.html I have the following code (this loads the NXi PFD and then my own on top?

Code:
<script type="text/html" import-script="/Pages/VCockpit/Instruments/NavSystems/WTG1000/PFD/WTG1000_PFD.html"></script>
<script type="text/html" import-script="/Pages/VCockpit/Instruments/NavSystems/G36XG1000/PFD/G36XG1000_PFD.html"></script>

In G36XG1000_PFD.html I have the following code - which I am assuming loads before the NXi?

Code:
<script type="text/html" import-script="/JS/dataStorage.js"></script>
<script type="text/html" import-script="/JS/coherent.js"></script>
<script type="text/html" import-script="/Pages/VCockpit/Instruments/NavSystems/G36XG1000/PFD/G36X_Utils.js"></script>

G36X_Utils.js I have:

Code:
console.log('Hello World');
1 (&gt;L:XMLVAR_MJB_FUEL)

I can see the hello world console log which is a real win! (well for me anyway!) WHen I try and set a simple L: var I get errors in the console. When I use an arbitrary L: Var from somewhere else like:

Code:
console.log('Hello World');
1 (&gt;L:XMLVAR_GPS_Approach)

I'm obviously missing something here.

What I need to do now is understand the best way to write in G36X_Utils.js to write a simple L: var that I can display in the NXi; i'm obviously not initiating the L: Var correctly.

From there that gives me a foundation to build on for using DataStore in the JS file.

As ever, many thanks for any pointers or thoughts.
 
Last edited:
Messages
701
Country
australia
That's not how you write to L vars in JS.

You need to use SetSimVarValue

Code:
SimVar.SetSimVarValue("L:Drifter_Prefs_Radio_ANL", "number", 1);

and to read this value you use GetSimVarValue

Code:
this.beepMode = SimVar.GetSimVarValue("L:Drifter_Prefs_Radio_Beep", "number");

I'm interested to know how you think you will set the fuel level too. In FSX and P3D this was impossible without using SimConnect to write to the A: variable directly (which I have done). I don't know if it's possible to use js to do the same because as far as I know there are no K: type event_ids for fuel level and the only times I have seen SetSimVarValue is to trigger a K: event_id
 
Messages
20
Country
unitedkingdom
Hi @Anthony31

Thanks for the pointers. Unfortunately
Code:
SimVar.SetSimVarValue("L:Drifter_Prefs_Radio_ANL", "number", 1);
doesn't work. I get a 0 in the console.

The fuel is settable according to the SDK docs (what didn't copy below was the settable tick)

FUEL TANK CENTER2 QUANTITYCurrent quantity in volumeGallonsTYPE_FLOAT64
 
Messages
701
Country
australia
Hi @Anthony31

Thanks for the pointers. Unfortunately
Code:
SimVar.SetSimVarValue("L:Drifter_Prefs_Radio_ANL", "number", 1);
doesn't work. I get a 0 in the console.

The fuel is settable according to the SDK docs (what didn't copy below was the settable tick)

FUEL TANK CENTER2 QUANTITYCurrent quantity in volumeGallonsTYPE_FLOAT64
It works because I have a working gauge where it works. I don't know the particulars of your situation or what you're doing but that code works (it works in the Asobo gauges too).

Yes, fuel is settable but only using SimConnect. It's how I've done it in all except one of the aircraft I have made for FSX and P3D. It was impossible to set fuel using XML in FSX and P3D.
 
Messages
20
Country
unitedkingdom
Ok So I am kinda getting somewhere.

I have managed to get the aircraft to save its fuel data to the datastore and then to read it on loading the aircraft. I have also managed to get the sim to write the values to the datastore when the bat 1 & engine is running therefore keeping up to date with fuel usage.

Code:
//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');
  }



// - - - - - - - - - - - - - - - - - - - WHEN SIM RUNNING - - - - - - - - - - - - - - - - - - - - -

var timerMilSecs = 30000;
var timer = window.setInterval(checkG36State, timerMilSecs);

function checkG36State() {
  if (SimVar.GetSimVarValue("ELECTRICAL MASTER BATTERY:1", "bool") && SimVar.GetSimVarValue("ENG COMBUSTION:1", "bool")) {
    let lefttank = SimVar.GetSimVarValue("FUEL TANK LEFT MAIN QUANTITY", "gallons");
    let righttank = SimVar.GetSimVarValue("FUEL TANK RIGHT MAIN QUANTITY", "gallons");
    SetStoredData('G36XIP_LEFT_FUEL', lefttank.toString());
    SetStoredData('G36XIP_RIGHT_FUEL', righttank.toString());
  }
}

I then moved on to setting Battery 1 switch but this doesn't set. I think this is due to the fact that I am not using a class or function. I'm not quite there with how to do that yet...
 
Top