lua编程问题!本人是个小菜鸟,这个错误不知道怎么回事!
ss=io.read()functionGetWeekDay(ss)tw={"刺刀","石头","火枪","大炮","导弹","尼泊尔","潘多拉"}returntw[s...
ss = io.read()
function GetWeekDay(ss)
tw ={"刺刀","石头","火枪","大炮","导弹","尼泊尔","潘多拉"}
return tw[ss]
end
io.write(GetWeekDay(ss))
错误
ua: 测试1.lua:32: bad argument #1 to 'write' (string expected, got nil)
stack traceback:
[C]: in function 'write'
测试1.lua:32: in main chunk
[C]: ?
>Exit code: 1 展开
function GetWeekDay(ss)
tw ={"刺刀","石头","火枪","大炮","导弹","尼泊尔","潘多拉"}
return tw[ss]
end
io.write(GetWeekDay(ss))
错误
ua: 测试1.lua:32: bad argument #1 to 'write' (string expected, got nil)
stack traceback:
[C]: in function 'write'
测试1.lua:32: in main chunk
[C]: ?
>Exit code: 1 展开
1个回答
展开全部
ss = io.read()
function GetWeekDay(ss)
tw ={"刺刀","石头","火枪","大炮","导弹","尼泊尔","潘多拉"}
return tw[tonumber(ss)]
end
io.write(GetWeekDay(ss))
你要注意 lua可以使用字符串作为table的下标 这里把字符串转化成数字就好了
function GetWeekDay(ss)
tw ={"刺刀","石头","火枪","大炮","导弹","尼泊尔","潘多拉"}
return tw[tonumber(ss)]
end
io.write(GetWeekDay(ss))
你要注意 lua可以使用字符串作为table的下标 这里把字符串转化成数字就好了
追问
大哥 可否传授我点学习lua的经验。这一个问题虽小去代表着 无穷无尽的其他问题。我想找个明白的人指导我学习
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询