我希望用户输入为io.read
,然后我想将该变量用作key
表。我对编程知之甚少
这可能吗?
修改
例如
Alpha = {}
print("foo")
Table1 = io.read()
Table1 = tonumber
print(Alpha.Table1)
谢谢!
答案 0 :(得分:2)
是的,您需要将该变量放在方括号中:
local input = io.read() -- get the value from the user
print(tbl[input]) -- access key in "tbl" based on value in "input"
答案 1 :(得分:0)
试试这个:
myTable= {"a", "b", "c"}
i = tonumber(io.read())
if i >= 1 and i <= #myTable then
print(myTable[i])
end