View Single Post
01-10-13, 05:50 AM   #11
Sauerkraut
A Wyrmkin Dreamwalker
 
Sauerkraut's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 52
Originally Posted by Phanx View Post
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.
Sorry I actually pasted a wrong section of code. I really appreciate the help Phanx however I could really do without the condescension. I've never claimed to be anything but a poor coder. My very basic understanding of lua allows me to make something that is functional and suits my tastes. I am not a programmer, just a guy that likes to tinker.
  Reply With Quote