View Single Post
05-03-17, 02:23 AM   #16
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
That looks confusing to me.

You can blend Ace3 and vanilla WoW code easily enough.
Lua Code:
  1. function Currency:OnInitialize()
  2.     Currency.eventFrame = CreateFrame("Frame") -- OnInit only fires once, so creating frames and setting their parameters here would be a good idea    
  3. end
  4.  
  5. function Currency:OnEnable()
  6.     -- mimic AceEvent without the callback or extra arg
  7.     -- basic functionality, but it works
  8.     -- you also gain RegisterUnitEvent yay!!
  9.     Currency.eventFrame:SetScript("OnEvent", function(self, event, ...)
  10.         Currency[event](Currency, ...) -- notice the change on this line?
  11.     end)
  12.  
  13.     Currency.eventFrame:RegisterEvent("SOME_EVENT")
  14.     Currency.eventFrame:RegisterEvent("ANOTHER_EVENT")
  15.     Currency.eventFrame:RegisterUnitEvent("PLAYER_EVENT", "player", "target")
  16. end
  17.  
  18. function Currency:OnDisable()
  19.     Currency.eventFrame:UnregisterAllEvents()
  20. end
  21.  
  22. function Currency:SOME_EVENT()
  23.     -- do something
  24. end
  25.  
  26. -- etc
  27. -- etc
Here are some issues I have with your InitObjects()
  • It is not a local function, but should be
  • You have some things in there that should be done only once, like creating frames, which is presumably good, yet there are other things that ought to be handled multiple times like registering events
  • Nothing wrong with having your event handlers inside that function, but it doesn't look easy to debug in a year or two

Last edited by myrroddin : 05-03-17 at 02:25 AM.
  Reply With Quote