I'm trying to do something very simple. I want to make a structure that holds the data for a player.
Within that data, I want an array to store things like its inventory, and its current eggs/monsters.
Yet I cannot interact with arrays at all, I'm constantly getting issues. Can someone tell me what I'm doing wrong and why it won't let me read and return arrays?
contract EtherMon{
uint public starterEgg;
address public owner;
struct player{
uint256 goldAmount;
uint[10] listOfEggs;
bool eggCoolDown;
uint eggTime;
uint eggID;
bool battleCoolDown;
bool breedingCoolDown;
uint[] ownedEthermon;
}
mapping (address => player) public listOfPlayers;
function EtherMon(){
owner = msg.sender;
}
function createAccount(){
starterEgg = block.timestamp % 10;
listOfPlayers[msg.sender].goldAmount = 100;
listOfPlayers[msg.sender].listOfEggs[0] = starterEgg;
}
function getCurrentEggs() returns (uint[]) {
uint length = listOfPlayers[msg.sender].listOfEggs.length;
uint[] eggArray;
for(uint i = 0; i < length; i++){
eggArray[i] = listOfPlayers[msg.sender].listOfEggs[i];
}
return eggArray;
}
}
Basically I just want to be able to...
- Call CreateAccount and it stores a random uint into the array that stores the eggs a player holds
- Pull that egg data from the mapping and see it/change it
Can someone give me an example of a structure that holds an array (and mapping because it seems I can use a mapping within a struct but have issues with dynamic arrays) and has getter and setter functions?