Home   Help Search Login Register  

Author Topic: displayAddEventHandler and stopping spam usage  (Read 2932 times)

0 Members and 1 Guest are viewing this topic.

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
displayAddEventHandler and stopping spam usage
« on: 25 Jan 2011, 02:08:50 »
Hi,

I have a script that runs everytime my F5 key is pressed. The script runs fine, however I noticed that holding the button down would run the script many times - this isn't ideal and would like at least a 1-2 second pause before it is able to be pressed again. I tried removing the display event handler in the running script for the keyDown event but it didn't work because I got an error (see below).

I am using displayAddEventHandler as opposed to _display displaySetEventHandler - From what I read, using set rather than add can overide existing Display EH's?

I've tried adding an event handler which is blank, I also tried removing the event handler using displayRemoveEventHandler but I am having issues with the second parameter, id. I tried the display ID which is past into the script via _this (first value in the array passed through) and it said that it was expecting a number, not a dialog display value. I tried 0 and also the number for the key I pressed - it still let me spam the script by holding the button down.

Also, KeyUp seems no different and doesn't actually wait for the keyUp at all I found ? :S
« Last Edit: 25 Jan 2011, 02:11:47 by JasonO »

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: displayAddEventHandler and stopping spam usage
« Reply #1 on: 25 Jan 2011, 04:52:27 »
I'm not going to pretend to know the answer but what if you added a global variable once the keyF5 button is pushed? I am not an sqf pro but you'll get the idea. For example:

Code: [Select]
//This checks to see if the script is activated.
If F5activated exitwith {};

//If it is already activated it will exit without proceeding, if not it will continue to this line. Which switches the variable state and declares teh script active.
F5activated = true;

//continue through the rest of your script

//At the end, just before exiting the script insert your desired time delay
Sleep 2;

//followed by your variable state switch to declare the script nonactive
F5activated = false;
exitwith {};


You may have to declare the variable state in the mission init or config(not sure how you're using it) before it is recognized in your script as anything usable.

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
Re: displayAddEventHandler and stopping spam usage
« Reply #2 on: 25 Jan 2011, 04:58:04 »
I thought about this, and it works however I might have quite a few key binds in the future so was seeing if there was an alternative to having lots of global variables.

It will do for now though I guess. Thanks for the reply :)

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: displayAddEventHandler and stopping spam usage
« Reply #3 on: 25 Jan 2011, 05:35:10 »
Can you not kill the variable at script end and create it again at start.

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: displayAddEventHandler and stopping spam usage
« Reply #4 on: 25 Jan 2011, 05:54:07 »
displayRemoveEventHandler's second parameter, id, is the value that was returned when you called displayAddEventHandler.

Code: [Select]
private "_id";

// add an event handler...
_id = (findDisplay 46) displayAddEventHandler ["KeyDown", "hint str _this;"];

// ...and remove it
(findDisplay 46) displayRemoveEventHandler ["KeyDown", _id];

Note that multiple event handlers can be added to a display. So in case someone wants to remove an event handler later there should be a way to tell displayRemoveEventHandler which one to remove. This is what the id is for.
« Last Edit: 25 Jan 2011, 05:58:51 by Worldeater »
try { return true; } finally { return false; }

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: displayAddEventHandler and stopping spam usage
« Reply #5 on: 25 Jan 2011, 08:21:58 »
Quote
if there was an alternative to having lots of global variables.
Instead of global variables you can use setVariable. 1,2,3,4 or 5
« Last Edit: 25 Jan 2011, 08:25:26 by h- »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.