xendance 3 Posted May 5, 2013 Hi, I have a question about passing parameters to functions. I made an event handler that can be used for squad leaders, which causes the SL to automatically tell his squad to open fire if the combatmode isn't yellow already. I got it working but I encountered some odd problems that I don't really understand. Here's the code that I couldn't get to work: _unit = _this select 0; if(leader group _unit == _unit) then { _unit addEventHandler ["fired", "[group _unit] call fnc_engage"]; }; fnc_engage = { private ["_unitGroup", "_fireAtWill"]; _fireAtWill = "YELLOW"; _unitGroup = _this select 0; if((combatMode _unitGroup) != _fireAtWill) then { _unitGroup setCombatMode _fireAtWill; }; }; That didn't work so I tinkered with it some more, and managed to fix it by passing _this as parameter to fnc_engage instead of group _unit. _unit = _this select 0; if(leader group _unit == _unit) then { _unit addEventHandler ["fired", "[_this] call fnc_engage"]; }; fnc_engage = { private ["_arr", "_leaderUnit", "_fireAtWill", "_unitGroup"]; _arr = _this select 0; _leaderUnit = _arr select 0; _fireAtWill = "YELLOW"; _unitGroup = group _leaderUnit; if((combatMode _unitGroup) != _fireAtWill) then { _unitGroup setCombatMode _fireAtWill; }; }; Why does the lower one work and not the upper one? This is all in one .sqf file that is called upon unit initialization. Could it be because there's no guarantee that _unit is in any group when the addEventHandler is called? Share this post Link to post Share on other sites
mikie boy 18 Posted May 5, 2013 you need to look at the fired eventhandler to see what parameters it outputs - i don't think it would accept a group, instead it would take a single object the eventhandler is assigned to Share this post Link to post Share on other sites
killzone_kid 1333 Posted May 5, 2013 addevenyhandler expects code to execute you give it string Share this post Link to post Share on other sites
xendance 3 Posted May 5, 2013 you need to look at the fired eventhandler to see what parameters it outputs - i don't think it would accept a group, instead it would take a single object the eventhandler is assigned to Righto. Is it possible to pass additional event args or is it always [unit, weapon, muzzle, mode, ammo]? Share this post Link to post Share on other sites
adanteh 58 Posted July 4, 2013 I'd love to know the same thing. I have several functions and one function is adding an event handler that spawns another function. I want to load some local variables from the first function in the second one so I figured I could do it as followed: (_dialog displayCtrl 8010) ctrlSetEventHandler ["MouseButtonClick","[_partsCfg, _partsSelect] spawn VES_fnc_previewPart"]; VES_fnc_previewPart has the following code in the function just for testing before I know how to use arguments _previewCfg = this select 0; _previewSelect = this select 1; hint format ["cfg: %1, select: %2", _previewCfg, _previewSelect]; Now this puts cfg: any, select: any... aka both the arguments return any for some reason. I can't for the hell of it figure out why that won't work. Googling resulted in this thread, so I figure I'd post here. Share this post Link to post Share on other sites