Solidity – Fixing struct.push Error: Member ‘push’ Not Found in Solidity

solidity

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract SimpleToken is ERC20{
    constructor(uint256 initialSupply) ERC20("SimpleToken", "ALPH") {
        _mint(msg.sender, initialSupply);
    }

    FFA[] public FFAArray;


    struct FFA
    {
        string Name;
        address Creator;
        address Wallet;
        uint8 entryFee;
        uint256 maxentries;
        uint8 validatorReward;
    }


    function CreateFFA(string memory _Name,uint256 _maxentries,uint256 _entryFee,uint8 _validatorReward) public
    {
        FFAArray.push(_Name,msg.sender,msg.sender,_entryFee,_maxentries,_validatorReward);
    }
} 

Error:Member "push" not found or not visible after argument-dependent lookup in struct at FFAArray.push(_Name,msg.sender,msg.sender,_entryFee,_maxentries,_validatorReward);
Can someone tell me why i am getting this error its like solidity thinks FFAArray is not array but struct

Best Answer

You must passed the struct defined into FFAarray variable. In your line of code:

FFAArray.push(_Name,msg.sender,msg.sender,_entryFee,_maxentries,_validatorReward);

you aren't defining a new instance of struct but you're passing the parameters to the array while these last have to passed to a new instance of struct. Having said that, you can use this way to insert a new FFA's struct.

function CreateFFA(string memory _Name, uint256 _maxentries, uint8 _entryFee, uint8 _validatorReward) public
{
    FFAArray.push(FFA(_Name, msg.sender, msg.sender, _entryFee, _maxentries, _validatorReward));
}