View Single Post
04-11-21, 03:53 PM   #10
sezz
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 158
Originally Posted by LudiusMaximus View Post
What you suggest is a good way to check if an event exists! Do you think it is more efficient than my solution:
Lua Code:
  1. if not APIDocumentation then
  2.     LoadAddOn("Blizzard_APIDocumentation");
  3. end
  4. local allEvents = APIDocumentation:GetAPITableByTypeName("event")
  5.  
  6. local EventExists = function(event)
  7.     local eventExists = false
  8.     for k, v in pairs(allEvents) do
  9.         if event == v.LiteralName then
  10.             eventExists = true
  11.             break
  12.         end
  13.     end
  14.     return eventExists
  15. end

My problem was really AceEvent's UnregisterAllEvents() function that tries to unregister non-existing events that were tried to be registered using pcall(). Maybe AceEvent assumes that a script will never continue after its RegisterEvent() fails. So it does not bother to remove a non-existent event from its own table of (putatively) registered events...?
Personally I'd would use my solution because it doesn't rely on Blizzard to provide a up-to-date and complete documentation (also you don't need to load the addon which itself takes about 2-3 times as long as it takes to check 10000 events for existance with the pcall approach).
  Reply With Quote