View Single Post
11/18/14, 11:03 AM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
That's probably by design. The items are not actually moved immediately, your commands are carried out after your handler exits.

Some time ago I wrote my own function for finding an empty slot, which allows me to start the search after the previous one:
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.         if GetItemType(bagId, slotIndex) == ITEMTYPE_NONE then
  6.             return slotIndex
  7.         end
  8.     end
  9.     return nil
  10. end
  11.  
  12. -- usage
  13. local numSlots = GetBagSize(BAG_BANK)
  14. local emptyIndex = findEmptySlotInBag(BAG_BANK, nil, numSlots - 1)
  15. while emptyIndex do
  16.    -- we have an empty slot in bank
  17.    ... put something in there
  18.     emptyIndex = findEmptySlotInBag(BAG_BANK, emptyIndex, numSlots - 1)
  19. end
  20. -- bank full
  Reply With Quote