Btw. rather use this function to get an existing bag's cache, or cretae a new one if not existing:
SHARED_INVENTORY:GetOrCreateBagCache(BAG_VIRTUAL)
GetItemLink uses params bagId, slotIndex.
But BAG_VIRTUAL is special, as the items in the Craftbag do not use a slotIndex, but they use the item's "itemId" instad (like all other items in inventories and banks use slotIndex 1, 2, 3, etc.)
-> But GetItemLink(BAG_VIRTUAL, slotData.itemId) should work fine
where slotData = each item's data generated from
local bagData = SHARED_INVENTORY:GetOrCreateBagCache(BAG_VIRTUAL)
if not ZO_IsTableEmpty(bagData ) then
for _, slotData in pairs(bagData) do
local itemLink = slotData.itemLink or GetItemLink(slotData.bagId, slotData.itemId)
end
end
Something like this.
Attention: it could even be that the table key of bagData is not an index 1, 2, 3, here (usualyl this would be the slotIndex of a normal inventory item!!!) but uses the itemId of the Craftbag already, so in ipairs would not work!!! You need to check that, and if it's not a non.gap index 1, 2, 3, ipairs must not be used!
Use ipairs then, and instead of for _, slotData use for itemId,slotData and you got your itemId then directly.
But as explaiend below you should have all needed item data in the slotData already and must not re-read them via API functions, cost-expensivley again! Only do that if they are nil, then you can re-read them.
Debugging stuff ingame
At best install merTorchbug enhanced debug addon: https://www.esoui.com/downloads/info2601-MerTorchbug-FixedandImprovedVariableinspectorScriptsEventsandmore.html
Make your bagData global via MyAddonNameBagData = bagData in your code so you can debug it inside ESO and do /tb MyAddonNameBagData ingame to inspect it and see al entries, and what the slots contain already.
Usually the itemlink etc. is ALL in there already so you do not need to generate that new ia API functions?
Tbug also provides a list of ingame constants, API functions etc. and search capabilities so you can enter /tb and see that search UI. Works for events too via the E at the headlin (Event tracker), scripts history to save and rerun your scripts, and many other features (live variable changes or live anchor changes at UI controls e.g.).
I also recommand to use LibDebugLogger and DebugLogViewer addons so you can see the debug messages and d() messages in that extra UI even after a reloadUI (to check old error messages etc.).
Enable the stack traceback in LibDebugLogger settings so your error message can be clicked in teh DebugLogViewer UI and you can see the stack, where it came from, what the variables values where etc.
Else always check the available API functions, constants, events in the current APIVersion's documentation files here: https://wiki.esoui.com/APIVersion
-> Select the current live or PTS API version (e.g. 101048 for current live) and then check the entry at
" API TXT Documentation": https://www.esoui.com/forums/attachment.php?attachmentid=1891&d=1757966271
The downloaded txt file contains all the possible API functions then, etc.