You don't tell us what the Set and Get functions are doing (setting the colours I'm guessing at here). Also, OnEvent and OnUpdate are two different scripts to do two different things. The game will trigger health update events which might be better in this situation than using OnUpdate which will cycle far more often than health gets updated (especially out of combat).
Something like:
Lua Code:
local function GetPlayerHealth(unit)
local max = UnitHealthMax(unit)
local health = UnitHealth(unit)
--local r, g, b = ...
-- do the math, get the colours
return r, g, b
end
local function SetPlayerHealth(self, r, g, b)
self.texture:SetVertexColor(r, g, b)
end
local frame = CreateFrame("Frame", k, UIParent)
frame:SetPoint("TOPLEFT", x, heightFromCorner)
frame:SetHeight(BOX_SIZE)
frame:SetWidth(BOX_SIZE)
frame.texture = frame:CreateTexture()
frame.texture:SetAllPoints(frame)
frame.texture:SetTexture("Interface/BUTTONS/WHITE8X8")
--frame.texture:SetColorTexture(1,1,1,1)
frame:SetScript("OnEvent", function(self, event, ...)
-- don't need to check for the event type because only one is registered.
local unit = ...
if unit == "player" then
SetPlayerHealth(self, GetPlayerHealth(unit))
end
end)
frame:RegisterEvent("UNIT_HEALTH_FREQUENT")
SetPlayerHealth(frame, GetPlayerHealth("player")) -- set initial colours