ctrlAddEventHandler: Difference between revisions

From Bohemia Interactive Community
(Undo revision 87874 by Longbow (talk) ctrlSET indeed does not support code, but this is ctrlADD page)
mNo edit summary
 
(49 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma2 |= Game name
|game1= arma2
|version1= 1.00


|1.00|= Game version
|game2= arma2oa
____________________________________________________________________________________________
|version2= 1.50


| Add an event handler ([[User Interface Event Handlers]]) to the given control. Returns id of the handler or -1 when failed. |= Description
|game3= tkoh
____________________________________________________________________________________________
|version3= 1.00


| control '''ctrlAddEventHandler''' [handler,function] |= Syntax
|game4= arma3
|version4= 0.50


|p1= control: [[Control]] |= PARAMETER1
|gr1= GUI Control - Event Handlers


|p2= [handler,function]: [[Array]]  |= PARAMETER2
|gr2= Event Handlers


|p3= handler: [[String]] - handler name|= PARAMETER3
|descr= Add an event handler to the given control.
|p4= function: [[String]] or [[Code]] - script|= PARAMETER4
 
| [[Number]] |= RETURNVALUE


{{Feature|important|
* Control event handlers are processed in reversed order, i.e. last added: first, first added: last. So if you have an override it should be set up in the 1st added EH.
* When using the event names listed [[User Interface Event Handlers|here]] with the [[ctrlAddEventHandler]], [[ctrlSetEventHandler]], [[displayAddEventHandler]] or [[displaySetEventHandler]] commands, the prefix "on" in the event name must be removed (e.g. ''''ButtonDown'''' instead of ''''onButtonDown'''').
}}


|x1= <code>_map [[ctrlAddEventHandler]] ["draw","_this call BIS_fnc_strategicMapOpen_draw"];</code>|= EXAMPLE1
|s1= control [[ctrlAddEventHandler]] [handler, function]
|x2= <code>_map [[ctrlAddEventHandler]] ["draw",{[[hintSilent]] [[str]] _this}];</code>|= EXAMPLE1


|p1= control: [[Control]]


____________________________________________________________________________________________
|p2= handler: [[String]] - handler name, see [[User Interface Event Handlers]]


| [[displayAddEventHandler]], [[ctrlRemoveEventHandler]], [[ctrlRemoveAllEventHandlers]] |= SEEALSO
|p3= function: [[String]], since {{GVI|arma3|1.06}} also [[Code]] - script. Several [[Magic Variables]] are available:
* Event Handler parameters are accessible via {{hl|_this}}
* The Event Handler type is available as {{hl|_thisEvent}}
* The Event Handler index is available as {{hl|_thisEventHandler}}


| |= MPBEHAVIOUR
|r1= [[Number]] - handler ID or -1 if failed
____________________________________________________________________________________________
}}


<h3 style='display:none'>Notes</h3>
|x1= <sqf>_map ctrlAddEventHandler ["Draw", "_this call BIS_fnc_strategicMapOpen_draw"];</sqf>
<dl class='command_description'>
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on October 30, 2013 - 11:14
<dt class="note">'''[[User:Killzone_Kid|Killzone_Kid]]'''<dd class="note">As of Arma 3 v1.05.111658 [[ctrlAddEventHandler]] and [[displayAddEventHandler]] support script [[Code]] in addition to [[String]] [http://forums.bistudio.com/showthread.php?149636-Development-Branch-Changelog&p=2546439&viewfull=1#post2546439]


|x2= <sqf>_map ctrlAddEventHandler ["Draw", { hintSilent str _this }];</sqf>


<!-- Note Section END -->
|x3= <sqf>findDisplay 12 displayCtrl 51 ctrlAddEventHandler ["Draw", { hintSilent str _this }]; //Arma 3 map control</sqf>
</dl>


<h3 style='display:none'>Bottom Section</h3>
|seealso= [[displayAddEventHandler]] [[ctrlRemoveEventHandler]] [[ctrlRemoveAllEventHandlers]]
[[Category:ArmA 2: New Scripting Commands List|{{uc:{{PAGENAME}}}}]]
}}
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_GUI_Control|{{uc:{{PAGENAME}}}}]]

Latest revision as of 15:17, 7 October 2025

Hover & click on the images for description

Description

Description:
Add an event handler to the given control.
Groups:
GUI Control - Event HandlersEvent Handlers

Syntax

Syntax:
control ctrlAddEventHandler [handler, function]
Parameters:
control: Control
handler: String - handler name, see User Interface Event Handlers
function: String, since Arma 3 logo black.png 1.06 also Code - script. Several Magic Variables are available:
  • Event Handler parameters are accessible via _this
  • The Event Handler type is available as _thisEvent
  • The Event Handler index is available as _thisEventHandler
Return Value:
Number - handler ID or -1 if failed

Examples

Example 1:
_map ctrlAddEventHandler ["Draw", "_this call BIS_fnc_strategicMapOpen_draw"];
Example 2:
_map ctrlAddEventHandler ["Draw", { hintSilent str _this }];
Example 3:
findDisplay 12 displayCtrl 51 ctrlAddEventHandler ["Draw", { hintSilent str _this }]; //Arma 3 map control

Additional Information

See also:
displayAddEventHandler ctrlRemoveEventHandler ctrlRemoveAllEventHandlers

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