OFPEC Forum
Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: JasonO 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
-
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:
//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.
-
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 :)
-
Can you not kill the variable at script end and create it again at start.
-
displayRemoveEventHandler (http://community.bistudio.com/wiki/displayRemoveEventHandler)'s second parameter, id, is the value that was returned when you called displayAddEventHandler (http://community.bistudio.com/wiki/displayAddEventHandler).
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.
-
if there was an alternative to having lots of global variables.
Instead of global variables you can use setVariable. 1 (http://www.ofpec.com/COMREF/index.php?action=details&id=1263&game=All),2 (http://www.ofpec.com/COMREF/index.php?action=details&id=1264&game=All),3 (http://www.ofpec.com/COMREF/index.php?action=details&id=1265&game=All),4 (http://www.ofpec.com/COMREF/index.php?action=details&id=1266&game=All) or 5 (http://www.ofpec.com/COMREF/index.php?action=details&id=1267&game=All)