Thread Tools Display Modes
05/23/17, 02:45 PM   #1
Klingo
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 16
SHARED_INVENTORY question

Hi

I was wondering what the best/most efficient way is to get the content of a bag (e.g. the bank).
When I first started working on an ESO addon, my thinking was to do something like this here. It basically does exactly what I wanted: looping over all items in my bag.
Lua Code:
  1. local lastSlot = FindFirstEmptySlotInBag(BAG_BANK) - 1
  2. for index = 0, lastSlot do
  3.     ...
  4. end

Some time later however, I noticed that most other devs are relying on "SHARED_INVENTORY". For this I noticed that there are couple of different implementations that are not fully clear to me, when which one should be used. "GetBagCache" sounds pretty good, but since there also is the option to "GetOrCreate...", respectively even "GenerateFullSlotData", I was wondering if there might be instances when the simple "Get..." might return some outdated information? Or even just 'nil'?

Are there any recommendation as to when which implementation is recommended?

Lua Code:
  1. local bagCache = SHARED_INVENTORY:GetBagCache(BAG_BANK)
  2. for index, data in pairs(bagCache) do
  3.     ...
  4. end

Lua Code:
  1. local bagCache = SHARED_INVENTORY:GetOrCreateBagCache(BAG_BANK)
  2. for index, data in pairs(bagCache) do
  3.     ...
  4. end

Lua Code:
  1. local bagCache = SHARED_INVENTORY:GenerateFullSlotData(nil, BAG_BANK)
  2. for index, data in pairs(bagCache) do
  3.     ...
  4. end


Lastly, I assume that the following is just a different implementation of "GetBagCache()" by directly accessing the variable instead of via a function?
Lua Code:
  1. local bagCache = SHARED_INVENTORY.bagCache[BAG_BANK]
  2. for index, data in pairs(bagCache) do
  3.     ...
  4. end

Thanks a lot in advance =)

Cheers
Klingo
  Reply With Quote
07/07/18, 09:14 AM   #2
nightstrike2
Join Date: Sep 2017
Posts: 18
This question never got an answer, but I have the same one. Any thoughts?

EDIT: I've also noticed that SHARED_INVENTORY:GetOrCreateBagCache(BAG_BANK) is only returning 203 items, when I have 369 in my bank. Strange.

EDIT: I've further noticed that GetBagSize(BAG_BANK) returns 210, despite me being a subscriber and having 420 slots. This makes http://esodata.uesp.net/100023/src/i...ons.lua.html#1 stop at 209, thus getting the bag cache in this manner prevents me from getting anything in the extra slots.

Is there another bag id for the ESO+ extra space?

EDIT: Well, apparently what you need to do (and what only one addon I looked at does) is:

Lua Code:
  1. local bagCache = SHARED_INVENTORY:GenerateFullSlotData(nil, BAG_BANK, BAG_SUBSCRIBER_BANK)

That should be better documented, methinks....

Last edited by nightstrike2 : 07/07/18 at 10:36 AM.
  Reply With Quote
07/07/18, 11:20 AM   #3
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 408
Lua Code:
  1. local lastSlot = FindFirstEmptySlotInBag(BAG_BANK) - 1
  2. for index = 0, lastSlot do
  3. ...
  4. end


This is not going to do what you want it to. Bag slots are not consecutive, that is, just because there's an empty slot at slot #10 doesn't mean that slot #50 is also empty. You'll want to do GetBagSize instead if you go this method. This is actually usually my preferred method. It's clean, simple, and easy to remember.

The player bank is actually not one single bag - it's two. BAG_SUBSCRIBER_BANK and BAG_BANK are treated internally as two different bags. As a result, you need to loop over both bags when trying to find stuff, and the StackBag function doesn't really work for the bank.

The Generate function works for combining both using the ZOS functions, but you could also just do something like

Lua Code:
  1. local lastSlot = GetBagSize(BAG_BANK)
  2. for index = 0, lastSlot do
Lua Code:
  1. [color=#E5E5E5] doStuff( BAG_BANK, index)[/color]
  2. [color=#E5E5E5] doStuff(BAG_SUBSCRIBER_BANK, index)
  3. end[/color]



GetBagCache probably shouldn't be used. If the bag cache doesn't exist, you get nothing, so GetOrCreateBagCache is probably always preferable over GetBagCache.

Source code of GetBagCache is:

function ZO_SharedInventoryManager:GetBagCache(bagId)
return self.bagCache[bagId]
end

so SHARED_INVENTORY.bagCache[BAG_BANK] is basically equivalent to GetBagCache, unless an addon changes it.

Finally, one other aspect of GenerateFullSlotData is that you can give it any number of bags, so it would probably be very useful for home storage, and the first parameter is also a filter, so if you want to filter out say anything that is bound, you can do that.

  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » SHARED_INVENTORY question

Thread Tools
Display Modes

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