Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBA_fnc_addBISEventHandler #313

Merged
merged 3 commits into from
Apr 24, 2016
Merged

CBA_fnc_addBISEventHandler #313

merged 3 commits into from
Apr 24, 2016

Conversation

commy2
Copy link
Contributor

@commy2 commy2 commented Apr 24, 2016

This adds CBA_fnc_addBISEventHandler

Was brought up in the ACE public slack. You can never pass arguments to event handlers and you can't retrieve the id for removing it from inside either.

This PR follows the idea of the recently added _thisScript (script handle passed as variable) to spawn (https://community.bistudio.com/wiki/spawn)

Using CBA_fnc_addBISEventHandler adds these variables to the executed function:

  • _this - default event handler information
  • _thisType - type of the event (e.g. Fired, Draw3D, keyDown)
  • _thisId - id used to remove the event (e.g. via ctrlRemoveEventHandler)
  • _thisArgs - additional arguments passed when the event handler was added
  • _thisFnc - CODE, a copy of the function

It can be used on objects, dialogs and controls, as well as add mission event handlers (using missionNamespace as "target")

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;

@commy2 commy2 added the Feature label Apr 24, 2016
@Killswitch00 Killswitch00 merged commit c5d83d3 into master Apr 24, 2016
@thojkooi thojkooi deleted the addBISEventHandler branch April 25, 2016 11:32
@commy2 commy2 added this to the 2.3.2 milestone May 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants