1. I'm trying to write a small addon to check if there are 3 or more free bag spaces left before moving items from the bank to my bags. The function invHasThreeFreeSlots() seems to work when tested on its own, but when put in a loop going through my bag slots, it seems to be an all or nothing shot. If I start the script with three or more free slots, it will fill up in inventory completely. If I start the script with two or one free slots, it won't move anything. I'd like for it to move items over until there are exactly two free slots. I'm completely stumped as to what I'm not doing here, any ideas?

     function invHasThreeFreeSlots()
        local freeSlots = 0
        for bag = 0,4 do
           bagFreeSlots, bagType = GetContainerNumFreeSlots(bag)
           freeSlots = freeSlots + bagFreeSlots
        end
        if (freeSlots >= 3) then
           return true
        else 
           return false
        end
     end
    
     for bag=5,11 do 
        for slot=0,22 do 
           itemLink=GetContainerItemLink(bag,slot) 
           if (invHasThreeFreeSlots()) then
              if itemLink and itemLink:find("Ashen") then 
                 UseContainerItem(bag,slot) 
              end    
          end
        end
    

    end

    After a break and then trying a few more things, I finally got the behavior I was looking for.

     function GetNumFreeSlots()
        local freeslots = 0
        for lbag=0,4 do
           numFreeSlots, BagType = GetContainerNumFreeSlots(lbag)
           freeslots = freeslots + numFreeSlots
        end
        return freeslots
     end
    
    
     FreeSlots = GetNumFreeSlots()
     for bag=5,11,1 do
        for slot=0,(GetContainerNumSlots(bag)),1 do
           itemLink=GetContainerItemLink(bag,slot)
           if itemLink and itemLink:find("Volatile") then
              if (FreeSlots > 2) then
                 UseContainerItem(bag,slot)
                 FreeSlots = FreeSlots - 1
              end
           end
        end
     end
    

    Glad you were able to get it working!