Zork; That also sets the texture but still returns nil.
I've looked at it some further and it seems to be some sort of problem with OnEvent. This is my modified code with a few tests in it:
Lua Code:
local F, C, L = unpack(select(2, ...))
if C.general.buffreminder == false then return end
local class = select(2, UnitClass("Player"))
local buffs = C.selfbuffs[class]
if buffs and buffs[1] then
local frame = CreateFrame("Frame", nil, UIParent)
local a1, p, a2, x, y = unpack(C.unitframes.target)
frame:SetPoint(a1, p, a2, x, y+90)
frame:SetSize(57, 57)
frame.icon = frame:CreateTexture(nil, "ARTWORK")
frame.icon:SetTexCoord(.08, .92, .08, .92)
frame.icon:SetAllPoints(frame)
frame.icon:SetTexture("Interface\\Icons\\Spell_Holy_InnerFire")
print(frame.icon:GetTexture()) -- returns texture
F.CreateBG(frame)
frame:Hide()
frame:RegisterEvent("UNIT_AURA")
frame:RegisterEvent("PLAYER_LOGIN")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:SetScript("OnEvent", function(self, event)
if (event == "PLAYER_LOGIN" or event == "LEARNED_SPELL_IN_TAB") then
for i, buff in pairs(buffs) do
local name = GetSpellInfo(buff)
local usable, nomana = IsUsableSpell(name)
if (usable or nomana) then
-- this makes no difference: frame.icon:SetTexture("Interface\\Icons\\Spell_Holy_InnerFire")
print(frame.icon:GetTexture()) -- returns nil
self.hasTexture = true
break
end
end
if (not self.hasTexture and event == "PLAYER_LOGIN") then
self:UnregisterAllEvents()
self:RegisterEvent("LEARNED_SPELL_IN_TAB")
return
elseif (self.hasTexture and event == "LEARNED_SPELL_IN_TAB") then
self:UnregisterAllEvents()
self:RegisterEvent("UNIT_AURA")
self:RegisterEvent("PLAYER_LOGIN")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
end
end
if (UnitAffectingCombat("player") and not UnitInVehicle("player")) then
for i, buff in pairs(buffs) do
local name = GetSpellInfo(buff)
if (name and UnitBuff("player", name)) then
self:Hide()
return
end
end
self:Show()
else
self:Hide()
end
end)
end
Setting the texture on frame.icon, then calling GetTexture(), returns the texture. However, calling GetTexture in the OnEvent code returns nil - whether or not I set the texture again, there.
I've added a boolean hasTexture to work around the GetTexture() problem, but it's very strange.