View Single Post
11/20/14, 02:04 PM   #11
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by merlight View Post
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:
  1. local function findEmptySlotInBag(bagId, prevIndex, lastIndex)
  2.    local slotIndex = prevIndex or -1
  3.    while slotIndex < lastIndex do
  4.       slotIndex = slotIndex + 1
  5.       -- this
  6.       local iInventory = PLAYER_INVENTORY.bagToInventoryType[bagId]
  7.       if not PLAYER_INVENTORY.inventories[iInventory].slots[slotIndex] then
  8.       -- instead of this
  9.       --if GetItemType(bagId, slotIndex) == ITEMTYPE_NONE then
  10.          return slotIndex
  11.       end
  12.    end
  13.    return nil
  14. end
  Reply With Quote