Thread Tools Display Modes
07/01/18, 08:07 PM   #1
static_recharge
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 32
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:
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!
  Reply With Quote
07/01/18, 08:33 PM   #2
SilverWF
 
SilverWF's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 55
Question

Pretty obvious question: why not filter effects inside your function, rather than try to break your brain?
  Reply With Quote
07/01/18, 08:39 PM   #3
static_recharge
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 32
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.
  Reply With Quote
07/01/18, 08:47 PM   #4
Scootworks
 
Scootworks's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2014
Posts: 312
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
  Reply With Quote
07/01/18, 09:53 PM   #5
static_recharge
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 32
Thank you for the reply, I wil experiment with it
  Reply With Quote
07/01/18, 11:37 PM   #6
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 408
Originally Posted by SilverWF View Post
Pretty obvious question: why not filter effects inside your function, rather than try to break your brain?


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.
  Reply With Quote
07/02/18, 12:50 AM   #7
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Short, what Scootworks want to say:
The eventFilters need unique names as 1st parameter
  Reply With Quote
07/02/18, 02:47 AM   #8
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
Originally Posted by Baertram View Post
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.
  Reply With Quote
07/02/18, 08:04 AM   #9
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Originally Posted by sirinsidiator View Post
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.
  Reply With Quote
07/02/18, 08:11 AM   #10
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
Originally Posted by Baertram View Post
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.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Multiple Event Filters?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off