Lua:将表格值连接为字符串

我想使用Lua随机生成的值放入一个字符串中,但是我一直得到错误。

function main()

times = 0

while times < 10 do

    ValueOne = {"1","2","3","4","5"}
    ValueTwo = {"1","2","3","4","5"}

    aval = math.random(1,#ValueOne)
    bval = math.random(1,#ValueTwo)

    a = ValueOne[aval]
    b = ValueTwo[bval]

    print ("Generated Values: " ..a.." "..b)

    times = times + 1

end

end
main()

我得到了这个错误:

Exception in thread "main" com.naef.jnlua.LuaRuntimeException: ...Eclipse\Lua\workspace\My_Project\src\main.lua:13: attempt to concatenate global 'b' (a nil value)
at com.naef.jnlua.LuaState.lua_pcall(Native Method)
at com.naef.jnlua.LuaState.call(LuaState.java:555)
at org.eclipse.koneki.ldt.support.lua51.internal.interpreter.JNLua51Launcher.run(JNLua51Launcher.java:122)
at org.eclipse.koneki.ldt.support.lua51.internal.interpreter.JNLua51Launcher.main(JNLua51Launcher.java:137)

这意味着出现了某种原因导致变量“b”无法连接。 我可能做错了什么。 请帮忙。

点赞