Lua 按以开头的名称计算嵌套表中的元素
我有下面列出的表格Lua 按以开头的名称计算嵌套表中的元素,lua,Lua,我有下面列出的表格 raids = { { T1I0 = { {'Mightstone of Sargaras', 'Mightstone of Sargaras\n\nMightstone of Sargaras is obtained by farming. GL'} }, T1I1 = { {'Blessings Jewel of Elune', 'test'} },
raids = {
{
T1I0 = {
{'Mightstone of Sargaras', 'Mightstone of Sargaras\n\nMightstone of Sargaras is obtained by farming. GL'}
},
T1I1 = {
{'Blessings Jewel of Elune', 'test'}
},
T1I2 = {
{'Lifegiving Gem of Amanthel', 'test'}
},
T2I0 = {
{'Practicing monster pot', 'test'}
},
T2I1 = {
{'Nuwa stone', 'test'}
}
}
}
通过使用下面的函数,结合tablelength(raids[1]),我成功地计算了元素的数量T1I0
->T2I1
=5
但是我在只计算以T1
开头的元素、声音返回3
时遇到了一些问题
有人知道如何修改最后一部分的ide吗?试试下面的代码:
for k in pairs(T) do if k:sub(1,2)=="T1" then count = count + 1 end end
但是,考虑在两层中重新构造表,第一个表具有键<代码> T1 < /代码>和<代码> T2< /代码>。在这之后,你想要的只是
#raids.T1
你真是个天才。非常感谢你抽出时间。
for k in pairs(T) do if k:sub(1,2)=="T1" then count = count + 1 end end