Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Event Handler Question

Featured Replies

  • Commercial Member

int Paused;void FSAPI EventHandler (ID32 event, UINT32 evdata, PVOID userdata) {if (event == KEY_PAUSE_TOGGLE){Paused = !Paused;}}In this snipped, I'm using the Event Handler to determine if the Sim is paused.This is evaluated twice per second, right?My problem appears to be that because it's evaluated twice per second, Pause remains at 0... whereas it should cycle between 1 and 0 each time I pause and unpause the sim.Any way around this? This looks like a pretty good way to determine if the sim is paused (assuming I can get it to work).P.S. This snipped is based on a sample published by Patrick Waugh... so all credit or blame goes to him :( Ciao,

I created this little one way back not C but XML -- You'll get it though :(

<Element><Select><Value>(P:Absolute time, seconds) (G:Var1) == if{ 1 (>G:Var2) } els{ 0 (>G:Var2) } (P:Absolute time, seconds) (>G:Var1)</Value>      </Select></Element>

G:Var2 gives the paused bool.Hope it helps,Roman

20AUG21_Avsim_Sig.png?dl=1  FS RTWR   SHRS F-111   JoinFS   Little Navmap 
 

 

int Paused;void FSAPI EventHandler (ID32 event, UINT32 evdata, PVOID userdata) {if (event == KEY_PAUSE_TOGGLE){Paused = !Paused;}}In this snipped, I'm using the Event Handler to determine if the Sim is paused.This is evaluated twice per second, right?My problem appears to be that because it's evaluated twice per second, Pause remains at 0... whereas it should cycle between 1 and 0 each time I pause and unpause the sim.Any way around this? This looks like a pretty good way to determine if the sim is paused (assuming I can get it to work).P.S. This snipped is based on a sample published by Patrick Waugh... so all credit or blame goes to him :( Ciao,
you don't seem to have initialised the variable Paused. As you code stands Paused could have any random value initially, so repeatedly toggling it won't cause it to change between 0 and 1.

Gerry Howard

  • Author
  • Commercial Member

Hmmm, well, I think the problem though is that it's evaluated twice.As a test I changed Pause = !Pausedto:Paused++And then returned Paused as a string to see what it was doing...Each time I pause/unpaused the sim, Paused went up in increments of 2...2...4...6... 8 etcSo it's definitely reading the Pause key event, it's just the counter that's the issue.

  • Commercial Member
Hmmm, well, I think the problem though is that it's evaluated twice.As a test I changed Pause = !Pausedto:Paused++And then returned Paused as a string to see what it was doing...Each time I pause/unpaused the sim, Paused went up in increments of 2...2...4...6... 8 etcSo it's definitely reading the Pause key event, it's just the counter that's the issue.
It is typical that a key has a 'down' and an 'up' event.

Ed Wilson

Mindstar Aviation
My Playland - I69

Try the declaration:bool Paused;I may be picky but the !-operator in principle works on boolean values not integers. I know that C isn't too particular about this but you never know!

Gerry Howard

  • Commercial Member

From a recent update of my internal version of sd2gau....There is a downside to the event handler, particularly if you are looking for a one-shot event such as KEY_GEAR_TOGGLE. Once an event is placed on the system, it remains live until superceded by another event. So, in the case of the G (default gear) key, you will be unable to detect a demand to reverse the action of the gear unless another event has occurred inbetween your keyboard demands. Even then, it doesn’t always work… Oddly enough, one reliable way I found to break the recognition of the current event when trying to track a toggle sequence is to use a timer.

int gear_handlepos=2;			//0=up 1=neutral 2=down(default)double gear_handle_timer=-1;//-----//Gear lever from keyboardvoid Gearlever(ID32 event){  if(event==KEY_GEAR_TOGGLE && gear_handle_timer==-1)  {	lookup_var(&currtick18);	gear_handle_timer=currtick18.var_value.n+1;	if(!gear_handlepos)gear_handlepos=2;	else if(gear_handlepos==2)gear_handlepos=0;  }  return;}//-----  case	PANEL_SERVICE_PRE_UPDATE:	if(gear_handle_timer!=-1)	{	  lookup_var(&currtick18);	  if(currtick18.var_value.n==gear_handle_timer)gear_handle_timer=-1;	}

-Dai

  • Author
  • Commercial Member
Try the declaration:bool Paused;I may be picky but the !-operator in principle works on boolean values not integers. I know that C isn't too particular about this but you never know!
Hey MGH,My 5 hours of precious time for an Integer!You were right... bool did the trick :( Thanks,
  • Commercial Member
Try the declaration:bool Paused;I may be picky but the !-operator in principle works on boolean values not integers. I know that C isn't too particular about this but you never know!
The ! operator performs a boolean operation of inverting each bit in the value. It doesn't care one bit what type of value it's looking at in C. However, it's important to remember that in a logical decision involving a boolean result that false is equal to 0, but true is equal to absolutely anything but 0. Since his value isn't initialized to any known value... if it's not a zero, then inverting the bits of the value will not return a 0 value no matter what.As example:Value of 5 in binary is 0101Invert that value and it is now 1010 which is 10.Either value of 5 or 10 would evaulate as a 'true' condition because they're not zero.

Ed Wilson

Mindstar Aviation
My Playland - I69

There's still an inherant problem with a handler to determine whether FS is paused or not. What happens if a user starts an external program while FS is paused -or- Starts FS paused -or- Pause on task switch is checked ? Your pause register is wrong.When FS is paused,,, time stands still.Roman

20AUG21_Avsim_Sig.png?dl=1  FS RTWR   SHRS F-111   JoinFS   Little Navmap 
 

 

  • Commercial Member
There's still an inherant problem with a handler to determine whether FS is paused or not. What happens if a user starts an external program while FS is paused -or- Starts FS paused -or- Pause on task switch is checked ? Your pause register is wrong.When FS is paused,,, time stands still.Roman
I believe TICK18 does not update any time the sim is paused.

Ed Wilson

Mindstar Aviation
My Playland - I69

I believe TICK18 does not update any time the sim is paused.
Ed, TICK18 still updates with the sim paused, but NOT when FS is in any menu system.Tom
The ! operator performs a boolean operation of inverting each bit in the value. It doesn't care one bit what type of value it's looking at in C. However, it's important to remember that in a logical decision involving a boolean result that false is equal to 0, but true is equal to absolutely anything but 0. Since his value isn't initialized to any known value... if it's not a zero, then inverting the bits of the value will not return a 0 value no matter what.As example:Value of 5 in binary is 0101Invert that value and it is now 1010 which is 10.Either value of 5 or 10 would evaulate as a 'true' condition because they're not zero.
The ! operator doesn't perform a boolean operation of inverting each bit in the value. The ! operator toggles the operand between true (non-zero) and false (0). According to "The C Programming Language" by Brian W Kernighan and Dennis M Ritchie (who originally designed and implemented and so know something about it):"The unary negation operator ! converts a non-zero or true operand into 0, and a zero operand into 1."As a consequence your example is incorrect because !5 = 0 and !0 = 1.What you are refering to is the one's complement operator ~ which, according to the same source:"The unary operator ~ yields the one's complement of an integer; that is it converts each 1-bit into a 0-bit and vice-versa."! and ~ are two different operators and are easily confused.

Gerry Howard

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.