WoWInterface - View Single Post - Script ran too long
View Single Post
03-11-15, 07:47 PM   #4
A Cobalt Mageweaver
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 215
Originally Posted by Phanx View Post
There are also some questionable bits in your code; for example:
		local UnitDebuff, index = UnitDebuff, 0
		while (true) do
			index = index + 1
			local name, _, icon, _, _, duration, expirationTime, _, _, _, spellId = (UnitDebuff or UnitBuff)(unit, index)
For one, I'd either upvalue UnitDebuff outside of your event handler, or don't bother upvaluing at all. For two, this code can never fall back to using UnitBuff, so you should probably get rid of that, or fix the rest of the code if it's supposed to use UnitBuff under some circumstances.
				UnitDebuff = nil
				index = 0
You don't need to manually un-set your (local) variables in Lua; they're automatically garbage-collected once they go out of scope.
I was thinking the same thing until I realized it scans debuffs before buffs.
It will loop through all debuffs then UnitDebuff becomes nil. Then it iterates over all buffs because it no longer uses UnitDebuff since now it is (nil or UnitBuff). Once it finishes with buffs it breaks out of the while loop. And all that explains why UnitDebuff is made local.
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison
  Reply With Quote