WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Event triggering multiple times. (https://www.wowinterface.com/forums/showthread.php?t=50583)

kaytotes 11-25-14 08:11 PM

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);


myrroddin 11-26-14 02:33 AM

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.

SDPhantom 11-26-14 11:46 AM

Can you use [highlight="Lua"][/highlight] tags? It's difficult to see the comments with everything looking the same.

kaytotes 11-27-14 06:05 PM

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.

myrroddin 11-28-14 05:19 AM

Quote:

Originally Posted by kaytotes (Post 301200)
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.
Quote:

Originally Posted by kaytotes (Post 301200)
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!

Phanx 11-28-14 07:45 PM

Quote:

Originally Posted by myrroddin (Post 301224)
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.


All times are GMT -6. The time now is 05:58 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI