BIS fnc addStackedEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{Feature|arma3 | " to "{{Feature | arma3 | ")
m (Fix SQF)
 
(14 intermediate revisions by the same user not shown)
Line 2: Line 2:


|game1= arma3
|game1= arma3
|version1= 1.00
|version1= 1.00


Line 11: Line 10:
|mp= This command has the same locality as [[addMissionEventHandler]].
|mp= This command has the same locality as [[addMissionEventHandler]].


|descr= Stacks an event handler.  All event handlers accept user arguments, which are passed to the EH code in <tt>_this</tt> variable. If the EH has own params returned in <tt>_this</tt> variable as well, user arguments are appended to the end of <tt>_this</tt> array. Note that if you try to add empty EH, i.e. with empty code, it will simply be ignored.
|descr= {{Feature|obsolete|[[Arma 3: Mission Event Handlers]] should be used instead.|arma3|1.58}}
<br><br>
Stacks an event handler.  All event handlers accept user arguments, which are passed to the EH code in {{hl|_this}} variable. If the EH has own params returned in {{hl|_this}} variable as well, user arguments are appended to the end of {{hl|_this}} array. Note that if you try to add an empty EH, i.e. with empty code, it will simply be ignored.
<u>Supported event handlers</u>
<br><br>
* <tt>"[[onEachFrame]]"</tt> - no EH params
* <tt>"[[onPlayerConnected]]"</tt> - EH params are passed as array in <tt>_this</tt> (<tt>[<id>,<uid>,<name>,<jip>,<owner>]</tt>) and in special variables <tt>_id</tt>, <tt>_uid</tt>, <tt>_name</tt>, <tt>_jip</tt>, <tt>_owner</tt>
* <tt>"[[onPlayerDisconnected]]"</tt> - EH params are passed as array in <tt>_this</tt> (<tt>[<id>,<uid>,<name>,<jip>,<owner>]</tt>) and in special variables <tt>_id</tt>, <tt>_uid</tt>, <tt>_name</tt>, <tt>_jip</tt>, <tt>_owner</tt>
* <tt>"[[onMapSingleClick]]"</tt> - EH params are passed as array in <tt>_this</tt> (<tt>[<units>,<pos>,<alt>,<shift>]</tt>) and in special variables <tt>_units</tt>, <tt>_pos</tt>, <tt>_alt</tt>, <tt>_shift</tt>
* <tt>"[[onPreloadStarted]]"</tt> - no EH params
* <tt>"[[onPreloadFinished]]"</tt> - no EH params


{{Feature | arma3 | Since '''{{arma3}}''' v1.57 a stackable MissionEventHandler is available and should be used instead: [[Arma_3:_Event_Handlers/addMissionEventHandler#MapSingleClick|MapSingleClick]]}}
{{{!}} class="wikitable"
{{!}}+ Supported Event Handlers
! Scripted Event Handler
! Mission EH Equivalent
! Description
{{!}}-
{{!}} "[[onEachFrame]]"
{{!}} [[Arma 3: Mission Event Handlers#EachFrame|EachFrame]]
{{!}} {{n/a}}
{{!}}-
{{!}} "[[onPlayerConnected]]"
{{!}} [[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.
<sqf>params ["_id", "_uid", "_name", "_jip", "_owner"];</sqf>
{{!}}-
{{!}} "[[onPlayerDisconnected]]"
{{!}} [[Arma 3: Mission Event Handlers#PlayerDisconnected|PlayerDisconnected]]
{{!}}-
{{!}} "[[onMapSingleClick]]"
{{!}} [[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.
<sqf>params ["_units", "_pos", "_alt", "_shift"];</sqf>
{{!}}-
{{!}} "[[onPreloadStarted]]"
{{!}} [[Arma 3: Mission Event Handlers#PreloadStarted|PreloadStarted]]
{{!}} {{n/a}}
{{!}}-
{{!}} "[[onPreloadFinished]]"
{{!}} [[Arma 3: Mission Event Handlers#PreloadFinished|PreloadFinished]]
{{!}} {{n/a}}
{{!}}}


|s1= [id, event, code, arguments] call [[BIS_fnc_addStackedEventHandler]]
|s1= [id, event, code, arguments] call [[BIS_fnc_addStackedEventHandler]]
Line 32: Line 53:
|p3= code: [[Code]] or [[String]]. The [[String]] is treated as function name
|p3= code: [[Code]] or [[String]]. The [[String]] is treated as function name


|p4= arguments: [[Array]] of [[Anything]] - arguments to make available in code in <tt>_this</tt> array
|p4= arguments: [[Array]] of [[Anything]] - arguments to make available in code in {{hl|_this}} array


|r1= [[String]] - custom id on success or "" on failure
|r1= [[String]] - custom id on success or "" on failure


|x1= <code>["someId", "onEachFrame", {[[hintSilent]] [[str]] [[time]]}] [[call]] [[BIS_fnc_addStackedEventHandler]];</code>
|x1= <sqf>["someId", "onEachFrame", { hintSilent str time }] call BIS_fnc_addStackedEventHandler;</sqf>


|x2= <code>["someId", "onEachFrame", {[[hintSilent]] [[str]] [[position]] (_this [[select]] 0)}, [<nowiki/>[[player]]]] [[call]] [[BIS_fnc_addStackedEventHandler]];</code>
|x2= <sqf>["someId", "onEachFrame", {hintSilent str position (_this select 0)}, [player]] call BIS_fnc_addStackedEventHandler;</sqf>
 
|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]]
}}
}}


<dl class="command_description">
{{Note
 
|user= ffur2007slx2_5
<dt><dt>
|timestamp= 20140625120800
<dd class="notedate">Posted on 25 Jun, 2014</dd>
|text= Stacking all the code into one PFH will be less demanding than separated calling within multiple PFH, e.g:
<dt class="note">[[User:ffur2007slx2_5|ffur2007slx2_5]]</dt>
<sqf>
<dd class="note">
{
{{GVI|arma3|1.22}} Stack all codes 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;
<code>{
} forEach [var0, var1, varN, var100]; // pretty demanding
[([[format]] [%1”,_forEachIndex]),”[[onEachFrame]]”,_code,[_x]] [[call]] [[BIS_fnc_addStackedEventHandler]];
</sqf>
} [[forEach]] [var0…var100]; //pretty demanding
<sqf>
</code>
[_id, "onEachFrame", {
<code>[_id, ”[[onEachFrame]]”,{
{ _x call _code } forEach [var0, var1, varN, var100];
  {_x [[call]] _code} [[forEach]] [var0…var100];
}] call BIS_fnc_addStackedEventHandler; // faster, only one event
}] [[call]] [[BIS_fnc_addStackedEventHandler]]; //faster
</sqf>
</code>
}}
<dt></dt>
<dd class="notedate">Posted on January 3, 2019 - 13:52 (UTC)</dd>
<dt class="note">[[User:DrSova|DrSova]]</dt>
<dd class="note">
For returning array with all ids:
 
<code>missionNamespace getVariable [format["BIS_stackedEventHandlers_%1",'''_event'''],[]];</code>
 
Where is '''_event''' - name of event ('OnEachFrame', etc.)
</dd>
</dl>

Latest revision as of 17:06, 1 November 2022

Hover & click on the images for description

Description

Description:
🕖
This information is obsolete as of Arma 3 v1.58. Reason: Arma 3: Mission Event Handlers should be used instead.

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.

params ["_id", "_uid", "_name", "_jip", "_owner"];

"onPlayerDisconnected" PlayerDisconnected
"onMapSingleClick" MapSingleClick Special variables _units, _pos, _alt, _shift are provided and are available in _this array as well.

params ["_units", "_pos", "_alt", "_shift"];

"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:
["someId", "onEachFrame", { hintSilent str time }] call BIS_fnc_addStackedEventHandler;
Example 2:
["someId", "onEachFrame", {hintSilent str position (_this select 0)}, [player]] call BIS_fnc_addStackedEventHandler;
Example 3:
private _eventName = "OnEachFrame"; missionNamespace getVariable [format ["BIS_stackedEventHandlers_%1", _eventName], []]; // gets an array with all existing ids

Additional Information

See also:
addMissionEventHandler BIS_fnc_removeStackedEventHandler

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
ffur2007slx2_5 - c
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
[_id, "onEachFrame", { { _x call _code } forEach [var0, var1, varN, var100]; }] call BIS_fnc_addStackedEventHandler; // faster, only one event