BIS fnc addStackedEventHandler – Talk

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
m (Corrected the look of the code)
Line 1: Line 1:
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!
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!


<code>/*
<code><nowiki>/*
Author: Nelson Duarte
Author: Nelson Duarte
Edit by: Dread '''(in bold)'''
Edit by: Dread </nowiki>'''(in bold)'''<nowiki>
Description:
Description:
Line 11: Line 11:
_this select 0: STRING - The onXxx event handler
_this select 0: STRING - The onXxx event handler
Returns:
Returns:</nowiki>
'''BOOL -'''
'''BOOL -'''
'''True if executed code returns true'''
'''True if executed code returns true'''
'''False if executed code returns anything else'''
'''False if executed code returns anything else'''
 
<nowiki>
*/Parameters
*/
//Parameters
private ["_event"];
private ["_event"];
_event = [_this, 0, "", [""]] call BIS_fnc_param;
_event = [_this, 0, "", [""]] call BIS_fnc_param;
Line 31: Line 32:
private "_data";
private "_data";
_data = missionNameSpace getVariable [_namespaceEvent, []];
_data = missionNameSpace getVariable [_namespaceEvent, []];
 
</nowiki>
'''//Add 2 new variables and define
'''//Add 2 new variables and define
'''private ["_return","_trash"];'''
'''private ["_return","_trash"];'''
'''_return = false;'''
'''_return = false;'''
'''_trash = false;'''
'''_trash = false;'''
 
<nowiki>
//Process data
//Process data
{
{
Line 46: Line 47:
if (typeName _code != typeName "") then {
if (typeName _code != typeName "") then {
//Execute code
//Execute code
</nowiki>
'''_trash =''' _arguments call _code; '''//call can return, why waste?'''
'''_trash =''' _arguments call _code; '''//call can return, why waste?'''
} else {
} else {
Line 58: Line 60:
'''};'''
'''};'''
'''};'''
'''};'''
<nowiki>
} forEach _data;
} forEach _data;


//Return
//Return</nowiki>
'''_return;'''
'''_return;'''
</code>
</code>
Can't get this post formatted correctly. I'm just going to leave it like it is. - [https://community.bistudio.com/wiki/User_talk:DreadedEntity DreadedEntity]
Can't get this post formatted correctly. I'm just going to leave it like it is. - [https://community.bistudio.com/wiki/User_talk:DreadedEntity DreadedEntity]

Revision as of 03:20, 9 December 2014

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