ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   AddFilterForEvent - unable to UnregisterForEvent (https://www.esoui.com/forums/showthread.php?t=9436)

nightdreaming 10/28/20 12:00 PM

AddFilterForEvent - unable to UnregisterForEvent
 
I am having a problem de-registering an event for which I have added a filter. For example:

Code:

EVENT_MANAGER:RegisterForEvent("myEvent1", EVENT_COMBAT_EVENT, myEventHandler)
EVENT_MANAGER:AddFilterForEvent("myEvent1", EVENT_COMBAT_EVENT, REGISTER_FILTER_TARGET_COMBAT_UNIT_TYPE, COMBAT_UNIT_TYPE_PLAYER)

The above works fine, if I switch my bar to one that has Crystal Fragments on it then I get an event saying ACTION_RESULT_EFFECT_GAINED "Crystal Fragments Passive", which is what I would expect (as the target of it is me). If I switch bar away from that I also get ACTION_RESULT_EFFECT_FADED "Crystal Fragments Passive" as I would expect.

The problem I am having is if I want to change what events I am getting, for example if I want all combat events instead of just those where I am the target (note this is a change without reloadui, so just a different section of my code). My code does this:

Code:

EVENT_MANAGER:UnregisterForEvent("myEvent1", EVENT_COMBAT_EVENT)
EVENT_MANAGER:RegisterForEvent("myEvent1", EVENT_COMBAT_EVENT, myEventHandler)

This should remove the old event registration and replace it. But it doesn't. I still get the same events triggered, for example when I switch bar. It seems as if unregistering the event doesn't actually unregister the filter.

Has anyone come across this, or have any thoughts?

Baertram 10/28/20 12:40 PM

As the filtering does not happen in lua code it could be that unregistering an event via lua does not remove the filters on it.
Maybe event filters will only clear on reloadui and are designed to be used that way.
This is something you should ask to ZOs.

Did you try to just overwrite the existing one without unregistering it, does it keep the filter as well? (I assume this would be intended, where your usecase though would be "an error").


Just use another unique identifier for new registered events and do not re-use your before used myEvent1. I actually always counted +1 and registered the same event's filters this way, if there is no other unique eventName portion like the abilityId or some other Id available. But even then I think I counted a variable + 1 and added it as string via
Code:

eventName.."_"..counterVar
at the end to make sure I do not alter or re-register some already registered event + filter.

nightdreaming 10/28/20 01:23 PM

Thanks Baertram, I reduced my code to make it more readable, I am registering events and filters using a counter on the namespace as you suggest, that all works fine.

I am trying to unregister and then re-use the unregistered namespace, but that gives the behaviour above. If I unregister the old namespace and then using a different namespace for the new event, I do get the new events, but I also continue to get the old events I don't want any more. As a developer, it offends me to leave things hanging around that are no longer being used :-) Hence my preference to unregisters events+filters I don't use any more.

It probably isn't unregistering the filters in the C code. Oh well...

ZOS_DanBatson 10/29/20 09:50 AM

I put in a fix, but it won't make it in until the next major update (not the one coming next week, but the one after that, update 29.) The issue specifically happens if you unregister and register again in the same frame. In the mean time you can alleviate this by waiting a frame before doing the re-register.

Baertram 10/29/20 10:34 AM

Just as an extra info (maybe there is a better way as well to achieve this?):
To wait 1 frame just call your function with a zo_callLater and delay 0 ms:

Code:

zo_callLater(function()
  -- run you code which should be delayed by 1 frame here
end, 0)


Solinur 11/01/20 07:15 PM

Thanks for the report an the nice explanation!


All times are GMT -6. The time now is 06:39 PM.

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