Thread Tools Display Modes
11-05-13, 06:20 AM   #1
skarie
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 37
self.bugged

Hi all,

I am new to this oUF thing and need your help on this matter. I am trying to store a variable in self and to change it using PostUpdateHealth. But for some reason, I cant seem to make it work. Pls look at codes below:

--[[my postupdatehealth]]--
Code:
local PostUpdateHealth = function(Health, unit, min, max)
  local self = Health:GetParent()
  self.Ptext:SetText("b") -- <----self.Ptext is always nil ???????
end
--[[ init is called for every unit frame ]]--
Code:
local function init(self)
	self:RegisterForClicks('AnyUp')
	self:SetScript('OnEnter', UnitFrame_OnEnter)
	self:SetScript('OnLeave', UnitFrame_OnLeave)

	local Ptext = self:CreateFontString(nil,"OVERLAY")
	Ptext:SetFont( "Interface\\AddOns\\oUF_HL2\\ghostsmileys.ttf", 72, "OUTLINE")
	Ptext:SetTextColor(0.81, 0.86, 0.77)
	Ptext:SetText("a")
	self.Ptext = Ptext -- <---trying to store self.Ptext here.

end
--[[ target frame ]]--
Code:
local function CreateTarget(self)
   init(self) --
   --[[ omit codes to create Health.... etc]]
   self.Ptext:SetPoint("CENTER",self,"CENTER") -- <---self.Ptext is ok here 
   self.Health = Health
   self.Health.PostUpdate = PostUpdateHealth
end
I am getting an error saying self.Ptext is undefined. What do I miss? Do I need to change PostUpdateHealth() also to make it work?
  Reply With Quote
11-05-13, 06:53 AM   #2
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
I assume you have something else as parent for Health. You could always access it through Health.__owner, which is set when the health element is enabled for the unit frame.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
11-05-13, 07:54 AM   #3
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
This. Check your self.Health creation. Maybe your parent is not set to self.
Lua Code:
  1. local Health = CreateFrame("StatusBar", nil, self)
  2. self.Health = Health
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
11-05-13, 12:54 PM   #4
skarie
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2011
Posts: 37
Thank you Haste and Zork. You guys are both right. Indeed something else was the parent of Health.

Old codes
Code:
 local Health = CreateFrame("StatusBar",nil,Hbg)
New codes <---which fixes the problem
Code:
local Health = CreateFrame("StatusBar",nil, self)
Thank you guys.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » self.bugged


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off