在 remix IDE 中编译我的代码时遇到问题

凯尔特人队

尝试编写石头、纸、剪刀游戏,但无法编译合约代码:

我得到的当前错误是: ParserError: Expected '(' but got identifier -->

我想我在某处遗漏了 { 或 ),但我不确定在哪里。帮助表示赞赏!

填充文字 填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字填充文字 填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字 文字填充文字

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

/**
 * @title Storage
 * @dev Store & retrieve value in a variable
 */
contract Game {

    uint8 constant ROCK = 0;
    uint8 constant PAPER = 1;
    uint8 constant SCISSORS = 2;
    address[] public players;

    // the public keyword will create a function with the same name as the mapping which will allow us to lookup the key outside the contract
    // no data is ever hidden in a smart contract deployed on a public chain and using `private` will not hide data in any way.
    mapping(address => uint8) public choices;
    
    
    function enroll() public payable {
        require(msg.value > .01 ether);

        players.push(msg.sender);
    }

    function play(uint8 choice) external {
        // check that the move is valid
        require(choice == ROCK || choice == PAPER || choice == SCISSORS);
        // check that the player hasnt played the move already
        require(choices[msg.sender] == 0);
        // set the choice for the players address
        choices[msg.sender] = choice;
    }

  function evaluate(address alice, address bob)
        public
        view
        returns (address add)
    {
        // if the choices are the same, the game is a draw, therefore returning 0x0000000000000000000000000000000000000000 as the winner
        if (choices[alice] == choices[bob]) {
            return address(0);
        }

        // paper beats rock bob/alice
        if (choices[alice] == ROCK && choices[bob] == PAPER) {
            return bob;
            // paper still beats rock (played in opposite alice/bob)
        } else if (choices[bob] == ROCK && choices[alice] == PAPER) {
            return alice;
        } else if (choices[alice] == SCISSORS && choices[bob] == PAPER) {
            return alice;
        } else if (choices[bob] == SCISSORS && choices[alice] == PAPER) {
            return bob;
        } else if (choices[alice] == ROCK && choices[bob] == SCISSORS) {
            return alice;
        } else if (choices[bob] == ROCK && choices[alice] == SCISSORS) {
            return bob;
        }

    
    function pickWinner(address bob, address alice) public payable {
        if (evaluate(alice, bob) == bob) {
            bob.transfer(address(this).balance);
        }
        if (evaluate(alice, bob) == alice) {
            alice.transfer(address(this).balance);
        }
        players = new address[](0);
    }
    }        

        
        
    
   
}
恩曼纽尔·罗德里格斯·帕斯

您错误地包含了“评估”功能。您需要将第 72 行的花括号移动到第 61 行。此外,我认为您必须在“pickWinner”函数中设置支付给 bob 和 alice 地址。做这两件事你就会有这个:

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

/**
 * @title Storage
 * @dev Store & retrieve value in a variable
 */
contract Game {

    uint8 constant ROCK = 0;
    uint8 constant PAPER = 1;
    uint8 constant SCISSORS = 2;
    address[] public players;

    // the public keyword will create a function with the same name as the mapping which will allow us to lookup the key outside the contract
    // no data is ever hidden in a smart contract deployed on a public chain and using `private` will not hide data in any way.
    mapping(address => uint8) public choices;
    
    
    function enroll() public payable {
        require(msg.value > .01 ether);

        players.push(msg.sender);
    }

    function play(uint8 choice) external {
        // check that the move is valid
        require(choice == ROCK || choice == PAPER || choice == SCISSORS);
        // check that the player hasnt played the move already
        require(choices[msg.sender] == 0);
        // set the choice for the players address
        choices[msg.sender] = choice;
    }

  function evaluate(address alice, address bob)
        public
        view
        returns (address add)
    {
        // if the choices are the same, the game is a draw, therefore returning 0x0000000000000000000000000000000000000000 as the winner
        if (choices[alice] == choices[bob]) {
            return address(0);
        }

        // paper beats rock bob/alice
        if (choices[alice] == ROCK && choices[bob] == PAPER) {
            return bob;
            // paper still beats rock (played in opposite alice/bob)
        } else if (choices[bob] == ROCK && choices[alice] == PAPER) {
            return alice;
        } else if (choices[alice] == SCISSORS && choices[bob] == PAPER) {
            return alice;
        } else if (choices[bob] == SCISSORS && choices[alice] == PAPER) {
            return bob;
        } else if (choices[alice] == ROCK && choices[bob] == SCISSORS) {
            return alice;
        } else if (choices[bob] == ROCK && choices[alice] == SCISSORS) {
            return bob;
        }
    }
    
    function pickWinner(address payable bob, address payable alice) public payable {
        if (evaluate(alice, bob) == bob) {
            bob.transfer(address(this).balance);
        }
        if (evaluate(alice, bob) == alice) {
            alice.transfer(address(this).balance);
        }
        players = new address[](0);
    }
           

        
        
    
   
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

remix ide中的蓝点有什么用?

为什么 Remix IDE 中的关键字不着色?

在Remix-Solidity IDE中,如何传递参数?

为什么 Remix IDE 中的循环只能写在函数中?

如何安装 Remix IDE 以供离线使用?

无法在Remix IDE中导入库

我正在尝试在 remix ide 中编写一个简单的智能合约,并一次又一次地遇到一般错误。下面是我的代码和错误

在VB6 IDE中设置ImageMagick时遇到问题

生成/编译Resurrection Remix牛轧糖错误

我在使用 lua eclipse ide 时遇到问题,有人可以帮助我吗?

在 Solidity 和 Remix 中恢复执行

关于Openzeppelin合同的Remix中的extcodehash的警告

有没有办法在 Remix IDE 上进行协作?

使用 remix-auth 在 Remix.run 中更新会话

为什么此智能合约功能在使用web3提供程序的Remix IDE上不起作用?

onClick 事件偵聽器在 Remix 中不起作用

新版本的Remix中缺少复制按钮

从 Remix.run 中的服务器获取数据

在编译使用C ++映射的代码时遇到问题

在IDE中预览代码

在OpenCV中编译c ++代码时遇到问题-DisplayImage.cpp(使用gcc和CMake)

openjdk代码编译/ IDE设置

将智能合约从 remix 部署到 azure 区块链时出现问题 - 错误

当我的函数返回 int 时,为什么 Remix 说返回 int256?

我在调试下面的代码时遇到问题。我在Visual Studio中得到正确的输出,

Remix IDE收到错误消息“请在文件资源管理器中选择可以找到合同元数据的文件夹”

我可以在 remix.run 的 Action 函数中访问 Loader 数据吗?

我在确定此 python 代码中两条线的交点时遇到问题

在我的代码中遇到问题以进行多级排序