Lua - 如何在表中使用运算符“and”?

我有一个代码可以正常运行。他打印“ok”。

data = "on482654225954"

  if data:find("on.") then
    start, stop = data:find("on.")
    local a = 0
    for i=stop,stop+11 do
      if data:sub(stop+a,stop+a):match("[0-9]") then
        t = { [a] = data:sub(stop+a,stop+a) }
        a = a + 1
        if t[0] == "4" then
          print("ok")
        end
      end
    end
  end

以下代码无法正常工作。它不会打印“ok”。

data = "on482654225954"

  if data:find("on.") then
    start, stop = data:find("on.")
    local a = 0
    for i=stop,stop+11 do
      if data:sub(stop+a,stop+a):match("[0-9]") then
        t = { [a] = data:sub(stop+a,stop+a) }
        a = a + 1
        if t[0] == "4" and t[5] == "4" and t[11] == "4" then
          print("ok")
        end
      end
    end
  end

如何使上面的代码正常工作?

编辑:

程序输出。

程序 'lua.exe''C:\Users\pic.pic-Komputer\Downloads\ZeroBraneStudio\myprograms' 中启动 (pid: 2628)。
0   4
1   8
2   2
3   6
4   5
5   4
6   2
7   2
8   5
9   9
10  5
11  4
程序在 0.06 秒内完成 (pid: 2628)。
点赞
用户2858170
用户2858170

这是一个永远不会包含超过一个元素的表格。

t = { [a] = data:sub(stop+a,stop+a) }
a = a + 1
if t[0] == "4" and t[5] == "4" and t[11] == "4" then
   print("ok")
end

如果你只有一个元素,那么永远不可能有3个元素同时有值。

2018-03-16 12:23:00
用户107090
用户107090

我觉得你的代码可以被这个替换:

if data:match("on4....4.....4") then
   print("ok")
end
2018-03-16 12:26:33