Solidity error message

Hi, can someone please tell me why this code does not work? It gives the error message…function, variable, struct or declaration expected. At line 5…public playerCount = 0;

Thanks

pragma solidity >=0.7.0 <0.9.0; 

contract FindPlayer {

     public playerCount = 0;   //counts the number of books in array//
     mapping(address => Player) public players;

     enum level {Novice, Intermediate, Advanced}
    

    struct Player {
        address playerAddress;
        level playerLevel;
        string firstName;
        string lastName;
        }

    function AddPlayer(string memory firstName, string memory lastName) public {
        players[msg.sender] = player(msg.sender, level.Novice firstName, lastName);
        playerCount += 1;  //adds the number of books to array in increments of 1//
        }

    function getPlayerAddress(address playerAddress) public view returns(level){
        return players[playerAddress].playerLevel;
        }
}
1 Like

Hey @NetworkP, hope you are ok.

You have mainly syntax errors, here is the same but with some of those errors fixed.

pragma solidity >=0.7.0 <0.9.0; 

contract FindPlayer {

    uint public playerCount = 0;   //counts the number of books in array//
    mapping(address => Player) public players;

     enum level {Novice, Intermediate, Advanced}
    

    struct Player {
        address playerAddress;
        level playerLevel;
        string firstName;
        string lastName;
        }

    function AddPlayer(string memory firstName, string memory lastName) public {
        players[msg.sender] = Player(msg.sender, level.Novice, firstName, lastName);
        playerCount += 1;  //adds the number of books to array in increments of 1//
        }

    function getPlayerAddress(address playerAddress) public view returns(level){
        return players[playerAddress].playerLevel;
        }
}

Carlos Z

Hello theCil,

Thank you for that. I am all good thanks. Hope you are too :+1:

1 Like