View Single Post
04-06-13, 06:33 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Resike View Post
Honestly i don't need the "PVPSound" table for nothing, just to bypass local functions between files.
Just use dot notation instead of colon notation to avoid confusion:

Code:
local _, ns = ...

function ns.FancyPrint(caller, ...)
   print("MyAddon:", ...)
end

local frame = CreateFrame("Frame")
frame:RegisterEvent("UNIT_AURA")
frame:SetScript("OnEvent", ns.FancyPrint)
-- will print, for example, "MyAddon: UNIT_AURA player")
Other file:
Code:
local _, ns = ...
ns.FancyPrint(nil, "Hello world!")
-- will print ("MyAddon: Hello world!")
The (probably more sensible) alternative would be to define script handlers directly in the SetScript call:

Code:
PVPSoundEffectSoundEngineFrame:SetScript("OnUpdate", function(self, elapsed)
     -- stuff goes on here
end)
The only reason to define the script handler function separately would be if you planned to call the same function from other places, or you wanted multiple frames to use the same event handler function, etc.

Also, when you set a list of variables with the same name, when you're done, there is only one copy of the variable, and it contains the last value set:

Code:
local var, var, var, var = 1, 2, "cat", "dog"
print(var) -> "dog"
So:

Code:
function object:method(self)
    print(self)
end
object:method("lolcats") -> "lolcats"
... because it's equivalent to:

Code:
function objec*****thod(self, self)
    print(self)
end
__________________
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.

Last edited by Phanx : 04-06-13 at 06:35 PM.
  Reply With Quote