WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Getting error spammed from a small addon. Can anyone help? (https://www.wowinterface.com/forums/showthread.php?t=52759)

Lesteryoung 09-20-15 10:50 PM

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


semlar 09-20-15 11:49 PM

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.

Lesteryoung 09-21-15 12:04 AM

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


semlar 09-21-15 12:09 AM

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

Lesteryoung 09-21-15 12:15 AM

Thank you very much.


All times are GMT -6. The time now is 07:00 AM.

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