I’m having some trouble figuring out a problem in my code. Basically, I have a contract that represents games using structs. I store some details there like the gameId, required buyin to play, etc. But I also want to store player addresses that interact with that specific game: (in an array in the game struct, preferably). I try to append them to the array on initialization but that doesn’t work – I assume due to the static length of the array. I’ve read online about incrementing the length of the players array as they are not dynamic, but honestly I’m not sure how to implement that in this case.
Here is my code for the Game struct:
struct Game {
address host; // Establishes host function access
uint gameId; // Allows different games to be played concurrently
uint buyinRequirement; // To establish minimum buyin amount for a game
uint etherWithdrawalReqs; // Tracks # of ether in total from requests. If >/< than contract balance, throws error
uint gamePot; // Tracks how much ether is in the game's pot
uint8 tableWithdrawalReqs; // Tracks how many players have requested a withdrawal
uint8 playerCount; // Tracks # of of players in a game
uint8 verifiedWithdrawalReqs; // Tracks # of verifs that withdrawal requests are valid
bool endedBuyin; // Host function to end buyin stage
address[] playerList; // Stores player addresses
}
Here is my attempt to initialize the struct:
function initializeGame(string memory name, uint buyinReq) public payable {
idToGame[gameNumber] = Game(msg.sender, gameNumber, buyinReq, 0, 0, 0, 0, 0, false, playerList.push(msg.sender));
games.push(idToGame[gameNumber]);
}
This is the error I get:
DeclarationError: Undeclared identifier.
–> contracts/YourContract.sol:104:93:
|
104 | idToGame[gameNumber] = Game(msg.sender, gameNumber, buyinReq, 0, 0, 0, 0, 0, false, playerList.push(msg.sender));
| ^^^^^^^^^^
Error HH600: Compilation failed
Ultimately, I just need to track addresses tied to a specific game so I can render those addresses to the front end with some other information. If there is an easier way to do this and I’m just overlooking something due to tunnel vision, I’m all ears for alternative solutions.
TYIA!