Returns a list of open slots in a container. The optional argument returnTable allows for performance optimization in cases where this function is expected to be called repeatedly. Rather than creating new tables each time the function is called (eventually requiring garbage collection), an existing table can be recycled. (Note, however, that this function does not clear the table's contents; use wipe() first to guarantee consistent results.)


See also Container functions.

Signature:

slotTable = GetContainerFreeSlots(container [, returnTable])

Arguments:

  • container - Index of one of the player's bags or other containers (number, containerID)
  • returnTable - Reference to a table to be filled with return values (table)

Returns:

  • slotTable - A table listing the indices of open slots in the given container (table)

Examples:

-- assuming the first two rows of slots in your backpack are full...
local bagSpaces = GetContainerFreeSlots(0)
print(unpack(bagSpaces))
-- Chat window shows "9 10 11 12 13 14 15 16"

-- assuming all slots but the first in the bag immediately left of your backpack are full...
GetContainerFreeSlots(1, bagSpaces)
print(unpack(bagSpaces))
-- Chat window shows "1 10 11 12 13 14 15 16"
-- oops, it overwrote the table from before... let's try again
wipe(bagSpaces)
GetContainerFreeSlots(1, bagSpaces)
print(unpack(bagSpaces))
-- Chat window shows "1"