View Single Post
  #1  
Unread 04-21-2013, 01:30 PM
Stever1388 Stever1388 is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Nov 2010
Posts: 33
Using Add/Remove callback functions with the localplayer EffectList

I'm working/updating my simple Party Debuff Tracker plugin, and I'm trying to get it to remove the local players "EffectAdded" event from the EffectList. For whatever reason, it does not work, yet will work for all other members of a players fellowship. Here is some relevant code:

Code:
-- player is the current member of the fellowship we are creating events for (loop is in another function)
function EffectTracker:HandleEffects(player)
	self.effectList[player:GetName()] = player:GetEffects(); -- kept for removecallback function
	self.effectAddedHandler = function(sender, args)
		-- outputs data to chat window (code not important to discussion)
	end
	AddCallback(player:GetEffects(), "EffectAdded", self.effectAddedHandler);
end

-- used to make sure party is current
function EffectTracker:UpdateParty()
	self.partyChangedHandler = function(sender, args)
		if localPlayer:GetParty() == nil then
			RemoveCallback(party, "MemberAdded", self.partyChangedHandler);
			RemoveCallback(party, "MemberRemoved", self.partyChangedHandler);
			self:RemoveEffectCallbacks();
		end
		party = localPlayer:GetParty();
		self:TrackEffects();
	end
	AddCallback(localPlayer, "PartyChanged", self.partyChangedHandler);
	AddCallback(localPlayer, "RaidChanged", self.partyChangedHandler);
	if party ~= nil then
		self:TrackEffects();
	end
end

-- this is where the problem is
function EffectTracker:RemoveEffectCallbacks()
	if self.effectList ~= nil then
		for k, v in pairs(self.effectList) do
                 -- should remove event functions for the EffectAdded events for all members of the fellowship. It works for every member of the fellowship, but fails to remove the localplayers event.
			RemoveCallback(v, "EffectAdded", self.effectAddedHandler);
		end
                -- added this to remove that callback that is not removed using RemoveCallback() function
		if localPlayer:GetEffects()["EffectAdded"] ~= nil then
			localPlayer:GetEffects()["EffectAdded"] = nil;
		end
	end
end
When I added some chat output lines to the RemoveCallback() function, it seems that "if object[event] == callback then" isn't "working" correctly for the EffectList of the local player. I cannot tell why, as the EffectList for other party members works correctly. It seems the table that holds the EffectList changes somewhat from setting the event function to removing it so the "object[event]" points somewhere else, however, the object[event] isn't nil, but I'm not quite sure how to check what exactly it is holding (apparently not the self.effectAddedHandler function). Considering that my workaround won't play safe with other plugins or other EffectAdded events to the local player, this is a somewhat annoying problem. Perhaps I am just missing something but I can't see it right now. If you need clarification please let me know. Thanks for your help!
Reply With Quote