lua - 需要字符串时如何使用表格?
问题描述
我正在尝试运行以下脚本来删除项目。当我尝试按原样运行它时,它为我提供了以下错误“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)
解决方案
item:find(search)
需要search
是字符串模式。然而,您将表 ( itemsToDelete
) 传递给UseContainerItemByName
,因此传入search
。
而不是UseContainerItemByName(itemsToDelete)
,使用
for _, item in ipairs (itemsToDelete) do
UseContainerItemByName (item)
end
推荐阅读
- java - 如何通过指定类而不是 jar 来加载代理
- java - 如何在 Spring Boot 应用程序中使用多个 mongodb 数据库?
- parsing - Convert String into exact same Int
- c# - 如何检查 customLogs 是否正在上传到 Azure Application Insights
- excel - 根据值更改散点图excel中特定点的形状
- php - 如何使用ffmpeg将具有过渡效果的文本添加到视频中?
- javascript - 如何在 multidatepicker 中添加禁用日期的描述
- linux - 我想替换 UNIX 文件第 6 列中的一个字符,这似乎有点挑战性
- c - 在 cpu 模拟器中是调用外部函数所需的程序集
- python-3.x - 如何从命令行运行没有模块的python