Update 49 is now available for testing on the PTS! You can read the latest patch notes here: https://forums.elderscrollsonline.com/en/categories/pts
Maintenance for the week of January 26:
• PC/Mac: No maintenance – January 26

GetItemLink not working for craft bag

robertlabrie
robertlabrie
✭✭✭
I'm looping through my craft bag using the table from
SHARED_INVENTORY:GenerateFullSlotData(nil, BAG_VIRTUAL)

Trying to find a slot index by itemLink but GetItemLink returns an empty string for BAG_VIRTUAL. Works fine for BAG_BACKPACK and BAG_BANK.

/script d(GetItemLink(BAG_VIRTUAL,1))
  • Baertram
    Baertram
    ✭✭✭✭✭
    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.

    About your question, a general advice:

    Best way is to search in esoui source code for BAG_VIRTUAL and check how ZOs does it:
    https://github.com/search?q=repo:esoui/esoui+BAG_VIRTUAL&type=code

    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.


    Edited by Baertram on January 27, 2026 2:51AM
Sign In or Register to comment.