i'm getting into creating my first WoW addon and during my research I have read that every frame creaated in WoW is global which really confuses me.
I've seen plenty of addons that just do f = CreateFrame(..), so wouldn't those be conflicting all the time?
There's probably an easy explanation for this so sorry if the question is a bit dumb but if someone could clear that up for me I would really appreciate it
Every frame created from an XML file is global so that they can be accessed from a Lua file.
## Interface: 90205
## Version: 1.0.0
## Title: Hello
hello.xml
<Ui>
<Script file="hello.lua"/>
<Frame name="HelloWorldFrame"> <!-- global frame -->
<Scripts>
<OnLoad>
HelloWorld_OnLoad(self)
</OnLoad>
<OnEvent>
HelloWorld_OnEvent(self, event, ...)
</OnEvent>
</Scripts>
</Frame>
</Ui>
function HelloWorld_OnLoad(self)
print("Loaded HelloWorldFrame")
self:RegisterEvent("CHAT_MSG_SAY")
end
function HelloWorld_OnEvent(self, event, ...)
print("Your character said something", event, ...)
end
While if you only use a Lua file and create your frame there you don't necessarily need to make it global.
local function OnEvent(self, event, ...)
print("Your character said something", event, ...)
end
local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_SAY")
f:SetScript("OnEvent", OnEvent)
I've seen plenty of addons that just do f = CreateFrame(..), so wouldn't those be conflicting all the time?
As long as they make it local, they wouldn't conflict. If everyone makes a global f
frame then it would conflict yes.