View Single Post
10-24-13, 03:12 PM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
It may be working, but it's not correct. The first argument for COMBAT_LOG_EVENT is the timestamp, and since you have the sub-event first it means your arguments are all off by one.

This is because "self" is implied when you use a colon to define a function. You could change it to events:COMBAT_LOG_EVENT_UNFILTERED(event, ...) but the entire point of writing an event handler like this is so you can define your variables directly in the function arguments.

I would personally remove the event name from the arguments since it's already the name of the function itself and I can't think of any reason you would need it. Something like this..

Lua Code:
  1. function events:COMBAT_LOG_EVENT_UNFILTERED(timestamp, event, _, srcGUID, srcName, srcFlags, srcRaidFlags, dstGUID, dstName, dstFlags, dstRaidFlags, ...)
  2.     print(event) -- for debugging
  3.     if (event == "UNIT_DIED") then
  4.         print("UNIT_DIED")
  5.     end
  6. end
  7.  
  8. -----------------
  9. --EVENT HANDLER--
  10. -----------------
  11. frame:SetScript("OnEvent", function(self, event, ...)
  12.     events[event](self, ...)
  13. end)
  14.  
  15. for k, v in pairs(events) do
  16.     frame:RegisterEvent(k)
  17. end

Also semi-colons are essentially just for looks, so unless you really like them the only time I would bother is to prevent ambiguity.

One more thing, NEVER do var = select(1, ...), it's literally the same thing as var = ... except with the overhead of a function call.
  Reply With Quote