Thread: Table Iteration
View Single Post
03-30-13, 12:20 PM   #6
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Also why does the order matter if it's multiplicative?
Because the order in which you multiply, when dealing with percents, affects the out-come? Increasing an amount by 60%, then 40% yields a different answer than increasing an amount by 40%, then 60%.

I suppose you are correct about the two table approach, but the metatable could be universal for two seperate tables, yielding only 3 tables, instead of four? (Bare in mind I know nothing about metatables, I just saw it used as a solution to a problem similar to mine).

If your code is not performance critical...
I guess you could say that code is performance critical.

My approach was, and this is pretty theoretical, to sort a table of healing increases (and decreases in a separate table) by hand, and as a for-loop iterates over it (assuming it is in descending order), if a player has a buff in the table, that percentage will be applied to an amount, and the process continues. In the example posted above, if a player had BOTH Guardian Spirit and Vampiric Blood, a potential heal would be increased by 60%, then 25(or 40)%.

My approach could be horrid, but it seemed like the most simple approach, until I ran into the issue with my table being impossible to index, and impossible to iterate over with ipairs().

Thanks for the replies!

Edit:

Here was the script I was using (granted, it doesn't work in that it reads the table in any order, but it still works)
Lua Code:
  1. for k, v in pairs(generalHealingIncrease) do
  2.     if UnitAura("player", k) then
  3.         totalDamageAmount = addPercent(totalDamageAmount, v)
  4.     end
  5. end

Last edited by Clamsoda : 03-30-13 at 12:27 PM.
  Reply With Quote