Indexing 在lua表(数组或字典表?)中保存字符串索引
所以我有一个两难的选择。我有一个读取特定消息的代码,例如:Indexing 在lua表(数组或字典表?)中保存字符串索引,indexing,lua,lua-table,Indexing,Lua,Lua Table,所以我有一个两难的选择。我有一个读取特定消息的代码,例如: m.content:sub(1,8) == 'Loot of ' then t = {dirty fur="quantity of msgs that show this",insert a new msg="how many times haves appear} 内容如下: 01:50 Loot of a starving wolf: a dirty fur, a salad, 2 pancakes, 60 gold 现在我正
m.content:sub(1,8) == 'Loot of ' then
t = {dirty fur="quantity of msgs that show this",insert a new msg="how many times haves appear}
内容如下:
01:50 Loot of a starving wolf: a dirty fur, a salad, 2 pancakes, 60 gold
现在我正试图将它插入到一个表中。到目前为止,我遇到的问题是,我无法让它计算字符串的类型,并在表中进行比较以添加其索引
例如:
m.content:sub(1,8) == 'Loot of ' then
t = {dirty fur="quantity of msgs that show this",insert a new msg="how many times haves appear}
到目前为止,我的工作是:
foreach newmessage m do
m.content:sub(1,8) == 'Loot of ' then
然后我就迷路了。我不知道如何创建这个表;我相信它应该是本地的,但我遇到的主要问题是,我不想成对打印,我想按插入顺序调用从1到#表的值。这就是我痛苦的开始
我想要像这样的东西:
table msgs = {spear='100',something='2', ovni='123'}
所以当我得到这个表时(我仍然无法生成),我可以为另一个函数调用同一个表,我想调用table。“xmsg”=数量。我希望有人能理解我的要求
function loot()
foreach newmessage m do
if m.type == MSG_INFO and m.content:sub(1,8) == 'Loot of ' then
local content = (m.content:match('Loot of .-: (.+)')):token(nil,', ')
for i,j in ipairs(content) do
return content
end
end
end
end
返回此函数的msgs:
{"3 gold coins"}
{"3 gold coins"}
{"nothing"}
{"6 gold coins", "a hand axe"}
{"12 gold coins", "a hand axe"}
我想写一个很长的答案来伴随这段代码,但我现在没有时间,对不起。
我以后再做。你能用真实的案例改写你的例子吗?如果你写“asdf”,很难知道你在说什么。然后你提到“spear”和“ovni”,但它们之前没有出现。你可能想做一个更好的解释。我有返回这些字符串的代码,所以没有必要读取时间或生物,现在我的问题是我无法在你给我的代码中工作,因此,我的问题是,我如何能包括您的计数器类型来计算这些消息{“3金币”}{“3金币”}{“无”}{“6金币”,“一把手斧”}{“12金币”,“一把手斧”}