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())
Run Code Online (Sandbox Code Playgroud)
不知道这个脚本有什么问题,感谢你们的一些意见.虽然错误在第19行说明:
print("Player One wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo..)
Run Code Online (Sandbox Code Playgroud)
那个预计接近')'
最后有一个串联call(..),但它只有一个参数.删除那个,那应该修复错误.请记住,连接意味着将两个字符串一起添加,它必须有两个参数.
print("Player One wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo)
Run Code Online (Sandbox Code Playgroud)
您还需要更改表名称或函数名称,因为它们是冲突的.