什么';这个lua脚本有什么问题
不知道这个脚本有什么问题,感谢你们的一些意见。尽管第19行的错误说明:什么';这个lua脚本有什么问题,lua,Lua,不知道这个脚本有什么问题,感谢你们的一些意见。尽管第19行的错误说明: RPS = {} RPS[1] = "Rock" RPS[2] = "Paper" RPS[3] = "Scissors" function RPS() playerOne = math.random( #RPS ) playerTwo = math.random( #RPS ) if playerOne == playerTwo then print("It is a tie\n
RPS = {}
RPS[1] = "Rock"
RPS[2] = "Paper"
RPS[3] = "Scissors"
function RPS()
playerOne = math.random( #RPS )
playerTwo = math.random( #RPS )
if playerOne == playerTwo then
print("It is a tie\n Player One played "..playerOne.."\n Player Two played "..playerTwo..)
elseif playerOne == RPS[1] then
if playerTwo == RPS[2] then
print("Player Two wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo..)
else
print("Player One wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo..)
end
elseif playerOne == RPS[2] then
if playerTwo == RPS[1] then
print("Player One wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo..)
else
print("Player Two wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo..)
end
else
if playerTwo == RPS[1] then
print("Player Two wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo..)
else
print("Player One wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo..)
end
end
end
print(RPS())
在结尾处有一个连接调用(
。
),但它只有一个参数。删除它,它将修复错误。请记住,连接意味着将两个字符串添加在一起,它必须有两个参数
print("Player One wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo..)
您还需要更改表名或函数名,因为它们相互冲突。意思是说“有一个预期的near')除了下面给出的解决方案之外,您还需要更改函数名或表名,使它们不一样。谢谢,已修复,但我仍然收到一个错误“[错误]lua/rps.lua:6:尝试获取全局“rps”(函数值)1的长度。RPS-lua/RPS.lua:6.2。未知-lua/rps。lua:31“查看你帖子下面的评论。您需要更改函数名,因为它与表名冲突;变量可以。您完全可以自由地为变量RPS分配表值和函数值。出现此问题的原因是,当函数运行时,RPS引用它,而代码将其视为引用表。
print("Player One wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo)