Author Topic: One-shot Trigger Disabling  (Read 931 times)

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4829
One-shot Trigger Disabling
« on: September 23, 2008, 01:23:30 PM »
Heh, almost forgot I was supposed to post this info.

If you have a trigger that is set to only fire once, then it will disable itself after it fires. The question I got from Hidiot, was at what point does the trigger get disabled.


Here's the sequence of events.
Code: [Select]
1) For each trigger:
    2) Check if the trigger should fire
    3) If the trigger fires, then get the callback address (the function you export from your DLL)
        3b) When getting the callback address, call Disable() if it's a One-shot trigger
4) For each trigger that fired:
    5) Call the trigger callback

This is important because, by the time your callback function executes, Disable() has already been called on that trigger. This means you can re-enable it in the callback. If it got disabled after the callback, then it would have forgotten any changes you tried to make.

This also means you can re-enable other One-shot triggers that are firing this tick, but haven't yet had their callback functions called. That is, if you have two triggers, A and B that will both fire on the current tick, then the callback for trigger A can re-enable trigger B, even before the callback for trigger B executes. As you can see in the above sequence of steps, all the triggers are checked and disabled if needed, before any of the callbacks are called.


Edit: I'd also like to point out that Disable() is not the same as Destroy(). If you Disable on a trigger, it still exists, and takes up one of the 255 ScStub objects, but won't fire. If you call destroy, then the space allocated for it is freed and can be reused.
 
« Last Edit: September 23, 2008, 01:26:55 PM by Hooman »

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1194
    • http://www.eddy-b.com
One-shot Trigger Disabling
« Reply #1 on: September 23, 2008, 01:31:38 PM »
Biggest question on people's minds right now would be:
If i destroy the one-time trigger from inside the callback function to save resources (read: ScStub objects), will that work or do i get some kind of exception?
« Last Edit: September 23, 2008, 01:32:03 PM by Eddy-B »
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1020
One-shot Trigger Disabling
« Reply #2 on: September 23, 2008, 01:33:02 PM »
It will work.

I've seen it work.
"Nothing from nowhere, I'm no one at all"

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4829
One-shot Trigger Disabling
« Reply #3 on: September 23, 2008, 01:39:59 PM »
From what I've read of the code, I see no reason why that wouldn't work.

Of course I've never tried it.