help with code
Why does not this code work?
local addon = CreateFrame("Frame", nil, UIParent)
-- frame
local frame_anchor = "BOTTOMLEFT"
local frame_x = 750
local frame_y = 400
-- font
local font = "Fonts\\SKURRI.ttf"
local size = 14
local outline = false
local shadow = false
local text_anchor = "BOTTOMLEFT"
-- used locals
local text, pvalue
-- new
function addon:new()
-- frame position
self:SetPoint(frame_anchor, UIParent, frame_anchor, frame_x, frame_y)
self:SetWidth(40)
self:SetHeight(11)
-- create fontstring
text = self:CreateFontString(nil, "OVERLAY")
- text style
if outline == true then
text:SetFont(font, size, "THINOUTLINE")
else
text:SetFont(font, size, nil)
end
text:SetPoint(text_anchor, self)
self:RegisterEvent("UNIT_HEALTH")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PLAYER_LOGIN")
-- update
self:SetScript("OnUpdate", self.update)
self:SetScript("OnEvent", self.event)
end
function addon:event()
if (event == "UNIT_HEALTH") then
pvalue:SetText(floor(((UnitHealth("player") / UnitHealthMax("player"))*100)+5).."%")
elseif event == "PLAYER_ENTERING_WORLD" then
pvalue:SetText(floor(((UnitHealth("player") / UnitHealthMax("player"))*100)+5).."%")
elseif event == "PLAYER_LOGIN" then
pvalue:SetText(floor(((UnitHealth("player") / UnitHealthMax("player"))*100)+5).."%")
end
end
-- update function
function addon:update()
-- set it
text:SetText(pvalue)
end
-- fire
addon:new()
Last edited by saxitoxin : 08-26-09 at 03:20 PM.
Reason: been trying to do that, aint happen srry
|