View Single Post
04-11-21, 03:12 PM   #9
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
Originally Posted by sezz View Post
did you try if it works without using acevent which itself uses callbackhandler and that's propably why it doesn's work as you expect it?

Lua Code:
  1. local f = CreateFrame("Frame");
  2.  
  3. local EventExists = function(event)
  4.     if (pcall(function() f:RegisterEvent(event); end)) then
  5.         f:UnregisterEvent(event);
  6.         return true;
  7.     end
  8. end
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...?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote