Trouble with KEY_THROTTLEx_SET [Solved]


Resource contributor
Dunno what's going on here, so I'm looking for a way out of the mudpit.


Throttle setting depends on the throttle icon that is being shown - it's not the normal slider but a series of icons that change depending on what percentage of input is being demanded. The screenshot doesn't show underscores for some reason.

mouseclick - t1_state shows that icon 21 should be displayed
throttle1 - thr_t1pos (the required throttle input) is calculated as 12743 and a bit (16383 / 27 icons)
throttle1 - thr_t1prev is just a code trap

The following code line after checking the state of thr_t1pos is
I then do a
and the result is always something stupid. Watched in real time it bounces crazily between zero and thr_t1pos, sometimes coming to a halt at an indeterminate figure between the two (usually less than one and greater than zero). I also checked the XML equivalent (GENERAL ENG THROTTLE LEVER POSITION:index) which gave the same results but as a percentage figure. One thing that I am absolutely-lutely-lutely certain of is that the throttle is not being set anywhere else. Disconnecting the joystick has no effect and reading the input as set by the joystick (KEY_AXIS_THROTTLE_SET) and also checking the keyboard input (F1-F4) gives the same results.

Ok... a few items for thought:

1. trigger_key_event is not instant. It is put into a queue and processed in the order it was received. It may or may not have been processed in the instant between the trigger_key_event and the lookup_var.
2. send_key_event is instant. It is pushed to the head of the queue and processed next. That does not assure that reading lookup_var will return the value you sent... here's why:
3. lookup_var is not a dynamic read of the variable. It is a read of a variable's value in a snapshot of sim time before the 18hz update cycle is called. It is unlikely to provide an updated value if you just changed the value in the same 18hz update cycle.

Of course, someone may wander by and say none of the above is true... but, that's my knowledge.


Resource contributor
I did try send_key_event after I'd posted, but to no avail. Reading through (3); if the lookup_var does not read the previous send command, then it should read the results of the send command on the next cycle, right? It should not show the constant 'zero-not zero' sequence that it is showing.

The queue information is good info though; thank you. I've updated the next issue of sd2gau to include it.
The trigger_key_event is like a PostMessage to a Windows application. The send_key_event is like a SendMessage to a Windows application. One is sent to the back of the queue, one is sent to the front of the queue.

Comment out your trigger_key_event. If you still see the throttle jumping in values... you have something, somewhere, that is indeed touching the throttle setting.


Resource contributor
The one thing about talking to you, Ed, is that you always make me think sideways. The digital equivalent of another pair of eyes. I found a bloody race condition... :banghead::):)