WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Help with code to apply !Beautycase borders (https://www.wowinterface.com/forums/showthread.php?t=57818)

lerb 02-14-20 10:10 AM

Help with code to apply !Beautycase borders
 
Hello!

I'm scratching my head pretty badly trying to set up a simple (although advanced for me) addon to apply !Beautycase borders to various frames.
Right now I'm only focusing on Pitbull4 "player" and "target", as well as a custom panel created with kgPanels.
I got the frame names using the /fstack command, so I am sure they are correct.

Much appreciated if anyone would like to help me not go bald with this.

Here is the TOC for my addon:

Code:

## Interface: 80300
## Title: zBorders
## Notes: Module used by LerbUI to skin borders. Built upon and an extension of !Beautycase, created by Neav.
## Author: Lerb
## Dependencies: !Beautycase, Pitbull4, kgPanels, kgPanelsConfig
## Version: 8.3.0-1

zBorders.lua

And here is the code inside zBorders.lua:

Lua Code:
  1. local f = CreateFrame("Frame")
  2. f:RegisterEvent("VARIABLES_LOADED")
  3. f:RegisterEvent("ADDON_LOADED")
  4. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  5.  
  6. f:SetScript("OnEvent", function(self)
  7.  
  8.     -- Pitbull4 borders --
  9.  
  10.     if "Pitbull4" then
  11.         f:SetScript("OnUpdate", function(self)
  12.             for _, pitframes in pairs({
  13.                 PitBull4_Frames_Player,
  14.                 PitBull4_Frames_Target,
  15.             }) do
  16.                 if pitframes:IsShown() then
  17.                     pitframes:CreateBeautyBorder(14)
  18.                     pitframes:SetBeautyBorderPadding(3)
  19.                 end
  20.             end
  21.         end)
  22.     end
  23.  
  24.     -- kgPanels borders --
  25.    
  26.     if "kgPanelsConfig" then
  27.         kgPanel1:CreateBeautyBorder(14)
  28.         kgPanel1:SetBeautyBorderPadding(3)
  29.     end
  30.  
  31. end)


When I log on, I am presented with the error below (only one error, no "spam"), but all frames are actually skinned (border applied). Does this has something to do with load order? I thought setting dependencies would be enough for that.

**EDIT** If I remove the code for kgPanels, it works great (borders on Pitbull4, no errors), so it has something to do with those 4 lines of code is my guess.

**EDIT2** I've also tried using if IsAddOnLoaded("Pitbull4") then instead of just if "Pitbull4" then, but the results are exactly the same. I don't know which of these are the "norm" or the "best" to use?

Error (the lower one is from Bugger):

Code:

Message: Interface\AddOns\zBorders\zBorders.lua:27: attempt to index global 'kgPanel1' (a nil value)
Time: Fri Feb 14 17:08:34 2020
Count: 4
Stack: Interface\AddOns\zBorders\zBorders.lua:27: attempt to index global 'kgPanel1' (a nil value)
[string "@Interface\AddOns\zBorders\zBorders.lua"]:27: in function <Interface\AddOns\zBorders\zBorders.lua:6>

Locals: self = <unnamed> {
 0 = <userdata>
}
(*temporary) = nil
(*temporary) = nil
(*temporary) = "OnUpdate"
(*temporary) = 83914
(*temporary) = "attempt to index global 'kgPanel1' (a nil value)"
f = <unnamed> {
 0 = <userdata>
}

Bugger:

Code:

4x zBorders\zBorders-8.3.0-1.lua:27: attempt to index global 'kgPanel1' (a nil value)
[string "@zBorders\zBorders-8.3.0-1.lua"]:27: in function <zBorders\zBorders.lua:6>


Fizzlemizz 02-14-20 11:21 AM

Being a custom panel builder KG won't actually create panels until some deferred time (probably at PLAYER_ENTRING_WOLRD or possibly PLAYER_LOGIN)

ADDON_LOADED will fire for your addon and every addon that loads after that and well before PLAYER_ENTRING_WOLRD so KG is unlikely to have created any panels by then. VARIABLES_LOADED falls into the same early call problem and will add to the error count.

Your KG panels are most likely being skinned because your frame receives its PLAYER_ENTRING_WOLRD event after KG has done initial setup so it actually works that time.

lerb 02-14-20 12:19 PM

Quote:

Originally Posted by Fizzlemizz (Post 335141)
Being a custom panel builder KG won't actually create panels until some deferred time (probably at PLAYER_ENTRING_WOLRD or possibly PLAYER_LOGIN)

ADDON_LOADED will fire for your addon and every addon that loads after that and well before PLAYER_ENTRING_WOLRD so KG is unlikely to have created any panels by then. VARIABLES_LOADED falls into the same early call problem and will add to the error count.

Your KG panels are most likely being skinned because your frame receives its PLAYER_ENTRING_WOLRD event after KG has done initial setup so it actually works that time.

Thank you for the excellent explanation Fizzlemizz!

I removed the lines below and I am left with beautifully bordered frames, as well as no errors. Thanks!

What I removed:

Lua Code:
  1. f:RegisterEvent("VARIABLES_LOADED")
  2. f:RegisterEvent("ADDON_LOADED")

My code as of now for future reference to anyone searching for the same thing:

Lua Code:
  1. local f = CreateFrame("Frame")
  2. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  3.  
  4. f:SetScript("OnEvent", function(self)
  5.  
  6.     -- Pitbull4 borders --
  7.  
  8.     if IsAddOnLoaded("Pitbull4") then
  9.         f:SetScript("OnUpdate", function(self)
  10.             for _, pitframes in pairs({
  11.                 PitBull4_Frames_Player,
  12.                 PitBull4_Frames_Target,
  13.             }) do
  14.                 if pitframes:IsShown() then
  15.                     pitframes:CreateBeautyBorder(14)
  16.                     pitframes:SetBeautyBorderPadding(3)
  17.                 end
  18.             end
  19.         end)
  20.     end
  21.  
  22.     -- kgPanels borders --
  23.    
  24.     if IsAddOnLoaded("kgPanels") then
  25.         kgPanel1:CreateBeautyBorder(14)
  26.         kgPanel1:SetBeautyBorderPadding(0)
  27.         kgPanel2:CreateBeautyBorder(14)
  28.         kgPanel2:SetBeautyBorderPadding(0)
  29.         kgPanel3:CreateBeautyBorder(14)
  30.         kgPanel3:SetBeautyBorderPadding(0)
  31.         kgPanel4:CreateBeautyBorder(14)
  32.         kgPanel4:SetBeautyBorderPadding(0)
  33.     end
  34.  
  35. end)


All times are GMT -6. The time now is 04:11 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI