View Single Post
01-12-15, 12:38 AM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,330
It depends on what your overall goal is. If you think you need an event frame that your other addon files need to access, you can store a pointer to it in the addon table. I would suggest using more meaningful names than just f. It will help when you decide to look at this code again later in the future.



This is what I suggest:
lua Code:
  1. local name,addon=...;
  2. addon.EventFrame=CreateFrame("Frame");

- and -
lua Code:
  1. local name,addon=...;
  2. addon.EventFrame:RegisterEvent("PLAYER_LOGIN");
  3. addon.EventFrame:HookScript("OnEvent",function(self,event,...)
  4.     if event=="PLAYER_LOGIN" then
  5. --      More stuff here
  6.     end
  7. end);

The key points are using Frame:HookScript() since this might not be your only file using the frame. As such, it would be wise to check if we're working on the event we want. Since you're sharing this frame with your other files, the frame will also run the script for events your other files register for.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 01-12-15 at 12:51 AM.
  Reply With Quote