I need help with the absolutely core functionality of MSFS2020 and 2024 - can you write RPN code to DETECT events designed into the sim. E.g. “XPNDR_1_INC”. A ‘stock’ event, that can be added in your Controls keybinds. Nothing to do with creating a NEW custom event, Nothing to do with B:variables. No need to worry about INC or DEC or SET functionality. Just the basic “stock MSFS async event triggers RPN code”.
I’m using the example of XPNDR_1_INC as an event (it actually means increment the transponder code by +1, but afaik it doesn’t matter what the event actually means).
Clearly works has been done in this area. You’d think the obvious answer to this question would be “yes” but my testing is suggesting otherwise, which is odd.
Basic idea:
Event “XPNDR_1_INC” is triggered in the sim, for example:
the player has a controls UI keybind setting Ctrl-N to “TRANSPONDER INCREMENT (1)” and hits Ctrl-N on the keyboard, or
some JS code includes writing “1” to the K:XPNDR_1_INC variable, or
a simconnect app issues the XPNDR_1_INC event.
Some bit of RPN e.g. 1 (>L:B21_TEST)in the model XML is run when that event has been triggered.
The smallest example Component I can create is 19 lines and ONLY works if the event is generated by a user UI keybind, i.e. the same XPNDR_1_INC doesn’t wake up the RPN code if it’s sent by Javascript or an external simconnect, although you can see the event having an effect in the sim. FWIW my code is using <UseInputEvent ID="ASOBO_GIE_Base"> with that pre-defined template but maybe there’s a better solution. The Model Behaviours Inputs SDK docs page probably provides valuable clues, but that page branches off into a world of flexible alternatives BEFORE it gives any working example of a Component that contains the basic core event-capture capability, so there’s no complete sample code in there. Model Behaviors Inputs
What’s the shortest model XML Component that would provide this functionality? Is there anything in the SDK docs that gives an example of this functionality, or anyone have an example? I.e. just XPNDR_1_INC → RPN., but it should equally be triggered if the event was fired by JS SimVar.SetSimVarValue("K:XPNDR_1_INC","number",1)
I think there are bugs in MSFS which mean this basic functionality isn’t possible, but I’d much prefer it’s just me being stupid. I anyone could fill in the blanks for a component that does pick up the XPNDR_1_INC event and run some RPN I’d be hugely grateful. I’ve studied all the docs so already know those links. I’m intentionally not distorting the thread with my non-working answer as a clean known working solution should only be a few lines.
I don’t think you can get around making a custom input event in order to capture a key event binding. But for a basic event that just runs code when a button is clicked can be very minimal.
I’ll add my chronograph trigger input event as an example. This doesn’t care about any parameters, if any of the bindings are activated, it will run the code. It has to have the value and inc and dec. It’s the bindings section that I have not found an easier way to associate with code.
This can also just trigger the original key event along with your code so it can be transparent if you want or you can take over the event and prevent it’s default.
This fulfills your other requirements because it can be triggered from JS by setting the B var. I don’t really use SimConnect so I’m not sure how that uses B vars or can set the K event.
In 2024, it may be easier to add a binding but I have not made that connection yet by inspecting the code.
And if you want a basic input event example for an axis control, this is the one I wrote to control cowl flaps with the spoiler axis but of course you could have any code there.
That is SO helpful, thanks very much. So you went straight for the InputEvent element rather than using the Asobo_GIE_Base template wrapper?
If I’ve understood correctly it looks like your code is designed to capture the FLAPS_INCR stock event and run RPN code, where in your case your extended design is to capture multiple different events and ultimately use RPN to trigger your own B-style events. So I should be able to use this for my simpler requirement. TBH rather than custom events I redesigned my JS gauges to have their UI triggered by L:vars simply being set to non-zero and the gauge resets that to zero - that’s been working really well and I should have done it earlier. Still have a need to detect stock events in the XML though.
I thought my Asobo_GIE_Base code was working like a boss (capturing stock events and running RPN code) but recently discovered it’s only working when I trigger the stock event via a Controls settings keybind, but does nothing when JS or simconnect code triggers the same stock event.
I should be able to test the same using your InputEvent design - will report back. Thanks.
I resisted input events as much as possible but then I figured out the basic structure and after that, it didn’t seem so bad. The bindings are important to use whenever you are dealing with non-mouserect user inputs. This makes your code more compatible with hardware controllers and I suspect it is faster to react than using update loops and LVars.
The new 2024 interaction templates seem to be able to create their own input events but I can’t find out how to add bindings.
abso-freakin-lutely - this is the use case that got scuppered when we found out my ambitious Asobo_GIE_Base template usage didn’t spark into life when MobiFlight sends the event. I don’t personally have that and only tested by triggering the event via the keyboard/keybinds.
For clarity, the first example has the value, inc and dec parts but these do not really do anything. If you need a dec or inc do do anything useful, you would add a binding like:
Then I would have the code part have: (B:CHRONO_TOGGLE, number) p0 + (>B:CHRONO_TOGGLE_Set)
to to add that binding parameter to the var.
But in my original code, there are no bindings so the only entry to that code is to call (>B:CHRONO_TOGGLE_inc). I do not intend to call that anyway so is why the FLAPS_INC and FLAPS_DEC are just assigned to the set command so that these will trigger the main code. It’s sort of “press any of these buttons” and it should work.
And the value section serves to sort of set a default value even though it will be overwritten anyway,
No matter how I trigger the FLAPS_INCR event (button keybind set up on my stick, JS SetSimVarValue), none of the L:vars change. At this stage I’m not worried about the functionality after that point, clearly I’ve misunderstood or messed something up if none of the RPN is executing.
Could I beg for a copy of that Component? I have spent so many hours on this trying to create one simple example of an event capture actually working, but barely making any progress. The Asobo_GIE_Base template is close, but wrapped up with so much other cruft nothing to do with capturing the actual event it’s been impossible for me to unpick. In my use of that template wrapper it ONLY catches the event if it has been set up as a keybind in the Controls settings and triggered by the user using that keybind. It doesn’t catch the event if it has been issued by an API like RPN, JS or SimConnect. Asobo_GIE_Base does have <InputEvent> underneath it, so that could be a limitation of that code, but with no working example I can’t work that out.
I copied your input event code and added it to one of my planes to test. I made some changes but these do not affect the core function.
It did not work at first but after some careful scrutinizing, I spotted the error. You have <ModelBehaviours> in your code but the correct tag is <ModelBehaviors>. With that corrected, you should see the input event in the behaviors debugger.
Since I already had a flap lever that has it’s own flaps bindings, I had to disable that. The plane I created the chrono toggle for doesn’t have flaps so that’s why I chose those key events.
Thanks very much indeed - you saved me so many hours. Apologies for that typo - that certainly cost you time trying to help.
This example you helped me with worked straight away when I ported it into my plane, so easily a good alternative to the Asobo_GIE_Base template which wraps so much other stuff around it.
I did find InputEvent has the same limitation as the Asobo_GIE_Base template, that the event subscription doesn’t fire for users with ‘external’ controllers that rely on simconnect to send in the events (e.g. VR users with controller decks that talk to the sim via Mobiflight/simconnect). Those control the sim ok but don’t trigger those InputEvents in the model XML. I’m not sure but it may be devs are using L: vars on knobs and buttons to work around this limitation.