Directly setting a settable simvar via WASM

What is the best way to set a simvar in a C++ wasm module? I know there is the key events but there is no key event to write on some of the simvars (Avars). I am trying to force a bus voltage (A:ELECTRICAL MAIN BUS VOLTAGE:1 for instance) using execute_calculator_code() function but not successful. According to the SDK, ELECTRICAL MAIN BUS VOLTAGE is a settable simvar but there is no key event to set it.
my function that I am using is:

execute_calculator_code(“28 (>A:ELECTRICAL MAIN BUS VOLTAGE:1, Volts)”, nullptr, nullptr, nullptr);

please let me know if there is a possibility to directly write into a settable simvar with an index.

Either the calculator code or simconnect… no other way.

Best,
R.

can you give me an example how should I use the calculator code for ELECTRICAL MAIN BUS VOLTAGE simvar?

Just like you would do it using RPN code, however the variable simvar must be writable, if it is not, you can only use events to manipulate the value

So technically this should work to set the voltage of a bus:1 to 28 volts:
execute_calculator_code(“28 (>A:ELECTRICAL MAIN BUS VOLTAGE:1, Volts)”, nullptr, nullptr, nullptr);

but it doesn’t :frowning:

Check that sim var is writable and also the electrical systems of that product you working with supports that voltage, it might be capped

Are you quite certain that overriding the voltage can actually work? I am pretty sure that in a running aircraft simulation the voltage is handled by the aircraft code itself. There are many instances where that is the case. While you can technically set the value of a variable (doesn’t matter how you do it) - it holds that value only briefly - then the associated aircraft system resets it to the value that it is supposed to have.

Try a loop, set the value constantly as fast as you can. Maybe use a crazy value, so you can definitely see if something is happening. Then at least you know that setting the variable is working and/or futile (unless you keep the loop running)