Originally Posted by Resike
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