Originally Posted by MoonWitch
Lua Code:
local hpbar = self:CreateStatusbar(nil, 'Frame') self.Health = hpbar
or
Lua Code:
self.Health = self:CreateStatusbar(nil, 'Frame')
|
Well, other than this almost certainly not being valid:
Code:
self:CreateStatusbar(nil, 'Frame')
... both of those achieve the same result once your spawn function is done. The main advantage of the first style is that you avoid performing the same table lookup over and over when you set the position, size, and other properties of the health bar, eg:
Code:
local hpbar = CreateFrame("StatusBar", nil, self)
hpbar:SetPoint("TOPLEFT", self, "TOPLEFT", 1, -1)
hpbar:SetPoint("TOPRIGHT", self, "TOPRIGHT", -1, -1)
hpbar:SetPoint("BOTTOM", self, "BOTTOM", 0, 1)
hpbar:GetStatusBarTexture():SetDrawLayer("ARTWORK")
hpbar.colorClass = true
hpbar.colorReaction = true
hpbar.bg.multiplier = 0.3
hpbar.frequentUpdates = true
hpbar.PostUpdate = addon.Health_PostUpdate
self.Health = hpbar
Using a local variable saves you 9 table lookups in this example, in addition to the typing.