I am having to set this K EVENT:
COVER_SET that requires 2 parameters, cover ID and state.
How can I do that in JS?
I was guessing like:
SimVar.SetSimVarValue("K:2:COVER_SET ", “number”, 1, 0); —> Error
or
SimVar.SetSimVarValue("K:2:COVER_SET ", “number”, 10);
Thanks!
Hello,
`SetSimVarValue` does not support multiple parameters.
If you are using the MSFS Avionics Framework, you can use KeyEventManager.triggerKey() to do this, which supports up to three key event parameters. If you are in raw JS, you can register the JS_LISTENER_KEYEVENT listener, then use the Coherent call ‘TRIGGER_KEY_EVENT’, which takes five parameters:
- name (string) - The string name of the key event to call (in this case it would just be ‘COVER_SET’)
- bypass (boolean) - Whether to bypass any previously configured intercepts in XML or JS for this key event. This will guarantee that the key event makes it to the sim even if it has been requested to be intercepted either in JS or in XML (with InputEvent event bindings).
- param1 (number) - The first parameter to the key event. Any number can be supplied if the key event in question does not require this parameter, as it will be ignored.
- param2 (number) - The second parameter to the key event. Any number can be supplied if the key event in question does not require this parameter, as it will be ignored.
- param3 (number) - The third parameter to the key event. Any number can be supplied if the key event in question does not require this parameter, as it will be ignored.
Hope that helps,
Matt
If you are not using MSFS Avionics Framework and have previously registered “JS_LISTENER_KEYEVENT”, You can create a helper at the beginning of your class:
triggerKey(key, bypass, value0 = 0, value1 = 0, value2 = 0) {
return Coherent.call(‘TRIGGER_KEY_EVENT’, key, bypass, value0, value1, value2);
}
Some practical examples:
set_valve_switch(i, v) { this.triggerKey("FUELSYSTEM_VALVE_SET", true, i, v); }
set_pump_switch(i, v) { this.triggerKey("FUELSYSTEM_PUMP_SET", true, i, v); }
set_junction_setting(i, v) { this.triggerKey("FUELSYSTEM_JUNCTION_SET", true, i, v); }
set_eng_bleed_airsource(i, v) { this.triggerKey("ENGINE_BLEED_AIR_SOURCE_SET", true, i, v); } // Sets if the indexed engine is a source to the bleed air system or not
set_pitot_heat_switch(i, v) { this.triggerKey("PITOT_HEAT_SET", true, i, v); } // Sets the pitot heat switch on/off.
Regards.
can a string paramater be used? for example if i’m targeting a named component in one of the new modular systems