BIS fnc addStackedEventHandler: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - "<code>([^<]*)\[\[([a-zA-Z][a-zA-Z0-9_]+)\]\]([^<]*) *<\/code>" to "<code>$1$2$3</code>") |
Lou Montana (talk | contribs) m (Fix SQF) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 26: | Line 26: | ||
{{!}} [[Arma 3: Mission Event Handlers#PlayerConnected|PlayerConnected]] | {{!}} [[Arma 3: Mission Event Handlers#PlayerConnected|PlayerConnected]] | ||
{{!}} rowspan="2" {{!}}Special variables {{hl|_id}}, {{hl|_uid}}, {{hl|_name}}, {{hl|_jip}}, {{hl|_owner}} are provided and are available in {{hl|_this}} array as well. | {{!}} rowspan="2" {{!}}Special variables {{hl|_id}}, {{hl|_uid}}, {{hl|_name}}, {{hl|_jip}}, {{hl|_owner}} are provided and are available in {{hl|_this}} array as well. | ||
< | <sqf>params ["_id", "_uid", "_name", "_jip", "_owner"];</sqf> | ||
{{!}}- | {{!}}- | ||
{{!}} "[[onPlayerDisconnected]]" | {{!}} "[[onPlayerDisconnected]]" | ||
Line 34: | Line 34: | ||
{{!}} [[Arma 3: Mission Event Handlers#MapSingleClick|MapSingleClick]] | {{!}} [[Arma 3: Mission Event Handlers#MapSingleClick|MapSingleClick]] | ||
{{!}} Special variables {{hl|_units}}, {{hl|_pos}}, {{hl|_alt}}, {{hl|_shift}} are provided and are available in {{hl|_this}} array as well. | {{!}} Special variables {{hl|_units}}, {{hl|_pos}}, {{hl|_alt}}, {{hl|_shift}} are provided and are available in {{hl|_this}} array as well. | ||
< | <sqf>params ["_units", "_pos", "_alt", "_shift"];</sqf> | ||
{{!}}- | {{!}}- | ||
{{!}} "[[onPreloadStarted]]" | {{!}} "[[onPreloadStarted]]" | ||
Line 57: | Line 57: | ||
|r1= [[String]] - custom id on success or "" on failure | |r1= [[String]] - custom id on success or "" on failure | ||
|x1= < | |x1= <sqf>["someId", "onEachFrame", { hintSilent str time }] call BIS_fnc_addStackedEventHandler;</sqf> | ||
|x2= < | |x2= <sqf>["someId", "onEachFrame", {hintSilent str position (_this select 0)}, [player]] call BIS_fnc_addStackedEventHandler;</sqf> | ||
|x3= < | |x3= <sqf> | ||
private _eventName = "OnEachFrame"; | |||
missionNamespace getVariable [format ["BIS_stackedEventHandlers_%1", _eventName], []]; // gets an array with all existing ids | |||
</sqf> | |||
|seealso= [[addMissionEventHandler]] [[BIS_fnc_removeStackedEventHandler]] | |seealso= [[addMissionEventHandler]] [[BIS_fnc_removeStackedEventHandler]] | ||
}} | }} | ||
{{Note | |||
|user= ffur2007slx2_5 | |||
|timestamp= 20140625120800 | |||
|text= Stacking all the code into one PFH will be less demanding than separated calling within multiple PFH, e.g: | |||
<sqf> | |||
{ | |||
Stacking all the code into one PFH will be less demanding than separated calling within multiple PFH, e.g: | [format ["%1", _forEachIndex], "onEachFrame", _code, [_x]] call BIS_fnc_addStackedEventHandler; | ||
< | } forEach [var0, var1, varN, var100]; // pretty demanding | ||
</sqf> | |||
} | <sqf> | ||
</ | [_id, "onEachFrame", { | ||
< | { _x call _code } forEach [var0, var1, varN, var100]; | ||
{ _x | }] call BIS_fnc_addStackedEventHandler; // faster, only one event | ||
}] | </sqf> | ||
</ | }} |
Latest revision as of 17:06, 1 November 2022
Description
- Description:
Stacks 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.
Supported Event Handlers Scripted Event Handler Mission EH Equivalent Description "onEachFrame" EachFrame N/A "onPlayerConnected" PlayerConnected Special variables _id, _uid, _name, _jip, _owner are provided and are available in _this array as well. "onPlayerDisconnected" PlayerDisconnected "onMapSingleClick" MapSingleClick Special variables _units, _pos, _alt, _shift are provided and are available in _this array as well. "onPreloadStarted" PreloadStarted N/A "onPreloadFinished" PreloadFinished N/A - Execution:
- call
- Multiplayer:
- This command has the same locality as addMissionEventHandler.
- Groups:
- Event Handlers
Syntax
- Syntax:
- [id, event, code, arguments] call BIS_fnc_addStackedEventHandler
- Parameters:
- id: String - custom id, a unique identifier. Adding same type of EH with the same id will overwrite existing
- event: String - event handler name, see description for supported EHs
- code: Code or String. The String is treated as function name
- arguments: Array of Anything - arguments to make available in code in _this array
- Return Value:
- String - custom id on success or "" on failure
Examples
- Example 1:
- Example 2:
- Example 3:
- private _eventName = "OnEachFrame"; missionNamespace getVariable [format ["BIS_stackedEventHandlers_%1", _eventName], []]; // gets an array with all existing ids
Additional Information
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
- Posted on Jun 25, 2014 - 12:08 (UTC)
-
Stacking all the code into one PFH will be less demanding than separated calling within multiple PFH, e.g:
{ [format ["%1", _forEachIndex], "onEachFrame", _code, [_x]] call BIS_fnc_addStackedEventHandler; } forEach [var0, var1, varN, var100]; // pretty demanding