View Single Post
07-21-17, 04:52 AM   #2
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Frames are tables and references within them are just keys in that table. You access a specific object by concatenating the strings together in brackets. The concatenation precedes the table lookup. Also, you don't need ipairs for what you're trying to do.

Lua Code:
  1. for i=1, 6 do
  2.     local start, duration, runeReady = GetRuneCooldown(i)
  3.     if not runeReady then
  4.         RuneFrame['Rune' .. i]:SetAlpha(RHNoCombatAlpha)
  5.     end
  6. end

ipairs is useful for sorted arrays with a number key and some value in each slot, whereas you would use pairs to iterate over an entire table in no particular order. When you're just using number indices for API calls, you don't need a custom iterator.
In your case, the table you're making just looks like this internally:
Lua Code:
  1. local runeID = {
  2.     [1] = 1,
  3.     [2] = 2,
  4.     [3] = 3,
  5.     [4] = 4,
  6.     [5] = 5,
  7.     [6] = 6,
  8. }

As you can probably tell, this is rather pointless and just creates overhead.

ipairs/pairs would be useful if you design this differently so that your table makes sense. If you use your table to reference your frames instead, like this:
Lua Code:
  1. local runes = {}
  2. for i=1, 6 do
  3.     runes[i] = RuneFrame['Rune'..i]
  4. end

...you could use your runes table to store and access the individual runes in one go:
Lua Code:
  1. for i, rune in ipairs(runes) do
  2.     local start, duration, runeReady = GetRuneCooldown(i)
  3.     if not runeReady then
  4.         rune:SetAlpha(RHNoCombatAlpha)
  5.     end
  6. end
__________________

Last edited by MunkDev : 07-25-17 at 12:44 PM.
  Reply With Quote