Loading FLT files via Javascript

Does anyone know if it’s possible to load any of the standard flt files that aircraft have via Javascript?

Currently if I want to put an aircraft into a shutdown state I have to manually send a bunch of single simvar commands to configure the state of the plane.

It would be better, and more consistent for each plane, if I could just load the appropriate FLT file such as apron.flt or ApronWithoutCovers.flt for Cold n’ Dark, or runway/runwaywater for takeoff.

I can’t find anything to do that on Coherent.js

Is it possible?
If not, can Asobo make it possible?

Use cases and context:
I just released Location Manager 2 for MSFS 2024/2020 Location Manager 2 for MSFS 2024/2020 - Sonicviz ( a rewrite of LM1, as the main map is now locked out of modification) and I would like better control over the aircraft state when a user teleports to a gate, runway, or other location, to place the aircraft in an aircraft consistent cold or hot state.

At the moment it’s quite a hacky solution and doesn’t provide a consistent a/c UX for transitioning to different states under user control. It would be better to utilize the system in place, which is just to reload the appropriate flt file for the state you want to place the plane in.

It’s something I’ve been looking to do for a while, but a customer just pinged me over it again, so here I am!

Thanks!

1 Like

Does anybody know if you can do this?

It seems like a basic no brainer function that should be available.
I remember looking for it in 2020 and never found it either.

Seriously, you still can’t seem to access the ability to load standard .flt state descriptor files from the aircraft folder?

It can’t be a security issue, you’re literally running it from a custom code base anyway, so that wouldn’t make sense. You could provide an API call that was restricted to the standard set of .flt files that describe state if you wanted to constrain it.

.flt files are loaded with Simconnect_FlightLoad. You can use Commbus API to call it from JS.

1 Like

Interesting, thanks.
I don’t know that one. Do you have a reference and/or example?

Update:
It seems it’s not working atm: Loading a saved flight via Simconnect is not working

Do you mean this communication API? Communication API

So you can’t call it directly from js it seems (even if it did work) you have to use the js to wasm, and build a separate Wasm module that does the simconnect_flighload

Is it possible just to make a straight call from js, without having to make a wasm module?

I don’t think it’s possible straight from JS. It works at least for flights starting on the ground. The module is simple:

#include <MSFS\MSFS.h>
#include <MSFS\MSFS_WindowsTypes.h>
#include <MSFS\MSFS_Events.h>
#include <MSFS\MSFS_CommBus.h>
#include <MSFS\Types\MSFS_EventsEnum.h>
#include <SimConnect.h>
#include <vector>
#include <string>
#include <sstream>

HANDLE g_hSimConnect;

static std::vector<std::string> splitArgs(const std::string& args) {
	std::istringstream iss(args);
	std::vector<std::string> result;
	std::string word;
	while (iss >> word) {
		result.push_back(word);
	}
	return result;
}

static void MyWasmCallback(const char* args, unsigned int size, void* ctx) { 
	std::vector<std::string> words = splitArgs(args);
	
	if (words.empty()) return;

	if (words[0] == "FLIGHT_SAVE") {
		SimConnect_FlightSave(g_hSimConnect, words[1].c_str(), words[1].c_str(),0, 0);
		fprintf(stderr, "Received command: %s\n", args);
	}
	else if (words[0] == "FLIGHT_LOAD") {
		SimConnect_FlightLoad(g_hSimConnect, words[1].c_str());
		fprintf(stderr, "Flight Load: %s\n", words[1].c_str());
	}
}

extern "C" MSFS_CALLBACK void module_init(void)
{
	fsCommBusRegister("MyWasmCallback", MyWasmCallback);
	g_hSimConnect = 0;
	HRESULT hr = SimConnect_Open(&g_hSimConnect, "Standalone Module", NULL, 0, 0, 0);
	if (hr != S_OK)
	{
		fprintf(stderr, "Could not open SimConnect connection.\n");
		return;
	}
}

extern "C" MSFS_CALLBACK void module_deinit(void)
{
	if (!g_hSimConnect)
		return;
	HRESULT hr = SimConnect_Close(g_hSimConnect);
	if (hr != S_OK)
	{
		fprintf(stderr, "Could not close SimConnect connection.\n");
		return;
	}
}
1 Like

Ah, right, I just wanted to KISS but it is what it is. Thanks!

1 Like

I think it’s a mistake not to call this what it is. MSFS has now accumulated 6 (SIX) programming environments with overlapping and inconsistent API’s:

  • model RPN
  • the model templates system
  • html/js
  • simconnect exe’s
  • WASM
  • node/typescript

None of those environments is simple except the one with most of your code in. We’re creeping into a situation where it’s normal for MSFS devs to say "ah, if you want this data, simple, just use my framework.

1 Like

NodeJS nor Typescript are available in the sim. If you want to use typescript you have to transpile it to JS yourself. I suspect what you really mean is the avionics framework, which is a framework/library to help build HTML/JS instruments.

Having done my fair share of work with raw JS at FlyByWire I cannot wait until the last of it is gone and we’re fully typesafe (or at least as close as you can get, because Typescript is still limited by the JS it has to transpile to), as it makes life so much nicer with good IDE completions and hints, cuts out a lot of bugs, and gives you much more confidence when refactoring.

1 Like

The OP is referring to triggering the load of a FLT file from within the MSFS system. The challenge isn’t about which is the best programming language for that, it’s that we have lots of programming languages/frameworks and it’s becoming necessary to know ALL of them if you’re the sole programmer on a complex aircraft. I.e. someone asks about doing the FLT load in the html/js ‘framework’, and the answer is to use the WASM ‘framework’ just for that function. Instead of tidying this up, we’re adding additional ‘frameworks’.