Stop doing this:
Lua Code:
_G["ChatFrame1"]:Hide() -- NO!
Just do this:
Lua Code:
ChatFrame1:Hide() -- YES!
Adding the extra _G lookup just makes your code more cluttered to read, and slower to run. The only reason to use a _G lookup is if you are dynamically construting a name that is not constant or known ahead of time, eg. in a loop:
Lua Code:
for i = 1, 10 do
_G["ChatFrame"..i]:SetFont("Fonts\\FRIZQT__.ttf", 16, "OUTLINE")
end
Also, don't do this (whoever suggested this solution, just... no, and stop using Blizzard's UI code as your guide; most of it is obviously written by people who are not familiar with Lua programming -- there's even a place where they do ~30 if/else checks to uppercase a string instead of just calling
string.upper FFS):
Lua Code:
local oEvents = {
"GOSSIP_SHOW",
"BANKFRAME_OPENED",
"GUILDBANKFRAME_OPENED"
}
if tContains(oEvents,event) then
This is quite possibly
THE most inefficient way you could achieve this goal. First, you are creating a new table every time an event fires. This is a total waste of memory, and wastes CPU cycles on garbage collection. Second, you are adding a function call (which is one of the slowest, if not
the slowest, single action you can perform in Lua) and looping over your entire table, instead of just structuring your table correctly for your purpose in the first place.
You should just do this instead:
Lua Code:
if event == "GOSSIP_SHOW"
or event == "BANKFRAME_OPENED"
or event == "GUILDBANKFRAME_OPENED"
then
(You can put it all one line if you want; I just included the line breaks to keep it more readable in the tiny boxes kgPanels provides for code entry.)
If you end up checking more events, using a table might be worthwhile, but please do it the
right way. Put the table in your OnLoad script so it's only created
once, and structure it correctly (hash table, not array):
Lua Code:
self.openEvents = {
GOSSIP_SHOW = true,
BANKFRAME_OPENED = true,
GUILDBANKFRAME_OPENED = true,
}
Then refer to it in your OnEvent script:
Lua Code:
if self.openEvents[event] then