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) 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) Has anyone come across this, or have any thoughts? |
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 |
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... |
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.
|
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() |
Thanks for the report an the nice explanation!
|
All times are GMT -6. The time now is 12:47 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI