lotrointerface.com
Search Downloads


Go Back   LoTROInterface > LotRO > Developer Discussions > Lua Programming Help (L)

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 


Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Read out the EffectList Kunter Lua Programming Help (L) 14 08-01-2012 06:49 PM
New Warden functions MrJackdaw Lua Programming Help (L) 1 10-04-2011 04:53 PM
Should I wait to add a new UI Silverfoot Interface Help (L) 3 10-02-2011 08:01 AM
LocalPlayer (a table value)? WTH goldbishop Lua Programming Help (L) 4 11-30-2010 05:13 PM
issue with functions inside of a class SanDBoX Lua Programming Help (L) 18 10-08-2010 07:44 PM


All times are GMT -5. The time now is 04:23 PM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui