View Single Post
03/15/17, 12:41 PM   #1
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
[open] item and ability link iterator

As the title says, it would be nice if we could have functions which allow us to easily iterate over all existing items or abilities without the need to filter by item name and set a hardcoded limit like this:

Lua Code:
  1. for i=1, 140000 do
  2.     local link = ("|H0:item:%d:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h"):format(i)
  3.     local name = GetItemLinkName(link)
  4.     if(name ~= "") then
  5.         -- something
  6.     end
  7. end

I'd say the simplest solution would be a function similar to GetNextMailId which returns the next valid itemId.
Lua Code:
  1. function GetNextItemLinkIter(state, itemId)
  2.     itemId = GetNextItemId(itemId)
  3.     return itemId, ("|H0:item:%d:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h"):format(itemId)
  4. end
  5.  
  6. for id, link in GetNextItemLinkIter do
  7.     -- something
  8. end
  Reply With Quote