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:
if not 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, -1 do 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:
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.