{"name":"BIS_fnc_addStackedEventHandler","operator":null,"title":"BIS fnc addStackedEventHandler","type":"function","url":"https://community.bistudio.com/wiki/BIS_fnc_addStackedEventHandler","revid":330780,"updated":"2022-11-01T16:06:55Z","groups":["Event Handlers"],"status":"deprecated","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"1.00"}],"since":{"game":"arma3","name":"Arma 3","version":"1.00"},"arma3_since":"1.00","branch":null,"locality":{"argument":null,"effect":"local","server_exec":false},"exec":null,"description":"> [!CAUTION]\n> This information is **obsolete**. Arma 3: Mission Event Handlers should be used instead.\n\nStacks an event handler.  All event handlers accept user arguments, which are passed to the EH code in `_this` variable. If the EH has own params returned in `_this` variable as well, user arguments are appended to the end of `_this` array. Note that if you try to add an empty EH, i.e. with empty code, it will simply be ignored.\n\n|  |  |  |  |\n|---|---|---|---|\n| + Supported Event Handlers | Scripted Event Handler | Mission EH Equivalent | Description |\n| \"onEachFrame\" | EachFrame | N/A |  |\n| \"onPlayerConnected\" | PlayerConnected | Special variables `_id`, `_uid`, `_name`, `_jip`, `_owner` are provided and are available in `_this` array as well.<br>```sqf<br>params [\"_id\", \"_uid\", \"_name\", \"_jip\", \"_owner\"];<br>``` |  |\n| \"onPlayerDisconnected\" | PlayerDisconnected |  |  |\n| \"onMapSingleClick\" | MapSingleClick | Special variables `_units`, `_pos`, `_alt`, `_shift` are provided and are available in `_this` array as well.<br>```sqf<br>params [\"_units\", \"_pos\", \"_alt\", \"_shift\"];<br>``` |  |\n| \"onPreloadStarted\" | PreloadStarted | N/A |  |\n| \"onPreloadFinished\" | PreloadFinished | N/A |  |","syntaxes":[{"syntax":"[id, event, code, arguments] call BIS_fnc_addStackedEventHandler","since":null,"effect":null,"exec":null,"params":[{"name":"id","type":"String","optional":false,"default":null,"description":"custom id, a unique identifier. Adding same type of EH with the same id will overwrite existing","types":["String"],"since":null,"text":"id: String - custom id, a unique identifier. Adding same type of EH with the same id will overwrite existing"},{"name":"event","type":"String","optional":false,"default":null,"description":"event handler name, see description for supported EHs","types":["String"],"since":null,"text":"event: String - event handler name, see description for supported EHs"},{"name":"code","type":null,"optional":false,"default":null,"description":"Code or String. The String is treated as function name","types":["Code","String"],"since":null,"text":"code: Code or String. The String is treated as function name"},{"name":"arguments","type":"Array of Anything","optional":false,"default":null,"description":"arguments to make available in code in `_this` array","types":["Array","Anything"],"since":null,"text":"arguments: Array of Anything - arguments to make available in code in `_this` array"}],"returns":{"type":"String","types":["String"],"description":"custom id on success or \"\" on failure","text":"String - custom id on success or \"\" on failure"}}],"examples":[{"text":"```sqf\n[\"someId\", \"onEachFrame\", { hintSilent str time }] call BIS_fnc_addStackedEventHandler;\n```","code":["[\"someId\", \"onEachFrame\", { hintSilent str time }] call BIS_fnc_addStackedEventHandler;"]},{"text":"```sqf\n[\"someId\", \"onEachFrame\", {hintSilent str position (_this select 0)}, [player]] call BIS_fnc_addStackedEventHandler;\n```","code":["[\"someId\", \"onEachFrame\", {hintSilent str position (_this select 0)}, [player]] call BIS_fnc_addStackedEventHandler;"]},{"text":"```sqf\nprivate _eventName = \"OnEachFrame\";\nmissionNamespace getVariable [format [\"BIS_stackedEventHandlers_%1\", _eventName], []]; // gets an array with all existing ids\n```","code":["private _eventName = \"OnEachFrame\";\nmissionNamespace getVariable [format [\"BIS_stackedEventHandlers_%1\", _eventName], []]; // gets an array with all existing ids"]}],"multiplayer":"This command has the same locality as addMissionEventHandler.","problems":null,"aliases":[],"see_also":["addMissionEventHandler","BIS_fnc_removeStackedEventHandler"],"notes":[{"user":"ffur2007slx2_5","date":"2014-06-25T12:08:00Z","text":"Stacking all the code into one PFH will be less demanding than separated calling within multiple PFH, e.g:\n\n```sqf\n{\n    [format [\"%1\", _forEachIndex], \"onEachFrame\", _code, [_x]] call BIS_fnc_addStackedEventHandler;\n} forEach [var0, var1, varN, var100]; // pretty demanding\n```\n\n```sqf\n[_id, \"onEachFrame\", {\n    { _x call _code } forEach [var0, var1, varN, var100];\n}] call BIS_fnc_addStackedEventHandler; // faster, only one event\n```"}],"categories":["Arma 3: Functions","Arma 3: New Functions","Function Group: Event Handlers","Functions","Functions: Local Effect","Introduced with Arma 3 version 1.00"],"docblock":null,"filled_from_docblock":[]}