luaworld-of-warcraft

How to use a table when a string is expected?


I'm attempting to run the following script to undertake deletion of items. When I attempt to run it as is it provides me with the following error "7: Bad argument #1 to 'find' (stirng expected, got table)

I am very fresh to this and having a hard time working out how to allow for it to read the table.

I get it working when I put in UseContainerItemByName("Lost Sole") however I want it to delete all that come up in the table.

Thanks

    local DeleteCursor = function (...) return __LB__.Unlock(DeleteCursorItem, ...) end

function UseContainerItemByName(search)
   for bag = 0,4 do
      for slot = 1,GetContainerNumSlots(bag) do
         local item = GetContainerItemLink(bag,slot)
         if item and item:find(search) then
            PickupContainerItem(bag,slot)
            DeleteCursor(bag,slot)
         end
      end
   end
end

itemsToDelete = {
    "Lost Sole",
    "Oribobber",
    "Elysian Thade Bait",
    "Old Glove",
    "Rusty Chain",
    "Broken Fishing Pole",
    "Elysian Thade Bait",
    "Lost Sole Bait",
    "Partially Eaten Fish",
    "Shrouded Cloth Bandage"
}


UseContainerItemByName(itemsToDelete)

Solution

  • item:find(search) requires search to be a string pattern. Yet you passed a table (itemsToDelete) to UseContainerItemByName, and therefore into search.

    Instead of UseContainerItemByName(itemsToDelete), use

    for _, item in ipairs (itemsToDelete) do
        UseContainerItemByName (item)
    end