View Single Post
12/29/14, 11:45 PM   #7
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
As merlight said, if you are going to use function SHARED_INVENTORY:GenerateSingleSlotData(bagId, slotIndex), much easier (and faster) is just checking data you get from this function.

Lua Code:
  1. local function IsSlotProtected(_iBagId, _iSlotId)
  2.     local slotData = SHARED_INVENTORY:GenerateSingleSlotData(_iBagId, _iSlotId)
  3.     if slotData and slotData.FilterIt_CurrentFilter then
  4.         return true
  5.     end
  6.     return false
  7. end

At first I wanted to add condition "slotData.stackCount > 0" to the function above, but it is not necessary. SHARED_INVENTORY checks it before storing slot data into the bag cache, so stackCount must be always more then zero.

Q: When slotData could be nil even if slot is not empty?
A: If you are using SHARED_INVENTORY:GenerateSingleSlotData(bagId, slotIndex) directly from the EVENT_INVENTORY_SINGLE_SLOT_UPDATE handler, it is possible that your function is called before bag cache is updated. If you want to be sure that cache is updated, use SHARED_INVENTORY's callbacks instead.

Example:
Lua Code:
  1. local function OnFullInventoryUpdated(bagId)
  2.     --some code here
  3. end
  4.  
  5. local function OnInventorySlotUpdated(bagId, slotIndex)
  6.     --some code here
  7. end
  8.  
  9. SHARED_INVENTORY:RegisterCallback("FullInventoryUpdate", OnFullInventoryUpdated)
  10. SHARED_INVENTORY:RegisterCallback("SingleSlotInventoryUpdate", OnInventorySlotUpdated)
  Reply With Quote