BIS fnc addStackedEventHandler – Talk

From Bohemia Interactive Community
Revision as of 03:46, 9 December 2014 by Dr StrangePete (talk | contribs)
Jump to navigation Jump to search

Not being able to override default engine behavior was really bumming me out, so I took a look at BIS_fnc_executeStackedEventHandler. By adding 2 variables, I was able to make the function perform as intended (as I see it). Please push this fix to the next hotfix, BIS!

/* Author: Nelson Duarte Edit by: Dread (in bold) Description: This function executes the stacked items, should not be called independently Parameter(s): _this select 0: STRING - The onXxx event handler Returns: BOOL - True if executed code returns true False if executed code returns anything else */ //Parameters private ["_event"]; _event = [_this, 0, "", [""]] call BIS_fnc_param; //Mission namespace id private "_namespaceId"; _namespaceId = "BIS_stackedEventHandlers_"; //Mission namespace event private "_namespaceEvent"; _namespaceEvent = _namespaceId + _event; //The data private "_data"; _data = missionNameSpace getVariable [_namespaceEvent, []]; //Add 2 new variables and define private ["_return","_trash"]; _return = false; _trash = false; //Process data { //Data item parameters private ["_code", "_arguments"]; _code = [_x, 2, "", [{}, ""]] call BIS_fnc_param; _arguments = [_x, 3, []] call BIS_fnc_param; if (typeName _code != typeName "") then { //Execute code _trash = _arguments call _code; //call can return, why waste? } else { //Execute function _trash = _arguments call (call compile _code); //not really sure what's happening here. 2 calls? }; if (typeName _trash == "BOOL") then { if (_trash) then { _return = true; }; }; } forEach _data; //Return _return; Can't get this post formatted correctly. I'm just going to leave it like it is. - DreadedEntity

According to this post http://forums.bistudio.com/showthread.php?167822-Stacked-event-handlers-OnEachFrame-OnPlayerConnected-etc the intention of these functions is for community/official content compatibility, thus the need for consistent functionality - I don't think you'll see them change this (although its easy enough for you to implement yourself for a specific need).
In addition, your code will only return the bool of the last iterated _data. Perhaps this should be run through the forums first --Strangepete (talk) 03:46, 9 December 2014 (CET)