ESOUI

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

Letho 07/10/19 02:02 PM

IsEventRegistered()
 
Hey guys, is it possible to check wether an event is already registered? If I register the same event multiple times, it seems not to be overwritten but registering multiple times which is very odd behavior.

Example:
Lua Code:
  1. function AuraMastery:RegisterForEvent(eventId, abilityId)
  2.         local eventNamespace = "AM_"..eventId..abilityId
  3.     local eventHandler = MyHandler
  4.     EVENT_MANAGER:RegisterForEvent(eventNamespace, eventId, eventHandler)
  5.     EVENT_MANAGER:AddFilterForEvent(eventNamespace, eventId, REGISTER_FILTER_ABILITY_ID, abilityId)
  6. end

AuraMastery:RegisterForEvent(EVENT_COMBAT_EVENT, 30920)
AuraMastery:RegisterForEvent(EVENT_COMBAT_EVENT, 30920)


Any use of ability(30920) will trigger MyHandler TWO TIMES! instead of one time.

I need a function to determine if an event of specified Namespace and filter /w abilityId is already registered.

(I know I could handle it manually by saving it to a table onRegistering, but maybe there is a more elegant way :)

sirinsidiator 07/10/19 03:41 PM

You are mistaken. Event handlers can only be registered once for the same eventNamespace/eventId pair. EVENT_MANAGER:RegisterForEvent returns true if it actually registered the function and false otherwise. In order to assign a different function you have to first call UnregisterForEvent for the same namespace and id, which will also return true in case it did unregister something.

The reason why you see your handler getting called more than once is that some abilities have more than one effect. I tried your code with Shadowy Disguise (id 62141) and it is called 2 times when it is cast and one more time when the invisibility runs out.

Letho 07/12/19 09:19 AM

Found the problem, thanks for the help!


All times are GMT -6. The time now is 12:14 PM.

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