ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Multiple Event Filters? (https://www.esoui.com/forums/showthread.php?t=7910)

static_recharge 07/01/18 08:07 PM

Multiple Event Filters?
 
So I'm following the Wiki on how to add multiple filters for the same event and I'm stumped. According to the Wiki:
Quote:

Multiple filters can be added in one call by repeatedly supplying a filter type followed by a parameter or in multiple calls by calling AddFilterForEvent for the same event. Filters cannot be removed once they were added without unregistering the event.
But when I try to do this (either method mentioned), the only filter that applies is the last one to run in the code.

My code for method 1:
Code:

EVENT_MANAGER:RegisterForEvent(SFR.addonName, EVENT_EFFECT_CHANGED, SFR.OnEffectChanged)

EVENT_MANAGER:AddFilterForEvent(SFR.addonName, EVENT_EFFECT_CHANGED, REGISTER_FILTER_ABILITY_ID, 89957, REGISTER_FILTER_ABILITY_ID, 61259)

My code for method 2:
Code:

EVENT_MANAGER:RegisterForEvent(SFR.addonName, EVENT_EFFECT_CHANGED, SFR.OnEffectChanged)

EVENT_MANAGER:AddFilterForEvent(SFR.addonName, EVENT_EFFECT_CHANGED, REGISTER_FILTER_ABILITY_ID, 89957)

EVENT_MANAGER:AddFilterForEvent(SFR.addonName, EVENT_EFFECT_CHANGED, REGISTER_FILTER_ABILITY_ID, 61259)

In both cases only the last filter to be executed works. I verified this by switching the abilityId's and still only the last one to be applied works. Any ideas or suggestions for what I'm doing wrong? I'd like to add a whole bunch of filters so that my code only fires on the events I want, but I can't even get these 2 to work.

Thanks in advance for any help!

SilverWF 07/01/18 08:33 PM

Pretty obvious question: why not filter effects inside your function, rather than try to break your brain? :D

static_recharge 07/01/18 08:39 PM

Don't get me wrong it had crossed my mind, I just wanted to see if there was an advantage to using the built-in filter or not. If it doesn't work that is exactly what I will be doing.

Scootworks 07/01/18 08:47 PM

you need something like this:
lua Code:
  1. local DETONATIONS =
  2. {
  3.     [61500] = true,
  4.     [63296] = true,
  5.     [63299] = true,
  6.     [63302] = true,
  7. }
  8.  
  9. local eventCounter = 0
  10. for abilityId in pairs(DETONATIONS) do
  11.     eventCounter = eventCounter + 1
  12.     local eventName = ADDON_NAME..eventCounter
  13.     EVENT_MANAGER:RegisterForEvent(eventName, EVENT_EFFECT_CHANGED, function(eventCode, changeType, _, _, unitTag, beginTime, endTime, _, _, _, _, _, _, _, _, abilityId)
  14.         self:OnEffectChanged(changeType, unitTag, beginTime, endTime, abilityId)
  15.     end)
  16.     EVENT_MANAGER:AddFilterForEvent(eventName, EVENT_EFFECT_CHANGED, REGISTER_FILTER_ABILITY_ID, abilityId)
  17. end

static_recharge 07/01/18 09:53 PM

Thank you for the reply, I wil experiment with it :D

Dolgubon 07/01/18 11:37 PM

Quote:

Originally Posted by SilverWF (Post 35249)
Pretty obvious question: why not filter effects inside your function, rather than try to break your brain? :D



Pretty obvious answer: Because it's better.


Using the filters on the Event Manger is better for performance, since the game does the filtering in the C code rather than Lua. For stuff with abilities which can fire a lot, this means you have less lag in places where it matters the most: Combat.

Baertram 07/02/18 12:50 AM

Short, what Scootworks want to say:
The eventFilters need unique names as 1st parameter

sirinsidiator 07/02/18 02:47 AM

Quote:

Originally Posted by Baertram (Post 35254)
Short, what Scootworks want to say:
The eventFilters need unique names as 1st parameter

That's not correct. The problem OP has is that he tries to register the same filter type multiple times, which is not possible. You have to register a separate event + filter for each ability id you want to filter.

Baertram 07/02/18 08:04 AM

Quote:

Originally Posted by sirinsidiator (Post 35257)
That's not correct. The problem OP has is that he tries to register the same filter type multiple times, which is not possible. You have to register a separate event + filter for each ability id you want to filter.

Ok, I was not clear enough. The loop in scoot works example showed the registering + filter for each ability id already.
But afai remember I even had to change the event name in order to get the multiple ability id's to work at the same time.

sirinsidiator 07/02/18 08:11 AM

Quote:

Originally Posted by Baertram (Post 35259)
Ok, I was not clear enough. The loop in scoot works example showed the registering + filter for each ability id already.
But afai remember I even had to change the event name in order to get the multiple ability id's to work at the same time.

That's right. You can also register a eventNamespace/eventId pair only once, so you need to use a different namespace when you want to listen for the same event more than once.


All times are GMT -6. The time now is 08:58 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI