Jump to content
Robustcolor

help with displayEH

Recommended Posts

Hi, is it possible to suspend or waitUntil inside a displayEH? My problem here is that it keeps executing the code aslong as the lean key is pressed, i need it to halt and wait until the lean action is back at 0 before checking again. Suggestions?

(findDisplay 46) displayAddEventHandler ["KeyDown", {
	params ["", "_key"];
	if (_key in [16,18,272,274] ) then {
	Something happens.
	};
}];

I was thinking something like this inside of the displayEH but not sure how to be able to waitUntil it.

(findDisplay 46) displayAddEventHandler ["KeyDown", {
    params ["", "_key"];
    if (_key in [16,18,272,274] ) then {
    something happens.
    waitUntil {inputAction "LeanLeft" == 0 || inputAction "LeanRight" == 0};
    };
}];

This is what i found that should be lean keys.

keyLeanLeft[]={16};
keyLeanRight[]={18};
keyLeanLeftToggle[]={272};
keyLeanRightToggle[]={274};

Share this post


Link to post
Share on other sites

If you want to stay compatible with any binding (I'm left handed and I modified most of the keys) , use actionKeys  command.

if (_key in actionKeys "leanLeft") then {...};  // all players friendly

 

You can spawn any  code inside the EH:
[] spawn {waitUntil {...}; ...};

You can use "keyUp" EH for ending a code.

 

Share this post


Link to post
Share on other sites

Good idea @pierremgi, but without a waitUntil {inputAction "LeanLeft" == 0} or something else makes it possible to spam the code by pressing the key several times. A regular sleep makes it wierd and the inputAction seems not work inside the EH.

player setVariable ["leaning",false];

(findDisplay 46) displayAddEventHandler ["KeyDown", {
	params ["", "_key"];
	if ((_key in actionKeys "leanLeft" || _key in actionKeys "leanLeftToggle" || _key in actionKeys "LeanRight" || _key in actionKeys "LeanRightToggle") && (player getVariable "leaning" == false)) then {
	Something happens.
	player setVariable ["leaning", true];
	};
}];

(findDisplay 46) displayAddEventHandler ["KeyUp", {
	params ["", "_key"];
	if ((_key in actionKeys "leanLeft" || _key in actionKeys "leanLeftToggle" || _key in actionKeys "LeanRight" || _key in actionKeys "LeanRightToggle") && (player getVariable "leaning" == true)) then {
	Something happens.
	player setVariable ["leaning", false];
	};
}];

 

Share this post


Link to post
Share on other sites

instead of :

(player getVariable "leaning" == false)

write:

!(player getvariable ["leaning,false])   // returns true if "leaning" variable is set to false (false by default if the variable doesn't exist yet)

same for

(player getVariable ["leaning",false])  // returns true if "leaning" variable is set to true (false by default if the variable doesn't exist yet)

 

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×