这个 lua 脚本有什么问题?

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())

这个脚本有问题,希望大家能提供一些意见。尽管错误在第19行:

    print("Player One wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo..)

提示附近有一个")"应该在哪里。

点赞
用户2537322
用户2537322

注意,这行代码中有一个连接调用(..),但是只有一个参数。删除它,这样应该就能解决错误了。记住,连接表示将两个字符串相加,因此必须有两个参数。

print("Player One wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo)

您还需要更改表名或函数名,因为它们冲突了。

2014-12-18 01:12:57