View Single Post
06-11-10, 06:34 AM   #2
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
You can't reliably sort a hash table because the returns you receive when iterating it aren't necessarily going to be in sorted order. Use an array instead, or add an additional data structure.

Code:
subsList = {
	-- etc
}

-- Copy character names to sorting array.
local sorted = {}

for name in pairs(subsList) do
	sorted[#sorted + 1] = name
end

table.sort(sorted, function(a, b) return a > b end)
Then you would use this to get a sorted value from your hash table.

Code:
local first = subsList[sorted[1]]
But really since you already have a value in your table for character name it's probably better to just switch over to an array.
  Reply With Quote