Thread Tools Display Modes
Prev Previous Post   Next Post Next
07-04-12, 06:34 AM   #11
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
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:
  1. local F, C, L = unpack(select(2, ...))
  2.  
  3. if C.general.buffreminder == false then return end
  4.  
  5. local class = select(2, UnitClass("Player"))
  6. local buffs = C.selfbuffs[class]
  7.  
  8. if buffs and buffs[1] then
  9.     local frame = CreateFrame("Frame", nil, UIParent)
  10.     local a1, p, a2, x, y = unpack(C.unitframes.target)
  11.     frame:SetPoint(a1, p, a2, x, y+90)
  12.     frame:SetSize(57, 57)
  13.    
  14.     frame.icon = frame:CreateTexture(nil, "ARTWORK")
  15.     frame.icon:SetTexCoord(.08, .92, .08, .92)
  16.     frame.icon:SetAllPoints(frame)
  17.     frame.icon:SetTexture("Interface\\Icons\\Spell_Holy_InnerFire")
  18.     print(frame.icon:GetTexture()) -- returns texture
  19.  
  20.     F.CreateBG(frame)
  21.  
  22.     frame:Hide()
  23.    
  24.     frame:RegisterEvent("UNIT_AURA")
  25.     frame:RegisterEvent("PLAYER_LOGIN")
  26.     frame:RegisterEvent("PLAYER_REGEN_ENABLED")
  27.     frame:RegisterEvent("PLAYER_REGEN_DISABLED")
  28.    
  29.     frame:SetScript("OnEvent", function(self, event)
  30.         if (event == "PLAYER_LOGIN" or event == "LEARNED_SPELL_IN_TAB") then
  31.             for i, buff in pairs(buffs) do
  32.                 local name = GetSpellInfo(buff)
  33.                 local usable, nomana = IsUsableSpell(name)
  34.                 if (usable or nomana) then
  35.                     -- this makes no difference: frame.icon:SetTexture("Interface\\Icons\\Spell_Holy_InnerFire")
  36.                     print(frame.icon:GetTexture()) -- returns nil
  37.                     self.hasTexture = true
  38.                     break
  39.                 end
  40.             end
  41.             if (not self.hasTexture and event == "PLAYER_LOGIN") then
  42.                 self:UnregisterAllEvents()
  43.                 self:RegisterEvent("LEARNED_SPELL_IN_TAB")
  44.                 return
  45.             elseif (self.hasTexture and event == "LEARNED_SPELL_IN_TAB") then
  46.                 self:UnregisterAllEvents()
  47.                 self:RegisterEvent("UNIT_AURA")
  48.                 self:RegisterEvent("PLAYER_LOGIN")
  49.                 self:RegisterEvent("PLAYER_REGEN_ENABLED")
  50.                 self:RegisterEvent("PLAYER_REGEN_DISABLED")
  51.             end
  52.         end
  53.         if (UnitAffectingCombat("player") and not UnitInVehicle("player")) then
  54.             for i, buff in pairs(buffs) do
  55.                 local name = GetSpellInfo(buff)
  56.                 if (name and UnitBuff("player", name)) then
  57.                     self:Hide()
  58.                     return
  59.                 end
  60.             end
  61.             self:Show()
  62.         else
  63.             self:Hide()
  64.         end
  65.     end)
  66. 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.

Last edited by Haleth : 07-04-12 at 06:42 AM.
 
 

WoWInterface » Site Forums » Archived Beta Forums » MoP Beta archived threads » Beta API discussion


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off