ctrlAddEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\|seealso= *\[\[([^ ]+)\]\], \[\[([^ ]+)\]\]" to "|seealso= $1 $2")
(Add magic variables)
Line 21: Line 21:
{{Feature|important|
{{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.
* 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'''').
* 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'''').
}}
}}
Line 31: Line 30:
|p2= handler: [[String]] - Handler name, see [[User Interface Event Handlers]]
|p2= handler: [[String]] - Handler name, see [[User Interface Event Handlers]]


|p3= function: [[String]], since {{GVI|arma3|1.06}} also [[Code]] - Script
|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}}


|r1= [[Number]] - Handler ID or -1 if failed
|r1= [[Number]] - handler ID or -1 if failed


|x1= <code>_map [[ctrlAddEventHandler]] ["draw", "_this [[call]] BIS_fnc_strategicMapOpen_draw"];</code>
|x1= <sqf>_map ctrlAddEventHandler ["draw", "_this call BIS_fnc_strategicMapOpen_draw"];</sqf>


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


|seealso= [[displayAddEventHandler]] [[ctrlRemoveEventHandler]] [[ctrlRemoveAllEventHandlers]]
|seealso= [[displayAddEventHandler]] [[ctrlRemoveEventHandler]] [[ctrlRemoveAllEventHandlers]]
}}
}}

Revision as of 09:38, 10 May 2022

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.png1.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 }];

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