Thread Tools Display Modes
02-25-07, 10:40 AM   #1
nepluto
A Murloc Raider
Join Date: Sep 2006
Posts: 5
Checking health.

Hi. Im a bit new to the LUA side of programming. I'm trying to work up a mod to determine who needs healed based off of health %. but so far i've come up with an extremely large code that uses alot of memory. Im trying to condense the code.

I have already succesfully grabbed how many people were in a raid or party to determine the max ammount of players to scan through their raid id. only problem i have is storeing all possible values in temp vars so that i can input them into vars for UI output. Im wondering if putting them in a table might help, so i can store the player name and health in one value. But im not quite sure on how i would go about scanning players 1-40(possible) without storeing them in localy declared vars and then sorting the list from lowest to highest, and putting them in the right vars according to the health% they are at. If anyone could help me out i'd appreciate it. thanks.
  Reply With Quote
02-25-07, 05:15 PM   #2
Syzgyn
An Aku'mai Servant
 
Syzgyn's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 37
Here's a function I use all the time in my addons to sort tables that dont have key values:

Code:
function Sorted(t, f)
	local a = {}
	for n in pairs(t) do table.insert(a, n) end
	table.sort(a, f)
	local i = 0      -- iterator variable
	local iter = function ()   -- iterator function
		i = i + 1
		if a[i] == nil then return nil
		else return a[i], t[a[i]]
		end
	end
	return iter
end
then instead of calling
Code:
for k, v in pairs(table) do
you call
Code:
for k, v in Sorted(table) do
You can pass a function as f to determine how you want it sorted too. Look at http://lua-users.org/wiki/TableLibraryTutorial for more info about that. Hope this helps.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Checking health.


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off