Originally Posted by SDPhantom
If the data is unrelated to each other, yes. I don't know the code that you're trying to use this method for, so I can't state any more specific ways to make your code efficient. As for any rule of thumb, there can be and often are exceptions.
|
I'm creating two FontStrings to display timers. The event that updates them fires ~every second. To not overwrite them if nothing changed, I'm caching their state, also in two local vars.
lua Code:
local BGtext = {
MiniMapBattlefieldFrame:CreateFontString(nil,nil,"GameFontNormal"),
MiniMapBattlefieldFrame:CreateFontString(nil,nil,"GameFontNormal")
}
local laststatus = {"",""}
BGtext[1]:SetPoint("RIGHT",MiniMapBattlefieldFrame,"LEFT")
BGtext[2]:SetPoint("TOPRIGHT",BGtext[1],"BOTTOMRIGHT")
MiniMapBattlefieldFrame:RegisterEvent("UPDATE_BATTLEFIELD_STATUS")
MiniMapBattlefieldFrame:SetScript("OnEvent",function(s,e,a)
if e == "UPDATE_BATTLEFIELD_STATUS" then
for i=1,2 do
local status, map = GetBattlefieldStatus(i)
if status == "queued" then
BGtext[i]:SetText(MySecondsToTime((GetBattlefieldEstimatedWaitTime(i)-GetBattlefieldTimeWaited(i))/1000))
else
if status ~= laststatus[i] then
laststatus[i] = status
if status == "confirm" then
BGtext[i]:SetText(map)
else
BGtext[i]:SetText("")
end
end
end
end
end
end)
Originally Posted by Torhal
If you need such a construct for local variables, you're probably structuring your code incorrectly; scoping is a logical tool, not something to be avoided.
|
The scope ain't a problem, it's just the fact, that I cannot access the variables the way I need/want to. I could have avoided this problem by simply declaring all 4 vars as globals, but that would have been the wrong way as far as I know.