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

max.paperno avatar image
max.paperno asked max.paperno commented

gauge_calculator_code_precompile() with code meant for format_calculator_string() reports format errors

Hello,

In the docs for gauge_calculator_code_precompile() it says:

A precompiled (compressed) calculator string can be used as input to the execute_calculator_code and format_calculator_string functions.

And indeed it works with any code destined for execute_calculator_code().

However when I give it "formatting" code meant for format_calculator_string(), it reports errors (below). The same code string works w/out error when passed directly to format_calculator_string(), w/out going through the precompile stage.

Using a simple example from the RPN string formatting docs:

Fuel Quantity: %( (A:FUEL TOTAL QUANTITY, liters) )%!1.2f!

When passed directly to format_calculator_string() it yields the expected result:
Fuel Capacity: 336.90

When passed to gauge_calculator_code_precompile() it throws errors in the Dev Mode Console:

Invalid script (command not found - perhaps a space is missing or there's an extra space?): "Fuel"
Invalid script (no command is more than 4 characters): "Quantity: ( (A:FUEL TOTAL QUANTITY, liters) )!1.2f!"
Invalid script (no command is more than 4 characters): "( (A:FUEL TOTAL QUANTITY, liters) )!1.2f!"

Which BTW are the same errors I'd see if I passed that calculator string to execute_calculator_code() directly.

FWIW, gauge_calculator_code_precompile() returns ok/true when this happens, a compiled size (pCompiledSize) of 11 and the byte code returned is 01:0B:00:00:00:00:00:00:00:00:00. (which clearly format_calculator_string() doesn't know what to do with and just returns the byte code data verbatim).


Is there some trick to pre-compiling string formatting code for use in format_calculator_string()? Or does it simply not work?


Thank you,
-Max

gaugeswasmc++
10 |10000

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

virtuali avatar image
virtuali answered max.paperno commented

I think it would be easier to help you if you posted some of your C++ code.

2 comments
10 |10000

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

max.paperno avatar image max.paperno commented ·

Was there something unclear about my question? I'm happy to elaborate but seems I posted pretty detailed info.

My question is directed at someone who is already familiar with what those functions do and how they work. I'm not looking for guesses or opinions.

Thanks,
-Max

0 Likes 0 ·
max.paperno avatar image max.paperno max.paperno commented ·

PS. if you want to see it how it works, the precompile code is here and usage is here. The latter function simply gets passed either the precompiled byte code or the verbatim calculator string, and runs it. As mentioned this all works in every other situation except the combination I'm inquiring about.

0 Likes 0 ·
EPellissier avatar image
EPellissier answered max.paperno commented

Hi @max.paperno,

The issue is under investigation on our end. I was wondering if you had already used gauge_calculator_code_precompile and format_calculator_string together on past versions of Flight Simulator: I can see that the documentation has always stated that both could work together but, looking at this part of the legacy code, I am wondering if it ever was the case.

Anyway, I'll let you know when I have more information on this topic.

Best regards,

Eric / Asobo

1 comment
10 |10000

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

max.paperno avatar image max.paperno commented ·

Hi Eric,

Thanks for the investigation. To answer your question, no, I've never used those functions before in any FS version. I'm just going by the current docs (FWIW the P3D docs also state the same thing). So indeed, maybe it never worked.

Thanks again,
-Max

0 Likes 0 ·

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 19.1 MiB each and 23.8 MiB total.