View Single Post
08-25-10, 09:55 AM   #23
Saiket
A Chromatic Dragonspawn
 
Saiket's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 154
Originally Posted by sacrife View Post
Both c1 and c2 returns 'nil'.
Oops, I think that would happen if it tried to sort empty bag slots. This version should just put them at the end instead of comparing the quality/IDs of empty slots.
lua Code:
  1. local QuickSort;
  2. do
  3.     local func = function(v1, v2)
  4.         if v1[1] == 0 or v2[1] == 0 then -- Empty bag slot
  5.             return v1[1] > v2[1]; -- Put empty slots last
  6.         elseif v1[2] ~= v2[2] then
  7.             return v1[2] > v2[2]; -- Higher quality first
  8.         elseif v1[1] ~= v2[1] then
  9.             return v1[1] < v2[1];
  10.         else -- Compare stack counts
  11.             local _, c1 = GetContainerItemInfo(v1[3].bagID, v1[3].slotID);
  12.             local _, c2 = GetContainerItemInfo(v2[3].bagID, v2[3].slotID);
  13.             return c1 < c2;
  14.         end
  15.     end;
  16.     QuickSort = function(tbl) table.sort(tbl, func); end
  17. end
  Reply With Quote