View Single Post
12/28/14, 10:08 PM   #4
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
One more question about this, mainly its out of curiousity as to why this is happening.

I took your suggestion & started using:
Lua Code:
  1. local function IsBagSlotOccupied(_iBagId, _iSlotIndex)
  2.     if (type(_iBagId) == "number" and _iBagId >= 0 and _iBagId <= 3) then
  3.         if (type(_iSlotIndex) == "number" and _iSlotIndex >= 0 and _iSlotIndex <= GetBagSize(_iBagId) - 1) then
  4.             local _, stackCount = GetItemInfo(_iBagId, _iSlotIndex)
  5.             return stackCount > 0
  6.         end
  7.     end
  8. end
To check and see if there is a valid item in the bag/slot.

But after I call that to check I'm trying to grab the slot data like this, but I'm getting an error sometimes:
Lua Code:
  1. local function IsSlotProtected(_iBagId, _iSlotId)
  2.    if not IsBagSlotOccupied(_iBagId, _iSlotId) then return false end
  3.  
  4.       local slotData = SHARED_INVENTORY:GenerateSingleSlotData(_iBagId, _iSlotId)
  5.  
  6.       -- But I'm getting an error (sometimes) on this: attempting to index a nil value
  7.       if slotData.FilterIt_CurrentFilter then
  8.           return true
  9.       end
  10.    return false
  11. end

So if the IsBagSlotOccupied(..) returns true, then there is an item in that bag slot.
and this
Lua Code:
  1. SHARED_INVENTORY:GenerateSingleSlotData(_iBagId, _iSlotId)
is not throwing any errors now, but then why does slotData come back nil (sometimes) if the slot is occupied?
I "think" its only occuring when I move items...but still if the slot is occupied I was assuming the bag/slot did not belong to an empty slot the item was moved out of, so there should still be data there?

The only thing I can think of now is to add another check to make sure the slotData is valid also.
Lua Code:
  1. local function IsBagSlotOccupied(_iBagId, _iSlotIndex)
  2.     if (type(_iBagId) == "number" and _iBagId >= 0 and _iBagId <= 3) then
  3.         if (type(_iSlotIndex) == "number" and _iSlotIndex >= 0 and _iSlotIndex <= GetBagSize(_iBagId) - 1) then
  4.             local _, stackCount = GetItemInfo(_iBagId, _iSlotIndex)
  5.             return stackCount > 0
  6.         end
  7.     end
  8. end
  9.  
  10. local function IsSlotOccupied(_tSlot)
  11.     return ((_tSlot ~= nil) and (_tSlot.stackCount > 0))
  12. end
  13.  
  14. local function IsSlotProtected(_iBagId, _iSlotId)
  15.    if not IsBagSlotOccupied(_iBagId, _iSlotId) then return false end
  16.       local slotData = SHARED_INVENTORY:GenerateSingleSlotData(_iBagId, _iSlotId)
  17.       if IsSlotOccupied(slotData) and slotData.FilterIt_CurrentFilter then
  18.          return true
  19.       end
  20.    return false
  21. end

Any ideas why this happens?
  Reply With Quote