Quantcast WoWInterface - View Single Post - Best way to determine who killed me
View Single Post
11-26-12, 01:28 AM   #3
A Cobalt Mageweaver
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 232
Originally Posted by Phanx View Post

Also, there's no need to use string.sub and tonumber on the GUID; just use bit.band on the whole GUID and compare it to the COMBATLOG_OBJECT_CONTROL_PLAYER global (0x00000100). This will save you 2 function calls and one string creation.
Yes, every day I'll learn something new :-)
Probably I also seen these globals during googling/wowiki/wowpedia and the book but I was unable how to use them with proficency.

I also don't know what you were using the type variable for (since it was always set to an empty string) and it's generally a bad idea to use local variables with the same names as global functions or variables (the type function tells you whether a value is a string, number, table, etc.) so I just deleted it.
this was a "read and rewrite" from a book :-) and it was used to define type = NPC, Player etc etc ... I didn't think to the global impact of the thing and used the same variable name I found. Now I'll take more care in the future for the variable name.

A thing which I didn't understand so well in your code is the defining as local of:

Lua Code:
  1. -- For general use, I wouldn't recommend obsessively upvaluing every
  2. -- global but it is worth doing for situations like CLEU or OnUpdate
  3. -- where you are accessing them extremely often.
  4. local bit_band = bit.band

1) Defining a lua function (bit.band) as local is better than use it as is ?
2) Defining local to this addon the global constant for the controller type. Is it better and faster than using as is ?

Last question:

Lua Code:
  1. frame_cleu:SetScript("OnEvent", function(self, event,
  3. --- etc etc

could be evaluated depending of a condition or a variable name ?

Something like (I am writing on the fly so be kind about my errors in the replies :-) :

Lua Code:
  1. if not UnitInBattleground("player") or not IsActiveBattlefieldArena() then
  3.          frame_cleu:SetScript("OnEvent", function(self, event,
  5.          --- etc etc
  7. end

Thanks again for everything.
  Reply With Quote