TypeError: Type is not callable - on compile

TypeError: Type is not callable - on compile

我创建了一个游戏,其中有一个界面和一个带有游戏函数的合约 但是当我编译它时抛出一个异常:

TypeError: 类型不可调用 myGameContract.depositPlayer(0, msg.value)();

很明显是指fallback之后:msg.value)();

但是,我不知道怎么修改界面。

interface Game{
    function depositPlayer(uint256 _pid, uint256 _amount) external payable;

function myGame(address _reciever) external payable {
    addressBoard = payable(_reciever);
    myGameContract= Game(addressBoard );
    myGameContract.depositPlayer(0, msg.value)();

在这种情况下我需要它包含后备 ();

更多内容如下:

For more clarification, comment as the answer indicates, only the call function contains a fallback

您可以执行不带空括号的外部函数。

执行外部depositPlayer函数的例子:

myGameContract.depositPlayer(0, msg.value);  // removed the `()`

您可以通过发送一个空的 data 字段来执行 fallback 函数。

address(myGameContract).call("");

但是当没有找到合适的函数(在data字段中指定)时执行回退函数。它不会在每个函数之后执行。所以你不能在同一个调用中同时执行 depositPlayerfallback(除了从 fallback 执行 depositPlayer)。

当您不小心使参数隐藏函数时,这是一个很容易犯的错误。这里有一个容易理解的地方会弹出这个错误:

 constructor(address owner, address[] memory defaultOperators) ERC777("Shipyard", "SHIP", defaultOperators) {
        transferOwnership(owner);
        ico = address(new ShipICO(this));
        _mint(owner(), INITIAL_SUPPLY, "", "");
        _pause();
    }

请注意,参数 owner_mint(owner()) 行中调用的函数同名。由于具有相同名称的参数,您现在尝试调用 address 类型的参数 owner,就好像它是 function 一样。 (请注意,在这种情况下,owner() 是从 OZ Ownable 合约继承的函数,因此特别容易错过。

简单、常见的约定是添加下划线。在这种情况下,_owner 可能已经被采用,因此您可以在参数的末尾添加下划线 (owner_ )。

关于OP的问题:

这意味着 myGameContract.depositPlayer 不是函数。去弄清楚为什么你认为它是,而编译器认为它不是。