Thread Tools Display Modes
09-20-15, 10:50 PM   #1
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
Getting error spammed from a small addon. Can anyone help?

Aforementioned error:

1x Tweaks\UnitColor.lua:10: attempt to index global 'c' (a nil value)
Tweaks\UnitColor.lua:10: in function <Tweaks\UnitColor.lua:7>
[C]: in function `TargetUnit'
FrameXML\SecureTemplates.lua:513: in function `handler'
FrameXML\SecureTemplates.lua:649: in function `SecureActionButton_OnClick'
FrameXML\SecureTemplates.lua:689: in function <FrameXML\SecureTemplates.lua:681>

Locals:
(*temporary) = "raid29"
(*temporary) = "PLAYER_TARGET_CHANGED"
(*temporary) = "PLAYER_TARGET_CHANGED"
(*temporary) = <function> defined =[C]:-1

This is the addon:

Code:
local frame = CreateFrame("FRAME")
frame:RegisterEvent("GROUP_ROSTER_UPDATE")
frame:RegisterEvent("PLAYER_TARGET_CHANGED")
frame:RegisterEvent("PLAYER_FOCUS_CHANGED")
frame:RegisterEvent("UNIT_FACTION")

local function eventHandler(self, event, ...)
        if UnitIsPlayer("target") then
                c = RAID_CLASS_COLORS[select(2, UnitClass("target"))]
                TargetFrameNameBackground:SetVertexColor(c.r, c.g, c.b)
        end
        if UnitIsPlayer("focus") then
                c = RAID_CLASS_COLORS[select(2, UnitClass("focus"))]
                FocusFrameNameBackground:SetVertexColor(c.r, c.g, c.b)
        end
end

frame:SetScript("OnEvent", eventHandler)

for _, BarTextures in pairs({TargetFrameNameBackground, FocusFrameNameBackground}) do
        BarTextures:SetTexture("Interface\\TargetingFrame\\UI-StatusBar")
end
  Reply With Quote
09-20-15, 11:49 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
That error shouldn't be possible, is this on the live version of the game?

Regardless, just add "if c then ... end" around both of your SetVertexColor lines, and put "local" in front of "c = RAID_CLASS_COLORS" because there's no reason for that to be global.
  Reply With Quote
09-21-15, 12:04 AM   #3
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
Like this?

Code:
local function eventHandler(self, event, ...)
        if UnitIsPlayer("target") then
              local if then c = RAID_CLASS_COLORS[select(2, UnitClass("target"))] end
                TargetFrameNameBackground:SetVertexColor(c.r, c.g, c.b)
        end
        if UnitIsPlayer("focus") then
              local if then c = RAID_CLASS_COLORS[select(2, UnitClass("focus"))] end
                FocusFrameNameBackground:SetVertexColor(c.r, c.g, c.b)
        end
end
  Reply With Quote
09-21-15, 12:09 AM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Lua Code:
  1. local frame = CreateFrame("FRAME")
  2. frame:RegisterEvent("GROUP_ROSTER_UPDATE")
  3. frame:RegisterEvent("PLAYER_TARGET_CHANGED")
  4. frame:RegisterEvent("PLAYER_FOCUS_CHANGED")
  5. frame:RegisterEvent("UNIT_FACTION")
  6.  
  7. local function eventHandler(self, event, ...)
  8.         if UnitIsPlayer("target") then
  9.                 local c = RAID_CLASS_COLORS[select(2, UnitClass("target"))]
  10.                 if c then
  11.                     TargetFrameNameBackground:SetVertexColor(c.r, c.g, c.b)
  12.                 end
  13.         end
  14.         if UnitIsPlayer("focus") then
  15.                 local c = RAID_CLASS_COLORS[select(2, UnitClass("focus"))]
  16.                 if c then
  17.                     FocusFrameNameBackground:SetVertexColor(c.r, c.g, c.b)
  18.                 end
  19.         end
  20. end
  21.  
  22. frame:SetScript("OnEvent", eventHandler)
  23.  
  24. for _, BarTextures in pairs({TargetFrameNameBackground, FocusFrameNameBackground}) do
  25.         BarTextures:SetTexture("Interface\\TargetingFrame\\UI-StatusBar")
  26. end
  Reply With Quote
09-21-15, 12:15 AM   #5
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
Thank you very much.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Getting error spammed from a small addon. Can anyone 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