Skip to content

CBA_fnc_addBISEventHandler

commy2 edited this page May 17, 2016 · 2 revisions

CBA event handler wrapper for BIS events

This is a framework/wrapper to add event handlers with arguments. The event handlers ID will also be passed as a special variable.

Adding and removing events

Events are added via CBA_fnc_addBISEventHandler.
The ID returned by that function can be used to remove the event via removeEventHandler, displayRemoveEventHandler, ctrlRemoveEventHandler or removeMissionEventHandler respectively. The events can also be removed from inside the event by utilizing the special variable _thisId.

Parameters:

  • _object: Thing to attach event handler to. Can be a <OBJECT>, <DISPLAY> or <CONTROL>. missionNamespace is used to add mission events.
  • _type - The event handler type. <STRING>
  • _function - The function to execute when the event occurs. <CODE>
  • _arguments - Arguments to pass to event handler. They will appear as _thisArgs special variable.

Special variables

  • _this: Default event handler arguments.
  • _thisType: The type of the event (e.g. "Fired", "Draw3D", "keyDown")
  • _thisId: The id used to remove the event (e.g. via ctrlRemoveEventHandler).
  • _thisArgs: - Additional arguments passed when the event handler was added.
  • _thisFnc: - A copy of the function. <CODE>

Examples

  • A one time reloaded event handler (prints "bananas" once after first reload):
[player, "reloaded", {
    systemChat _thisArgs;
    player removeEventHandler [_thisType, _thisID];
}, "bananas"] call CBA_fnc_addBISEventHandler;
  • Print text once after 300 frames:
[missionNamespace, "EachFrame", { 
    if (diag_frameno < _thisArgs) exitWith {};
    systemChat "hello world"; 
    removeMissionEventHandler [_thisType, _thisID]; 
}, diag_frameno + 300] call CBA_fnc_addBISEventHandler;