Thread: Inverted health
View Single Post
12-11-14, 05:06 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by MoonWitch View Post
Lua Code:
  1. local hpbar = self:CreateStatusbar(nil, 'Frame')
  2. self.Health = hpbar
or
Lua Code:
  1. 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.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote