Tables can't be sorted by keys. This is a combination of how Lua tables are stored in memory and how WoW serializes SavedVars. Lua tables are stored in two components, an array list and a hashmap. Non-array keys are stored in memory by hash and are completely random.
You need to make
ITEMSCRAPESTATS into an array and put the ItemID somewhere in each entry. For example, this keeps track of items already scanned using a lookup table and adds them to the array and sorts when each entry is created.
Lua Code:
ITEMSCRAPESTATS = {};
local ItemScrapeLookup = {};
local function ScrapeSort(a, b)
return a[1] < b[1];
end
function ess(x)
ES:SetHyperlink("item:"..x..":0:0:0:0:0:0:0");
if _G["ESTooltipTextLeft2"]:GetText() then
if not ItemScrapeLookup[x] then
local dump = {x};
ItemScrapeLookup[x] = dump;
table.insert(ITEMSCRAPESTATS, dump);
table.sort(ITEMSCRAPESTATS, ScrapeSort);
print("Scraping Stats for Item Number: " .. x);
for i=1, ES:NumLines() do
table.insert(dump, _G["ESTooltipTextLeft" .. i]:GetText());
end
end
else print("No Stats for Item Number: " .. x); end
end
Note: Ideally, you'll want to only call
table.sort() once after you add all the entries. Calling it as each entry is added will eat up a lot of processing power.