View Single Post
03-15-12, 05:02 AM   #1
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
3 LUA questions (array, vars scope, mob health)

Hello,

I have some LUA related questions I hope someone here will be able to answer.

1) What is the best way to search an array?
Code:
for _, value in pairs(myArray) do
  -- use value
end
or
Code:
for i = 1, #myArray do
   -- use myArray[i]
end
or perhaps another way?

2) Let's say I have this code:
Code:
function xxx ()
   local counter = ...
   
   for counter = 1, 3, 1 do
      print(counter)
   end

   -- use counter
end
Is "counter" of the for loop local only for the for loop scope? Or will the loop alter the "counter" declared at the beginning of the function?

3) I want to track boss health. for that I use "boss1" .. "boss4" which relate to the 4 boss frames on the right side of the screen. for example:
Code:
UnitHealth("boss1")
The problem is that at a certain phase some adds might fill those boss frames and "push out" the original boss. This happens for example on Yor'sahj, when 4 Globules appear and "take" all 4 boss frames. How can I still get Yor'sahj health in such scenario?
Is there a way to get unit health through the unit name for example? Any other solution?

Thanks in advance!
  Reply With Quote