char code[128];
sprintf(code, “(‘%s’) (>L:DEST_ID, String)”, destId);
execute_calculator_code(code, NULL, NULL, NULL);
What’s wrong with that? Thanks
char code[128];
sprintf(code, “(‘%s’) (>L:DEST_ID, String)”, destId);
execute_calculator_code(code, NULL, NULL, NULL);
What’s wrong with that? Thanks
L: Variables don’t support strings, only float numbers. Very clearly explained in the SDK, even if it would be very useful if they did.
I’ll check that. So how for example the standard PC-24 gets destination ID and altitude? I couldn’t find any simwar either. Thanks
L: variables do support strings.
But you can’t access string ones directly from C++ WASM, only via calculator expressions.
L: variables don’t support strings:
https://docs.flightsimulator.com/html/Additional_Information/Reverse_Polish_Notation.htm#L
IMPORTANT! "
L:" vars can only hold numeric data and nothing else, eg: no strings, no binary values, no structs, etc…
But you can’t access string ones directly from C++ WASM, only via calculator expressions.
No, you just can’t read/store strings on L: vars, because they only store numbers.
There are SOME (very few) A: variables, like ATC ID, that accepts string values but, at least until very recently, they couldn’t be set with C++ execute_calculator_code(), even if according to this post:
It seems execute_calculator_code() now work on these, starting from MSFS 2024 SU3. However, these are A: vars, not L: vars, and it’s the very limited set of A: vars that support strings.
How to get the destination airport name? FlightPlanDestinationName
With this it seems to open the wasm file?
char destName[256] = {0};
char destIdent[16] = {0};
double destAlt = 0.0;
// Get values
execute_calculator_code(“(@c:FlightPlanDestinationName)”, destName, nullptr, nullptr);
execute_calculator_code(“(@c:FlightPlanDestinationIdent)”, destIdent, nullptr, nullptr);
execute_calculator_code(“(@c:FlightPlanDestinationAltitude, feet)”, nullptr, &destAlt, nullptr);
// Push to L: vars (for JS)
char code[256];
sprintf(code, “(‘%s’) (>L:DEST_NAME, String)”, destName);
execute_calculator_code(code, nullptr, nullptr, nullptr);
sprintf(code, “(‘%s’) (>L:DEST_ID, String)”, destIdent);
execute_calculator_code(code, nullptr, nullptr, nullptr);
sprintf(code, “(%.1f) (>L:DEST_ALT, Number)”, destAlt);
execute_calculator_code(code, nullptr, nullptr, nullptr);
Even the exmple does not work!
The PC-24 avionics (Primus Epic 2) are coded in JavaScript, (really Typescript if we’re being specific) and do not use the SimConnect API at all. The flight plan in the avionics is held entirely in the memory of the avionics code and is not directly accessible from any simvar based API. If you are coding an instrument in JS, then you could conceivably read the Avionics Framework Event Bus which contain the events regarding the flight plan in avionics code memory, but it isn’t really meant to be consumed directly in that way.
However, those avionics do read the EFB flight plan to bootstrap their systems and synchronize with the world map at the beginning of the flight using the Planned Route API, available in both JavaScript ( JS_LISTENER_PLANNEDROUTE ) and WASM ( Planned Route API ). If this is what you are interested in you can use one of those APIs to get the destination ICAO identifier.
Hope that helps,
Matt
This doesn't work. I have the Epic2 in my plane. Would you have an idea on what is wrong? Thanks
onInstalled() {
this.showDestinationInfo();
...
showDestinationInfo() {
// Register the listener once
Coherent.on("JS_LISTENER_PLANNEDROUTE", (routeData) => {
console.log("Route update:", routeData);
// Extract destination info
const destIdent = routeData.destinationAirportIdent || "";
const destName = routeData.destinationAirportName || "";
const destElev = routeData.destinationAirportElevation || 0;
console.log(`Destination: ${destIdent} / ${destName} / Elevation: ${destElev}`);
// Publish numeric altitude L:var
SimVar.SetSimVarValue("L:DEST_ALT", "Number", destElev);
// Encode first two characters of ICAO into numeric L:vars
if (destIdent.length >= 1) {
const charCodes = destIdent.split("").map(c => c.charCodeAt(0));
SimVar.SetSimVarValue("L:DEST_ID_CH1", "Number", charCodes[0]);
SimVar.SetSimVarValue("L:DEST_ID_CH2", "Number", charCodes[1] || 0);
}
});
}