When I say "the rest of your code" I really mean "the rest of your code", as in,
all of your code. The snippets you posted are not enough; for example, one of the snippets you posted is referring to a function that is not defined in any of the snippets you posted, and none of the snippets provide any context whatsoever.
Assuming your current code matches the file I downloaded from the page you linked, there are several issues with your arrow code:
1. You have duplicate functions for every unit, which is wasteful and unnecessary; you can get the frame's current unit via
self.unit and do not need to hardcode the unit into the function.
2. You are potentially creating a new table every time you color the arrow texture, which is also wasteful and unnecessary. Define the default color once, outside of the functions, and then refer to it when needed.
lib.lua:
Code:
local arrow = {[[Interface\Addons\oUF_Fail\media\textureArrow]]}
local arrowDefaultColor = {.3,.45,.65}
lib.setPowerArrowColor = function(self)
local _, powerType = UnitPowerType(self.unit)
self.Power.arrow:SetVertexColor(unpack(oUF.colors.power[powerType] or arrowDefaultColor))
end
lib.setClassArrowColor = function(self)
local _, class = UnitClass(self.unit)
self.Power.arrow:SetVertexColor(unpack(oUF.colors.class[class] or arrowDefaultColor))
end
As for the rest, this (core.lua, line 91) won't work:
Code:
self.Power.arrow.PostUpdate = lib.setPowerArrowColor
...because self.Power.arrow is not an actual oUF element. If you change it to:
Code:
self.Power.PostUpdate = lib.setPowerArrowColor
...it will probably work as desired without the need for anything like this:
Code:
self:RegisterEvent("PLAYER_LOGIN", lib.setPowerArrowColor)
self:RegisterEvent("PLAYER_ENTERING_WORLD", lib.setPowerArrowColor)
self:RegisterEvent("UNIT_DISPLAYPOWER", lib.setPowerArrowColor)
...since oUF will then automatically update the arrow any time the power bar is updated.
On a side note, whatever layout you based your code on (I'm guessing the mis-named oUF "Simple") is pretty unreadable. There's no consistency in naming conventions at all, related functions are in totally separate files, there's tons of duplication, tons of inefficient and wasteful code, etc. It's pretty bad.