View Single Post
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