Quantcast
WoWInterface - View Single Post - oUF_AuraBars
Thread: oUF_AuraBars
View Single Post
09-17-12, 07:27 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Please post your current whole file; without it, identifying the cause of any error is pretty much impossible.

Originally Posted by sirann View Post
... 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 View Post
We then set up an if statement,
Lua Code:
  1. if not t then
  2.      t = table_create()
  3.      buffs[numBuffs] = t
  4. 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 View Post
Lua Code:
  1. for i = #buffs, numBuffs + 1, -1 do
  2.      buffs[i] = table_delete(buffs[i])
  3. 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 View Post
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:

Code:
local bar = {}
local aura = { name = "Blah" }
bar.aura = aura
print(bar.aura.name)
==> "Blah"
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.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote