Originally Posted by Phanx
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:
-- For general use, I wouldn't recommend obsessively upvaluing every
-- global but it is worth doing for situations like CLEU or OnUpdate
-- where you are accessing them extremely often.
local bit_band = bit.band
local COMBATLOG_OBJECT_CONTROL_PLAYER = COMBATLOG_OBJECT_CONTROL_PLAYER
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:
frame_cleu:SetScript("OnEvent", function(self, event,
--- 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:
if not UnitInBattleground("player") or not IsActiveBattlefieldArena() then
frame_cleu:SetScript("OnEvent", function(self, event,
--- etc etc
end
Thanks again for everything.