Thread Tools Display Modes
11-25-14, 08:11 PM   #1
kaytotes
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Nov 2014
Posts: 18
Event triggering multiple times.

I have searched but have some how not found anything that hints towards help on this matter. PARTY_KILL seems to run twice every time. I can't seem to discern why or how to prevent this. Any help is much appreciated.

Code:
killTracker = CreateFrame( "Frame" );
killTracker:RegisterEvent( "COMBAT_LOG_EVENT_UNFILTERED" );

killTracker:SetScript("OnEvent", function(_, _, _, event, _, sourceGUID, sourceName, _, _, destGUID, destName,  destFlags)
	if ( event == "PARTY_KILL" and sourceGUID == player) then
		if( inInstance == true ) then
			if( instanceType == "pvp" or instanceType == "arena" ) then
				message:AddMessage( "Killing Blow!", 1, 1, 0, 53, 3 );
			end
		end
	end

	if( event == "PARTY_KILL" ) then
		local string = sourceName.." killed "..destName;
		UpdateKills( string );
	end
end);
  Reply With Quote
11-26-14, 02:33 AM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I did the following:
  • Got rid of the ugly and useless semicolons
  • Cleaned up the code
  • Commented where necessary
Lua Code:
  1. local killTracker = CreateFrame( "Frame" ) -- stop global leaking
  2. killTracker:RegisterEvent( "COMBAT_LOG_EVENT_UNFILTERED" )
  3.  
  4. killTracker:SetScript("OnEvent", function(_, _, _, event, _, sourceGUID, sourceName, _, _, destGUID, destName,  destFlags)
  5.     if ( event == "PARTY_KILL" )  then
  6.         local string = sourceName.." killed "..destName
  7.         UpdateKills( string ) -- is UpdateKills a local function? it had better be!
  8.         if (sourceGUID == player) then
  9.             local _, instanceType = IsInInstance()
  10.             if ( instanceType == "pvp" ) or ( instanceType == "arena" ) then
  11.                 message:AddMessage( "Killing Blow!", 1, 1, 0, 53, 3 ) -- is message a local reference? what is it, where is it?
  12.             end
  13.         end
  14.     end
  15. end
This might still be buggy, and I'm not about to test it in game, but it should be better. PARTY_KILL was running twice because you had two things responding to it, in two different parts of your code. I moved it to one chunk.

Also, you currently don't do anything with being in an instance other than what the instance type is, so that got slimmed down.

I have no idea what references UpdateKills and message you have; since both are generic names, and looking over your existing code, I'm going to assume you have leaking global references. Further, there is no function reference in your posted to code to message other than what we see, therefore the numbers after the string are meaningless and won't do anything.

But it is a start.

Last edited by myrroddin : 11-26-14 at 07:59 PM. Reason: switch from code tags to Lua tags
  Reply With Quote
11-26-14, 11:46 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Can you use [highlight="Lua"][/highlight] tags? It's difficult to see the comments with everything looking the same.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
11-27-14, 06:05 PM   #4
kaytotes
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Nov 2014
Posts: 18
I apologize for the lack lack of LUA tags. Will remember for the future.

Thank you myrroddin the issue definitely was the double PARTY_KILL and I can't believe I missed it.
  Reply With Quote
11-28-14, 05:19 AM   #5
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by kaytotes View Post
I apologize for the lack lack of LUA tags. Will remember for the future.
I don't mind the [ code ] [ /code ] tags, but I understand why some people prefer the Lua highlighting. Normally I use the former because the latter sometimes is inaccurate.
Originally Posted by kaytotes View Post
Thank you myrroddin the issue definitely was the double PARTY_KILL and I can't believe I missed it.
We've all been there. Hopefully it all worked out for you!
  Reply With Quote
11-28-14, 07:45 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by myrroddin View Post
I don't mind the [ code ] [ /code ] tags, but I understand why some people prefer the Lua highlighting. Normally I use the former because the latter sometimes is inaccurate.
I avoid the Lua tags and actually ended up writing some user CSS to remove the coloring in my browser when other people use them because many of the colors have terrible, terrible contrast and are very hard for me to read.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Event triggering multiple times.

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