Originally Posted by Phanx
Not necessarily. Just be consistent. The reason "self" is so popular is that -- partly because it's so popular -- immediately recognizable. When you're reading someone else's code and you see a variable named "self" you know right away that it's a reference to whatever object "owns" the function, so it's not confusing that "self" in different parts of the code refers to different things.
But if you see "frame" at the top of a function, and then jump down 10 lines inside the same function and see "frame" again, it would be insane to assume it referred to something other than what the first "frame" referred to. And if you're looking at a unit frame addon and you see a variable named "frame" it's kind of automatic to assume it's referring to a unit frame, which is why I suggested "element" as an alternative here.
|
Ah okey! Then I don't have to think about that
Did change the "frame" in the bar_OnUpdate function to element , no diffrence. I have no clue how to continue with this now
With the changes you posted:
Part above the Spawn function.
Code:
-- Aura Bars
local BUFF_HEIGHT = 20
local function bar_OnUpdate(frame, elapsed)
local t = frame.timeLeft - elapsed
frame:SetValue(t > 0 and t or 0)
frame.timeLeft = t
end
local function auras_PostCreateIcon(element, icon)
local frame = element.__owner
local bar = CreateFrame("StatusBar", nil, icon)
bar:SetPoint("LEFT", icon, "RIGHT")
bar:SetWidth(frame:GetWidth() - BUFF_HEIGHT)
bar:SetHeight(BUFF_HEIGHT)
bar:SetStatusBarTexture("Interface\\AddOns\\oUF_Kygo\\Media\\Neal")
bar:SetStatusBarColor(0, 0.6, 0)
local bg = bar:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints(true)
bg:SetTexture("Interface\\AddOns\\oUF_Kygo\\Media\\Neal")
bg:SetVertexColor(0, 0.2, 0)
bar.bg = bg
bar.timeLeft = 0
bar:SetMinMaxValues(0, 1)
bar:SetScript("OnUpdate", bar_OnUpdate)
icon.bar = bar
end
And the part below the Spawn function:
Did try to change "frame.Buffs = Auras" to "element.buffs = Auras" and same with the "Debuffs = Auras" only to see if it threw the "nil" error I expected.
Code:
---------------------------------
-- Aurabars --
---------------------------------
if unit == "player" or unit == "target" then
local Auras = CreateFrame("Frame", nil, element)
Auras:SetPoint("BOTTOMLEFT", frame, "TOPLEFT", 0, 10)
Auras:SetWidth(BUFF_HEIGHT) -- no, Width/HEIGHT is not a mistake
Auras["initialAnchor"] = "BOTTOMLEFT"
Auras["growth-y"] = "UP"
Auras["spacing-y"] = 1 -- 1px gap between bars, adjust as desired
Auras["num"] = 10 -- limit to showing 5 bars, adjust as desired
Auras["size"] = BUFF_HEIGHT
Auras.PostCreateIcon = auras_PostCreateIcon
if unit == "player" then
function Auras:CustomFilter(unit, icon, name, rank, texture, count, debuffType, duration, timeLeft, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff)
if duration < 30 then
icon.bar.timeLeft = timeLeft
icon.bar:SetMinMaxValues(0, duration)
icon.bar:SetValue(timeLeft)
return true
end
end
frame.Buffs = Auras
elseif unit == "target" then
function Auras:CustomFilter(unit, icon, name, rank, texture, count, debuffType, duration, timeLeft, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff)
if canApplyAura then
icon.bar.timeLeft = timeLeft
icon.bar:SetMinMaxValues(0, duration)
icon.bar:SetValue(timeLeft)
return true
end
end
frame.Debuffs = Auras
end
end