【发布时间】:2015-11-13 07:27:18
【问题描述】:
我正在为《魔兽世界》(WoW) 游戏编写插件。它使用 lua,带有一个特定于游戏的函数库。我正在检查是否可以在字符串中找到子字符串。有问题的子字符串由变量 ItemType 给出,在本例中包含字符串 "Two-Handed Swords"。我正在检查的字符串由表条目给出,包含"One-Handed Axes, One-Handed Swords, Two-Handed Axes, Two-Handed Swords, Bows, Crossbows, Guns, Wands, Mail, Plate, Shields"。问题是当我在相关项目上运行该函数时,它的行为就好像该项目不匹配。
完整代码如下
local NotUsableItemsTable = {
"Wands",
"Daggers, Fist Weapons, Staves, Bows, Crossbows, Guns, Wands",
"One-Handed Maces, Two-Handed Maces, Wands, Plate, Shields",
"Polearms, Staves, Two-Handed Axes, Two-Handed Maces, Two-Handed Swords, Wands, Mail, Plate, Shields",
"Fist Weapons, One-Handed Axes, One-Handed Swords, Polearms, Two-Handed Axes, Two-Handed Maces, Two-Handed Swords, Bows, Crossbows, Guns, Leather, Mail, Plate, Shields",
"Daggers, Fist Weapons, Staves, Bows, Crossbows, Guns, Wands, Shields",
"One-Handed Swords, Polearms, Two-Handed Swords, Bows, Crossbows, Guns, Wands, Plate",
"Fist Weapons, One-Handed Axes, One-Handed Maces, Polearms, Two-Handed Axes, Two-Handed Maces, Two-Handed Swords, Bows, Crossbows, Guns, Leather, Mail, Plate, Shields",
"Fist Weapons, One-Handed Axes, One-Handed Maces, Polearms, Two-Handed Axes, Two-Handed Maces, Two-Handed Swords, Bows Crossbows, Guns, Leather, Mail, Plate, Shields",
"Placeholder String: There is no class corresponding to index 10.",
"One-Handed Axes, One-Handed Swords, Two-Handed Axes, Two-Handed Swords, Bows, Crossbows, Guns, Wands, Mail, Plate, Shields"
}
function IsItemUseableByPlayer(itemID)
if itemID == nil then return nil end
local ClassInfo = {UnitClass("player")}
local NotUsableItemsString = NotUsableItemsTable[ClassInfo[3]]
local ItemInfo = {GetItemInfo(itemID)}
local ItemType = ItemInfo[7]
if string.match(NotUsableItemsString, ItemType) then
return true
else
return false
end
end
UnitClass("player") 在这种情况下返回{ "Druid", "DRUID", 11 }。
ItemType 即ItemInfo[7] 返回"Two-Handed Swords"
【问题讨论】:
标签: arrays regex string lua lua-patterns