AddElement only accepts four arguments: (1) the element name, (2) the update function, (3) the enable function, and (4) the disable function. You can't register multiple elements in one AddElement call, or change the order of the arguments.

(Also, "DisableDeuff" is misspelled.)

If you want separate elements for buffs and debuffs, you need to add them separately:

Also, I'd suggest using the names "BuffBars" and "DebuffBars" instead of "AuraBarsBuff" and "AuraBarsDebuff"; they're shorter, and more descriptive.

Also, a lot of that code is really inefficient; I'm not sure whether that was in the original module, or part of your changes. Creating 2-82 tables every time the unit's auras change (1-41 in each UpdateBuff and UpdateDebuff) is basically a memory leak, and your module will consume memory like a horde of kids in a candy store. Reuse tables as much as possible, instead of simply discarding them and creating new ones.

Consistent indentation, and separating blocks with empty lines, will also help the code be more readable.

First off, thank you for taking the time to fix and optimize my code that you'll never use. That's pretty awesome.

Secondly, I put your suggested code in, but I'm getting this pretty frustrating error. I can't seem to put my finger on what causes it. Sometimes I don't get it for a few minutes, sometimes it's as I start attacking something.

Also, add this anywhere before the UpdateBuff and UpdateDebuff functions:

Code:

local table_create, table_delete
do
local pool = { }
local function table_create()
local t = next(pool)
if t then
pool[t] = nil
end
return t or {}
end
local function table_delete(t)
if type(t) == "table" then
for k, v in pairs(t) do
t[k] = nil
end
t[true] = true
t[true] = nil
pool[t] = true
end
return nil
end
end
local default_sort = function(a, b)
if a.noTime then
if b.noTime then
-- both timeless, sort by name REVERSE
return a.name < b.name
else
-- a timeless, b not
return true
end
else
if b.noTime then
-- b timeless, a not
return false
else
-- neither timeless, sort by expiry time
return a.expires > b.expires
end
end
end

So if I'm understanding this correctly, we make a table for buffs with: local buffs = {}

We then make a function, for simplicity sake we'll just stick with the buffs. The function is called UpdateBuffs. It only updates when an event fires, which we register with self:RegisterEvent('UNIT_AURA', UpdateBuff). This function is also unit bound, so there can be target buffs, player buffs, focus buff, insert x frame category buffs all shown independently, and they all update independently. IE, when the player gains a buff, it doesn't cause the target buff UpdateBuff function to fire, thus unnecessarily increasing cpu load. Additionally it's set to fire only for HELPFUL aura changes. So it won't update when the unit gains or loses a debuff.

Next we set a variable, numBuffs to 0. We then set up our index to start at unit buff 1 get all the information from the UnitBuff api at that position, and store them in local variables set up. It continues to check each buff until it doesn't receive a name back (aka out of buffs to check) and breaks.

We create a local t and set it to the individual index of our buffs table created earlier (IE buffs[numBuffs]) so why don't we just use buffs[i] since whatever buff data we just got will be buff number i?

We then set up an if statement,

Lua Code:

ifnot t then

t = table_create()

buffs[numBuffs]= t

end

I don't fully understand this, we're checking to see if we have t, or anything in our buffs table. If we don't we create a table?

We then set buffs[i].locals to the locals that were set with the UnitBuff api.

We now set up a new for statement

Lua Code:

for i = #buffs, numBuffs + 1, -1do

buffs[i]= table_delete(buffs[i])

end

