View Single Post
07-22-13, 08:53 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You don't need a separate frame for each event, but you do need to handle your events properly. In the code you posted, you are defining CLEU-specific variables before checking that you're actually handling the CLEU event. Check the event first, and then assign the provided arguments to variables:

Code:
MyFrame:SetScript("OnEvent", function(self, event, ...)
   if event == "COMBAT_LOG_EVENT_UNFILTERED" then
      local timestamp, eventType, sourceGUID, sourceName, sourceFlags, destGUID, destName = ...
      -- do stuff here

   elseif event == "LOOT_OPENED" then
      local autoLoot = ...
      -- do stuff here
   end
end)
Also, that CLEU handling code itself is pretty horrifyingly inefficient. If you just want to detect when you enter a boss fight, use INSTANCE_ENCOUNTER_ENGAGE_UNIT, not COMBAT_LOG_EVENT_UNFILTERED. At the very least, implement some kind of sub-event filtering and/or basic throttling so you're not running that pairs loop 1000000 times per second in raid combat.

Finally, there is no reason to define your event-handler-specific variables as locals in any scope other than the scope of your event handler function. Always limit your variables to the narrowest scope necessary. Defining, for instance, local enemy outside of your CLEU handler just makes your code look badly written (eg. leaked globals) to anyone else who glances at it, and makes it harder for anyone (yourself included) to determine the variable's scope, but doesn't actually confer any performance benefits.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote