Originally Posted by merlight
2) Check whether a slot is empty using something other than GetItemName (comparing strings will always be slower than comparing numbers). I used GetItemType for that.
|
merlight, this is strictly a curiosity question to see if there is something I'm missing or do not understand, it is probably a negligible difference.
But, Is there a reason you don't just check the inventory slots table instead of calling GetItemType and comparing it to see if its ITEMTYPE_NONE?
Wouldn't that be even faster?
Lua Code:
local function findEmptySlotInBag(bagId, prevIndex, lastIndex)
local slotIndex = prevIndex or -1
while slotIndex < lastIndex do
slotIndex = slotIndex + 1
-- this
local iInventory = PLAYER_INVENTORY.bagToInventoryType[bagId]
if not PLAYER_INVENTORY.inventories[iInventory].slots[slotIndex] then
-- instead of this
--if GetItemType(bagId, slotIndex) == ITEMTYPE_NONE then
return slotIndex
end
end
return nil
end