Jump to content
Grenadier ITF

Pass local variable in displayAddEventHandler

Recommended Posts

As the title suggests I can't pass the _target variable.

_target = _this select 0;
 

_id=(findDisplay 46) displayAddEventHandler ["KeyDown", 

   

   "if(_this select 1==22)then {_nul =[_target] execVM 'koc.sqf'};"];

any suggestions would be welcome :))

Share this post


Link to post
Share on other sites

Target has to be defined within the scope of your event handler action. You can store/retrieve it in missionnamespace for example. It depends on what type of data you are trying to pass.

  • Like 2

Share this post


Link to post
Share on other sites

Or store _target on the display using setVariable, then retrieve it from the display inside the EH. Rather than using a global variable.

Spoiler

_target = _this select 0;
findDisplay 46 setVariable[ "TAG_target", _target ];

_id = findDisplay 46 displayAddEventHandler[ "KeyDown", {
	params[ "_display", "_keyCode", "_shft", "_ctr", "_alt" ];
	
	if ( _keyCode == 22 ) then {
		_target = _display getVariable "TAG_target";
		_nul = [ _target ] execVM 'koc.sqf';
	};
}];

 

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
16 minutes ago, Larrow said:

Or store _target on the display using setVariable, then retrieve it from the display inside the EH. Rather than using a global variable.

  Hide contents


_target = _this select 0;
findDisplay 46 setVariable[ "TAG_target", _target ];

_id = findDisplay 46 displayAddEventHandler[ "KeyDown", {
	params[ "_display", "_keyCode", "_shft", "_ctr", "_alt" ];
	
	if ( _keyCode == 22 ) then {
		_target = _display getVariable "TAG_target";
		_nul = [ _target ] execVM 'koc.sqf';
	};
}];

 

 

thanks.  tried but without success.
from the koc.sqf file
variable not defined 

Share this post


Link to post
Share on other sites
22 minutes ago, Mr H. said:

Target has to be defined within the scope of your event handler action. You can store/retrieve it in missionnamespace for example. It depends on what type of data you are trying to pass.

 

the target is an object, vehicle, unit or other

Share this post


Link to post
Share on other sites

Resolved. thank you guys

_target = _this select 0;

missionNamespace setVariable ["YourString",_target];

   

   _id=(findDisplay 46) displayAddEventHandler ["KeyDown", 

   

   "if(_this select 1==22)then {
       _target = missionNamespace getVariable 'YourString';

       _nul =[_target] execVM 'koc.sqf'};"];

DONE!

Share this post


Link to post
Share on other sites

Then, same as:

YourString = _this select 0;

_id=(findDisplay 46) displayAddEventHandler ["KeyDown", {

   if(_this select 1==22)then {
       [YourString] execVM "koc.sqf"

   };

}];

  • Like 1

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

×