Thread Tools Display Modes
08-30-12, 04:29 PM   #1
wolftech
A Deviate Faerie Dragon
Join Date: May 2008
Posts: 14
KG Panels/LDB Plugin help

I have kg panels that I am setting up for the addon Broker_StatsNow. The addon is broken down into sub addons (Spells, Ranged, Melee, Tank, PVP) and each of those has a LDB display for each stat. (I am using StatBlockCore as my LDB display). I have it set up so the panel shows only in combat and it hides the ldb plugins when the panel isn't visible. This works great, as long as the ldb plugins are active. When they are not, I get this error.(I only have 2 set up so far... one for spells and one for ranged stats)

Code:
1x <string>:"ranged_OnEvent":13: attempt to index global "StatBlockCore_RangeAP" (a nil value)
<string>:"ranged_OnEvent":13: in function <string>:"ranged_OnEvent":1

Locals:
I get one for StatBlockCore_SpellPower if I am on my hunter and the spell stats are inactive.

The panels are not parented to the addons because when I try, I get a warning about a loop and it breaks.

Here is how they are scripted:

On Load:
Lua Code:
  1. local _,class = UnitClass("player")
  2.  
  3. self:SetBackdropBorderColor(RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b)
  4.  
  5. self:RegisterEvent("PET_BATTLE_OPENING_START")
  6. self:RegisterEvent("PET_BATTLE_CLOSE")
  7. self:RegisterEvent("PLAYER_REGEN_DISABLED")
  8. self:RegisterEvent("PLAYER_REGEN_ENABLED")
  9. self:RegisterEvent("PLAYER_ENTERING_WORLD")
  10. self:Hide()

On Event:
Lua Code:
  1. if event == "PET_BATTLE_OPENING_START" then
  2.   self:Hide()
  3. elseif event == "PET_BATTLE_CLOSE" then
  4.   self:Show()
  5. end
  6.  
  7. if event == "PLAYER_REGEN_ENABLED" then
  8.   self:Hide()
  9. elseif event == "PLAYER_REGEN_DISABLED" then
  10.   self:Show()
  11. end
  12.  
  13. StatBlockCore_RangeAP:SetParent(kgPanels:FetchFrame("ranged"))
  14. StatBlockCore_RangeCrit:SetParent(kgPanels:FetchFrame("ranged"))
  15. StatBlockCore_RangeHaste:SetParent(kgPanels:FetchFrame("ranged"))
  16. StatBlockCore_RangeMastery:SetParent(kgPanels:FetchFrame("ranged"))

It is scripted the exact same way for the spells (except using the LDB plugin frame names for spell stats). I also tried making the script dependent on the addon but that didn't work either.
  Reply With Quote
08-30-12, 07:35 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
As the error message indicates, you need to check that StatBlockCore_RangeAP exists before trying to do something with it.

Change your code from:
Code:
StatBlockCore_RangeAP:SetParent(kgPanels:FetchFrame("ranged"))
StatBlockCore_RangeCrit:SetParent(kgPanels:FetchFrame("ranged"))
StatBlockCore_RangeHaste:SetParent(kgPanels:FetchFrame("ranged"))
StatBlockCore_RangeMastery:SetParent(kgPanels:FetchFrame("ranged"))
to:
Code:
if StatBlockCore_RangeAP then
     StatBlockCore_RangeAP:SetParent(kgPanels:FetchFrame("ranged"))
end
if StatBlockCore_RangeCrit then
    StatBlockCore_RangeCrit:SetParent(kgPanels:FetchFrame("ranged"))
end
if StatBlockCore_RangeHaste then
    StatBlockCore_RangeHaste:SetParent(kgPanels:FetchFrame("ranged"))
end
if StatBlockCore_RangeMastery then
    StatBlockCore_RangeMastery:SetParent(kgPanels:FetchFrame("ranged"))
end
or this less repetitive and more easily extensible version:
Code:
local frameNames = {
    "StatBlockCore_RangeAP",
    "StatBlockCore_RangeCrit",
    "StatBlockCore_RangeHaste",
    "StatBlockCore_RangeMastery",
}

local panelFrame = kgPanels:FetchFrame("ranged")

for i = 1, #frameNames do
    local frameName = frameNames[i]
    if _G[frameName] then
        _G[frameName]:SetParent(panelFrame)
    end
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 08-31-12 at 07:44 PM.
  Reply With Quote
08-31-12, 11:45 AM   #3
wolftech
A Deviate Faerie Dragon
Join Date: May 2008
Posts: 14
Thanks Phanx. That first code change fixed the errors (for some reason, it didn't like the more compact version, but I don't mind the extra code as long as it works).

Now I just need to change my show on combat scripting so that it doesn't spawn the panel at all if the addons for it are not present. I will try making it dependent on the addon first, if that doesn't work, then I simple if then should do the trick. I might be back though, if I can't get it sorted
  Reply With Quote
08-31-12, 07:44 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
There was an error in the code in my last post; it's fixed now.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » KG Panels/LDB Plugin help


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