Originally Posted by sacrife
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:
local QuickSort;
do
local func = function(v1, v2)
if v1[1] == 0 or v2[1] == 0 then -- Empty bag slot
return v1[1] > v2[1]; -- Put empty slots last
elseif v1[2] ~= v2[2] then
return v1[2] > v2[2]; -- Higher quality first
elseif v1[1] ~= v2[1] then
return v1[1] < v2[1];
else -- Compare stack counts
local _, c1 = GetContainerItemInfo(v1[3].bagID, v1[3].slotID);
local _, c2 = GetContainerItemInfo(v2[3].bagID, v2[3].slotID);
return c1 < c2;
end
end;
QuickSort = function(tbl) table.sort(tbl, func); end
end