WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   GetItemInfo hanging? (https://www.wowinterface.com/forums/showthread.php?t=57261)

Aeriez 07-06-19 02:45 AM

GetItemInfo hanging?
 
I'm looping through a SavedVariable storing loot history. Printing line by line with a link to the item within the line. However, when create a SavedVariable with a 100 item history, when I load the game it will do one of them and then error out saying that the variable is nil, expecting value. But it's only once. So basically every time I reload the UI, it'll add one more item successfully to the list until I have the entire list printed out. Then it will no longer error out. Almost as if GetItemInfo is not able to keep up with the loop.

Lua Code:
  1. for i=1, #DKP_Log do
  2.     local itemToLink = select(2,GetItemInfo(DKP_Log[i]["loot"])) -- log holds Item ID
  3.  
  4.     .... write variable to fontstring ....
  5. end

error received: Interface\AddOns\DKP\ConfigMenuTabs.lua:546: attempt to concatenate local 'itemToLink' (a nil value)

Just seems really strange that once all items have been loaded, it's fine until the game is restarted. Is there a way to delay the loop on each iteration?

humfras 07-06-19 03:09 AM

https://wow.gamepedia.com/API_GetItemInfo#Details
Quote:

If the item hasn't been encountered since the game client was last started, this function will initially return nil, but will asynchronously query the server to obtain the missing data, triggering GET_ITEM_INFO_RECEIVED when the information is available.
Since you store the item already, you should store the actual link because it carries more data than the itemId (like forging, sockets and bonus effects)

To get some information about an item immediately, you can use GetItemInfoInstant
Lua Code:
  1. itemID, itemType, itemSubType, itemEquipLoc, icon, itemClassID, itemSubClassID = GetItemInfoInstant(itemID or "itemString" or "itemName" or "itemLink")

Quote:

Though it is not documented, this function apparently returns info available directly in client files. Because of that it returns less data, but have several advantages over GetItemInfo: it always return data, when GetItemInfo can return nil for valid, but not loaded items and it never initiates requests to server, that could be subject to throttling or forced disconnection.

Aeriez 07-06-19 03:31 AM

My goal was to minimize the footprint of the SavedVariable file. But if storing the string is the best method I'll go ahead and do that. Thank you

Kanegasi 07-06-19 11:41 AM

Word of advice for add-on files, either SavedVariables or the add-on itself: Do not worry about how much space or memory you use. There is no difference between storing 100 item IDs and storing 100 item strings. In fact, it's a waste of CPU having to look up those item IDs. Always consider CPU, space/memory is never an issue. Better to save data than look it up.


All times are GMT -6. The time now is 11:25 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI