Thread Tools Display Modes
01-27-10, 03:08 PM   #1
kingamajick
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 3
PLAYER_TARGET_CHANGED not working as expected

I've been hacking around with some addons, and I've hit a bit of difficulty with the PLAYER_TARGET_CHANGED event.

I'm trying to register when the player changes their target, which is the following scenarios:
Code:
Player has no target -> Player selects target
Player has target    -> Player selects new target*
Player has target    -> Player clears target*
I would have expected PLAYER_TARGET_CHANGED to handle all these events, as PLAYER_FOCUS_CHANGED does. However it seems to be only firing for the * scenarios. When I have no target and select a target the event doesn't get fired. Is this working as intended or is there something I've miss understood here?

I've looked at other mods (I'm trying to display the targets buffs/debuffs) and as far as I can see they only register for "UNIT_AURA" and "PLAYER_TARGET_CHANGED", so I'm pretty confused to what I'm missing.

Cheers
  Reply With Quote
01-27-10, 04:39 PM   #2
wurmfood
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 122
I just verified by using the "/eventtrace" command in game that the event does fire if I'm not targeting anything and then target someone.

Can you provide more info about how it is/isn't working?
  Reply With Quote
01-27-10, 05:48 PM   #3
kingamajick
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 3
Hey, thanks for your reply.

I'm currently working on an Element for an oUF layout I've been playing with, this is the current code for the element

Code:
local _, ns = ...
local oUF = ns.oUF or oUF
assert(oUF, 'oUF_AuraBars was unable to locate oUF install.')

--[[
	AuraBars.
]]--



local function Update(self, event, unit)
	DEFAULT_CHAT_FRAME:AddMessage("AuraUpdate")
end

local function Enable(self)
	local auraFrame = self.AuraBars
	if(auraFrame) then
		DEFAULT_CHAT_FRAME:AddMessage("AuraEnable "..self.unit)
		self:RegisterEvent("UNIT_AURA", Update)	
		self:RegisterEvent("PLAYER_TARGET_CHANGED", Update)
	end
end

local function Disable(self)
	DEFAULT_CHAT_FRAME:AddMessage("AuraDisable")
	local auraFrame = self.AuraBars
	if(auraFrame) then
		self:UnregisterEvent("UNIT_AURA", Update)
	end
end

oUF:AddElement("AuraBars", Update, Enable, Disable)
I've activated this element on my target frame, and correctly see "AuraEnable target" when the UI loads. However I only see the the "AuraUpdate" message outtput when either and aura is gained or lost by the target or the two *'ed examples in my previous post.

I'll have a look at the "/eventtrace" command, and see what I can see from that end.

Cheers
  Reply With Quote
01-27-10, 07:03 PM   #4
wurmfood
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 122
Not sure why it's not working for you, but I verified it's working for me. I added it to my oUF layout and it seems ok. I even added "print(UnitName("target"))" to the Update to make sure it was showing the unit changes from nil to a target.
  Reply With Quote
01-28-10, 06:51 AM   #5
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Change your Enable function to return true when it enables itself. This will make oUF add your Update function to the list of functions which is executed when the frame is shown.

You have to remember that oUF doesn't execute events on hidden frames.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
01-28-10, 12:29 PM   #6
kingamajick
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 3
Originally Posted by haste View Post
Change your Enable function to return true when it enables itself. This will make oUF add your Update function to the list of functions which is executed when the frame is shown.

You have to remember that oUF doesn't execute events on hidden frames.
Great, returning true from the function gives me the extra call to Update I required

Good call on the issue with PLAYER_TARGET_CHANGED, that was down to the frame not been displayed (which explains why it didn't work from no target -> target, but worked in the other scenarios)

Cheers for the help folks
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » PLAYER_TARGET_CHANGED not working as expected


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