View Single Post
04-08-24, 06:54 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,333
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:
  1. ITEMSCRAPESTATS = {};
  2. local ItemScrapeLookup = {};
  3.  
  4. local function ScrapeSort(a, b)
  5.     return a[1] < b[1];
  6. end
  7.  
  8. function ess(x)
  9.     ES:SetHyperlink("item:"..x..":0:0:0:0:0:0:0");
  10.     if _G["ESTooltipTextLeft2"]:GetText() then
  11.         if not ItemScrapeLookup[x] then
  12.             local dump = {x};
  13.             ItemScrapeLookup[x] = dump;
  14.             table.insert(ITEMSCRAPESTATS, dump);
  15.             table.sort(ITEMSCRAPESTATS, ScrapeSort);
  16.  
  17.             print("Scraping Stats for Item Number: " .. x);
  18.             for i=1, ES:NumLines() do
  19.                 table.insert(dump, _G["ESTooltipTextLeft" .. i]:GetText());
  20.             end
  21.         end
  22.     else print("No Stats for Item Number: " .. x); end
  23. 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.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-08-24 at 07:15 PM.
  Reply With Quote