so basically we start with the number of buffs in our buffs table and go to the total number of buffs found with numBuffs (isn't that the same as #buffs), and then continue till i = -1? I don't understand the 3 part for loop I guess.

We then sort the buffs using either the BuffsBars.sort function or default_sort.

Now we make a for loop starting at 1 and going until we run out of buffs. The loop makes a bar for each buff and breaks if the width of the bars is set to 0. We create and set a local bar = to bars[i] which is essentially BuffBars.bars[i].

If it discovers there's no bar made yet, it makes it, and decreases the i by one to redo the loop for that buff. We then show the bar.

We create a local statusBar and set it to bar.statusBar which is essentially bars[i].statusBar which is BuffBars.bars[i].statusBar.

We also create a local buff and set it to the individual i in our buffs table.

Now we set bar.aura = buff. This I don't understand, we say that BuffBars.bars[i].aura = buff or in other words BuffBars.bars[i].aura = buffs[i]. Where did .aura even come from? I think this may be where a lot of issue is coming from. I don't see the .aura set up anywhere else. I don't know, I'm pretty awful at coding so maybe I'm just misreading this

Please post your current whole file; without it, identifying the cause of any error is pretty much impossible.

Originally Posted by sirann

... why don't we just use buffs[i] since whatever buff data we just got will be buff number i?

Because you are not adding every buff on the unit to the table. You are only adding buffs that pass the filter. If you only add data to the table at indices 1, 3, 7, and 9, for example, there are holes in your table and that breaks ipairs and sort. You need to keep track of how many buffs you are actually putting in the table.

Originally Posted by sirann

We then set up an if statement,

Lua Code:

ifnot t then

t = table_create()

buffs[numBuffs]= t

end

I don't fully understand this, we're checking to see if we have t, or anything in our buffs table. If we don't we create a table?

If there was previously a table at position 3, we can just reuse it, instead of going through the trouble of "deleting" it and getting a "new" one.

Originally Posted by sirann

Lua Code:

for i = #buffs, numBuffs + 1, -1do

buffs[i]= table_delete(buffs[i])

end

so basically we start with the number of buffs in our buffs table and go to the total number of buffs found with numBuffs (isn't that the same as #buffs), and then continue till i = -1? I don't understand the 3 part for loop I guess.

A loop normally increments i (or whatever variable name you're using for your counter) by +1 on each iteration. If you want to use some other increment, you can specify it as the third parameter.

So the above code starts with the total number of values in the buffs table, and increments it down by -1 on each iteration, until it reaches the last index we actually used on this pass, and erases all of the unused ones.

A simpler version would be to clear all of the indices first:

Code:

for i = 1, #buffs do
buffs[i] = table_delete(buffs[i])
end

... and then fill them back up:

Code:

local t = table_create()
buffs[numBuffs] = t

But that requires more function calls, so it's slightly slower.

Originally Posted by sirann

Now we set bar.aura = buff. This I don't understand, we say that BuffBars.bars[i].aura = buff or in other words BuffBars.bars[i].aura = buffs[i]. Where did .aura even come from?

It didn't "come from" anywhere. You are simply attaching the buff's data table to the bar object, using the key name "aura". It's the same as doing:

As for why that's being done, it simply makes it easier to tell which buff the bar is displaying later, when the bar is updated in the OnUpdate script, without having to go look up buffs[i] every time.

would set "bar.aura" to nil, because "aura" isn't defined. I think you meant "bar.aura = buff" there.

In your current file, line 305:

Code:

local bar = bars[i] --unecessary? se line 267 above

No, because line 267 is not in scope here. Local only exist inside the "if/for/do/function ... end" block where they are defined with the "local something" declaration. The entire file counts as one big "do ... end" block for the purpose of scoping, but each block inside the file gets its own scope, and they nest like those Russian dolls. Each scope can only "see" variables declared in itself, or in a higher scope that contains itself. Line 267 and line 305 are in parallel scopes of equal depth; neither can "see" any variables defined inside the other.

Edit:

Alright, I just ended up rewriting the whole thing. Tested (as far as the BuffBars element with 2 buffs on a level 12 warlock) and working:

So I changed the code I put into my oUF_Skaarj layout target function to this: http://pastebin.com/kTTfUHDn
(basically just changed all the frame to self, except for the frame inside of the filterFunc.)

I then received this error:

Code:

Message: Interface\AddOns\oUF_AuraBars\oUF_AuraBars.lua:279: attempt to compare number with nil

You should really use the entire file I posted; you left half of it out in your paste, and my code was not even remotely designed to be dropped into the middle of some other code. It's a total rewrite from scratch, not just a few changes here and there. If you're using code in your layout based on the example in the file I posted, of course you're going to get endless errors if you're not actually using the file I posted.

It took me a few minutes to figure out what you could have been referring to, the original pastebin link I have is invalid. That's not what I have as my file. I have this as my file: http://pastebin.com/nLRdQH6y

I have no idea why you changed all of the variable names in my code. Variables are not aware of their names, only their values. You only need to pass in the right value from your code. In your code, the frame object is the value of the variable named "self", so you need to pass "self" into the function. It doesn't matter if the function then refers to that value as "frame" or "kazoo". Only the order of arguments matter.

A more efficient solution to the nil count problem is to store nil counts as 1 in the first place, since that's techincally accurate; a buff with no charges effectively has 1 charge.

Finally, while I'm not really picky about being credited for stuff, I have put a lot of time into helping you with this, and does seem a little insulting that you would remove the "Rewritten by Phanx" comment from the file, when it being there has absolutely no effect on the functionality of the file because it's in a comment.

First let me apologize for the misunderstanding that's seemingly occurred. I never removed your "Rewritten by Phanx" from the beginning instructions. If you look at your first pass at the code, it wasn't there. I must have copied it by mistake and thus it wasn't in my file. I will revise by saying I didn't touch the comment up there, the version I copied (mistakenly) did not have that comment.

Secondly, I want to thank you for the time you've put into writing this addon. It's hard for me to show appreciation, especially when you probably think I'm an idiot who keeps ****ing up your code and posting the oops aftermath.

Thirdly, your latest revision, 6276, you added the "or 0" to count. You also have to do this for duration, as timeless buffs/debuffs are set to nil, this messes with your later if statement and throws an error:

Lua Code:

if aura.duration ==0then

bar.duration, bar.expirationTime =nil, nil

bar:SetMinMaxValues(0, 1)

bar:SetValue(1)

bar.time:SetText(nil)

else

bar.duration, bar.expirationTime = aura.duration, aura.expirationTime

--print (aura.duration)

bar:SetMinMaxValues(0, aura.duration)

-- No need to set the value or time text here; the OnUpdate will do it.

numAurasWithDuration = numAurasWithDuration + 1

end

Line 46 should read: local format, min, next, pairs, type, sort = format, min, next, pairs, type, sort the type, sort were backwards. I also added if not name then break end to the Update function under the if filterFunc(...

Line 221 was a function calling itself causing a stack overflow I believe:

Lua Code:

function table_delete(t)

iftype(t)=="table"then

for k, v inpairs(t)do

--t[k] = table_delete(t)

t[k]=nil

end

t[true]=true

t[true]=nil

pool[t]=true

end

returnnil

end

The commented out code was the line you posted in your latest revision, the t[k] = nil was the line that was in your previous table_delete(t) function.

Fourthly, this is working exactly how I wanted it. I don't know what to say besides thank you for making a reality what I've dreamt about for a few years. My final request is to be able to color bars by dispelType, DebuffTypeColor[element.dispelType or "none"] for debuffs but not buffs

Holy mother of necros, but, I'm curious if you think it would be possible to edit either the oUF_AuraBars.lua or my oUF layout to check (on PLAYER_TARGET_CHANGED) if the target is the same unit as one of the boss frames, and if so, hide the debuffbar frame associated with the respective boss..n's frame. All attempts thus far have either, a, caused an LUA error, or b, caused it to hide both target and all said boss' debuffbar frame.

I suppose I could write something in the oUF_AuraBars code that would create a frame, registerevent player_target_changed, and then do an on event script of

Possible, certainly, but that snippet you posted has a syntax error on almost every line.

1. The proper format is "for ... do" just like "if ... then" -- you are missing the "do" keyword.

2. You have an "if ... else ... end" inside of a "do ... (end)" but you are missing the last "end" keyword.

3. The second and third lines will throw errors about attempting to concatenate nil values. You need to (a) put quotes around the "oUF_TerennaBoss" part to make it a string value and (b) wrap that and the "..i" in a _G[...] lookup to actually get a refererence to the global object.

Code:

for i = 1, 5 do
if UnitIsUnit('target', 'boss'..i) then
_G["oUF_TerennaBoss"..i].DebuffBars:Hide()
else
_G["oUF_TerennaBoss"..i].DebuffBars:Show()
end
end