Thread Tools Display Modes
Prev Previous Post   Next Post Next
07-31-17, 07:58 AM   #1
Mortimerlol
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Jul 2017
Posts: 71
Exclamation Help comparison tables

I have this code:
Lua Code:
  1. local BangDB = CreateFrame("FRAME");
  2. BangDB:RegisterEvent("ADDON_LOADED");
  3. BangDB:RegisterEvent("PLAYER_ENTERING_WORLD");
  4.  
  5. local function eventHandler(self, event, ...)
  6.     if event == "ADDON_LOADED" and ... == "Bang_Bang" then
  7.         if not BangCharKills then BangCharKills = {} end
  8.         if not BangCharHateds then BangCharHateds = {} end
  9.  
  10.         self:UnregisterEvent("ADDON_LOADED");
  11.     end
  12.  
  13. -- SORT TABLE A BY NAMES - format{ ["Name"] = true, ["Nametwo"] = true, ... }
  14. local hates = {}
  15.     for k in pairs(BangCharHateds) do hates[#hates + 1] = k end
  16.         table.sort(hates)
  17.     for i = 1, #hates do print(hates[i]) end
  18.  
  19. -- SORT TABLE B BY KILLS, NAMES - format{ ["Name"] = 12, ["Nametwo"] = 5, ... }
  20. function spairs(BangCharKills, order)
  21.     local tokills = {}
  22.     for k in pairs(BangCharKills) do tokills[#tokills + 1] = k end
  23.     if order then
  24.         table.sort(tokills, function(a,b) return order(BangCharKills, a, b) end)
  25.     else
  26.         table.sort(tokills)
  27.     end
  28.     local i = 0
  29.     return function()
  30.         i = i + 1
  31.         --testing with:
  32.         --if tokills[i] == hates[i] then -- doesn't works
  33.         --if BangCharKills[tokills[i]] == hates[i] then -- doesn't works
  34.         if tokills[i] then
  35.             return tokills[i], BangCharKills[tokills[i]]
  36.         end
  37.     end
  38. end
  39.     for k,v in spairs(BangCharKills, function(BangCharKills,a,b) return BangCharKills[b] < BangCharKills[a] end) do
  40.         print(v, k)
  41.     end
  42. end
  43. BangDB:SetScript("OnEvent", eventHandler);
All works fine but now I need sort TABLE B with (number, name) but if name is in TABLE A...

Thanks for help!
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Help comparison tables


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off