Quantcast Handler callback function stops working, why? - WoWInterface
Thread Tools Display Modes
05-13-18, 06:58 PM   #1
A Murloc Raider
Join Date: Feb 2016
Posts: 5
Handler callback function stops working, why?

Can someone explain to me why this doesn't work? Do hidden frames not execute "OnUpdate" script handler? I am confused. This is an extremely simple UI addon which shows an icon on target/focus if they're in combat or not in combat. I localized each function for each handler, but it seems that once the frame is hidden, it can't execute the callback anymore. Why?

Lua Code:
  1. --combat script
  2. local UnitAffectingCombat = UnitAffectingCombat;
  4. local TargetCombatFrame=CreateFrame("Frame")
  5. TargetCombatFrame:SetParent(TargetFrame)
  6. TargetCombatFrame:SetPoint("LEFT",TargetFrame,"RIGHT",0,0)
  7. TargetCombatFrame:SetSize(35,35)
  8. TargetCombatFrame.t=TargetCombatFrame:CreateTexture(nil,BORDER)
  9. TargetCombatFrame.t:SetAllPoints()
  10. TargetCombatFrame.t:SetTexture("Interface\\Icons\\Ability_Sap")
  11. TargetCombatFrame:Show()
  13. local function FrameOnUpdate(self,elapsed)
  14.     print("test1")
  15.     if not UnitAffectingCombat("target") then
  16.         self:Show()
  17.     else
  18.         self:Hide()
  19.     end
  20. end
  21. TargetCombatFrame:SetScript("OnUpdate",FrameOnUpdate)
  23. local FocusCombatFrame=CreateFrame("Frame")
  24. FocusCombatFrame:SetParent(FocusFrame)
  25. FocusCombatFrame:SetPoint("RIGHT",FocusFrame,"LEFT",0,0)
  26. FocusCombatFrame:SetSize(35,35)
  27. FocusCombatFrame.t=FocusCombatFrame:CreateTexture(nil,BORDER)
  28. FocusCombatFrame.t:SetAllPoints()
  29. FocusCombatFrame.t:SetTexture("Interface\\Icons\\Ability_Sap")
  30. FocusCombatFrame:Show()
  32. local function FrameOnUpdate(self,elapsed)
  33.     print("test2")
  34.     if not UnitAffectingCombat("focus") then
  35.         self:Show()
  36.     else
  37.         self:Hide()
  38.     end
  39. end
  40. FocusCombatFrame:SetScript("OnUpdate",FrameOnUpdate)
  Reply With Quote
05-13-18, 08:42 PM   #2
I did that?
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 916
Hiding a frame stops the OnUpdate process until the frame is shown again. You could make it fully transparent.
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle and Move Pad Plus.
  Reply With Quote
05-19-18, 12:41 AM   #3
A Pyroguard Emberseer
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,732
Here's what I came up with as well as improving the code.

Lua Code:
  1. local UnitAffectingCombat=UnitAffectingCombat;
  2. local SecureButton_GetUnit=SecureButton_GetUnit;
  4. local Textures={};--    Texture object lookup table
  5. local function OnUpdate(self) Textures[self]:SetShown(UnitAffectingCombat(SecureButton_GetUnit(self))); end
  7. local function SetupCombatTexture(frame,...)--  Passes vararg to :SetPoint()
  8.     if not Textures[frame] then
  9.         local tex=frame:CreateTexture(nil,"BORDER");
  10.         tex:SetPoint(...);--    Set point from vararg
  11.         tex:SetSize(35,35);
  12.         tex:SetTexture("Interface\\Icons\\Ability_Sap");
  14.         Textures[frame]=tex;--  Store texture in our lookup table
  15.         frame:HookScript("OnUpdate",OnUpdate);--    Register our hook
  16.     end
  17. end
  19. SetupCombatTexture(TargetFrame,"LEFT",TargetFrame,"RIGHT");
  20. SetupCombatTexture(FocusFrame,"RIGHT",FocusFrame,"LEFT");

This simply creates textures on the existing frame you were attaching them to instead of making dynamic frames for that purpose. Since you can hook frame scripts using :SetHook(), there really isn't a need for extra frames for script handling. This also uses the fact that TargetFrame and FocusFrame inherit SecureUnitButtonTemplate, which allow using SecureButton_GetUnit() to get their set unit instead of hard-coding them. This will allow you to reuse the code for other frames that inherit the same template.
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
05-19-18, 01:43 AM   #4
A Murloc Raider
Join Date: Feb 2016
Posts: 5
Nice use of SecureButton_GetUnit, I didn't even know that existed. There's probably more API I don't know about.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Handler callback function stops working, why?

Thread Tools
Display Modes

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