首页 > 解决方案 > 需要字符串时如何使用表格?

问题描述

我正在尝试运行以下脚本来删除项目。当我尝试按原样运行它时,它为我提供了以下错误“7:'find'的错误参数#1(预期搅拌,得到表)

我对此非常陌生,并且很难弄清楚如何让它读取表格。

当我输入 UseContainerItemByName("Lost Sole") 时,我让它工作了,但是我希望它删除表中出现的所有内容。

谢谢

    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)

标签: luaworld-of-warcraft

解决方案


item:find(search)需要search是字符串模式。然而,您将表 ( itemsToDelete) 传递给UseContainerItemByName,因此传入search

而不是UseContainerItemByName(itemsToDelete),使用

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

推荐阅读