Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 按以开头的名称计算嵌套表中的元素_Lua - Fatal编程技术网

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