One more question about this, mainly its out of curiousity as to why this is happening.
I took your suggestion & started using:
Lua Code:
local function IsBagSlotOccupied(_iBagId, _iSlotIndex)
if (type(_iBagId) == "number" and _iBagId >= 0 and _iBagId <= 3) then
if (type(_iSlotIndex) == "number" and _iSlotIndex >= 0 and _iSlotIndex <= GetBagSize(_iBagId) - 1) then
local _, stackCount = GetItemInfo(_iBagId, _iSlotIndex)
return stackCount > 0
end
end
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:
local function IsSlotProtected(_iBagId, _iSlotId)
if not IsBagSlotOccupied(_iBagId, _iSlotId) then return false end
local slotData = SHARED_INVENTORY:GenerateSingleSlotData(_iBagId, _iSlotId)
-- But I'm getting an error (sometimes) on this: attempting to index a nil value
if slotData.FilterIt_CurrentFilter then
return true
end
return false
end
So if the IsBagSlotOccupied(..) returns true, then there is an item in that bag slot.
and this
Lua Code:
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:
local function IsBagSlotOccupied(_iBagId, _iSlotIndex)
if (type(_iBagId) == "number" and _iBagId >= 0 and _iBagId <= 3) then
if (type(_iSlotIndex) == "number" and _iSlotIndex >= 0 and _iSlotIndex <= GetBagSize(_iBagId) - 1) then
local _, stackCount = GetItemInfo(_iBagId, _iSlotIndex)
return stackCount > 0
end
end
end
local function IsSlotOccupied(_tSlot)
return ((_tSlot ~= nil) and (_tSlot.stackCount > 0))
end
local function IsSlotProtected(_iBagId, _iSlotId)
if not IsBagSlotOccupied(_iBagId, _iSlotId) then return false end
local slotData = SHARED_INVENTORY:GenerateSingleSlotData(_iBagId, _iSlotId)
if IsSlotOccupied(slotData) and slotData.FilterIt_CurrentFilter then
return true
end
return false
end
Any ideas why this happens?