这个lua脚本有什么问题

law*_*s16 2 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())
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)

那个预计接近')'

mey*_*er9 6

最后有一个串联call(..),但它只有一个参数.删除那个,那应该修复错误.请记住,连接意味着将两个字符串一起添加,它必须有两个参数.

print("Player One wins\n Player One played "..playerOne.."\n Player Two played "..playerTwo)
Run Code Online (Sandbox Code Playgroud)

您还需要更改表名称或函数名称,因为它们是冲突的.

  • 只是为了澄清,Lua值,如表和函数没有名称; 变量呢.您可以完全自由地为变量RPS分配一个表值,然后分配一个函数值.出现问题是因为当函数运行时,RPS引用它并且代码将它视为引用表. (2认同)