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) |
Just a quick glance shows that you are redefining the self.effectAddedHandler function on every call to EffectTracker:HandleEffects so the table representing the function is not the same after each call. The function should either be defined once and used for everyone or there should be a table of functions with one instance for each player depending on what exactly you are doing with the function. But in any case you definately should not be redefining the function and then expecting it to match when you remove it - in other words, only functions that match an entry in the event table will get removed and since you redefined it, it doesn't match and isn't removed. As implemented, this actually should fail for all but one party member, that being the last one passed to EffectTracker:HandleEffects so I'm not sure how you were testing but if you only tested with a party of two then it would appeared to be working for all but the local player (when in fact it was just working for the last one added).
Basically, to fix this, move the definition of the callback funtions outside of the routine that adds them (you would use the "sender" argument to determine which player triggered the event) or create a table of functions, one for each player, i.e. self.effectAddedHandler[player:GetName()]=function... Of couse, if you go the route of using a table, then you have to pass the correct instance to the removecallback - RemoveCallback(v, "EffectAdded", self.effectAddedHandler[k]); So, option 1 is to move the definition outside :HandleEffects and use the Sender to determine the player that fired the event Code:
self.effectAddedHandler = function(sender, args) Code:
self.effectAddedHandler={} |
Yeah I was only testing with 2 players since it's the easiest way to do it.
And option one is what I was going for. I knew I was overlooking something like that, which is why I posted the question. I miss having a roommate that knows coding because this stuff is solved a lot faster! Thanks Garan! Edit: The sender in that event call is the EffectList that calls the event, not the player. How would I go about getting the player that the EffectList is for? Can I add a third parameter to the self.effectAddedHandler to be the player that has the EffectList, or would I have to go with option 2 and use the table? |
Quote:
change EffectTracker:HandleEffects to Code:
function EffectTracker:HandleEffects(player) Code:
self.effectAddedHandler = function(sender, args) |
Thanks for your help. The second option isn't really that tough to implement anyway, so I went ahead with that.
|
Quote:
|
Quote:
|
All times are GMT -5. The time now is 11:04 AM. |
vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI