1

I am playing around with solidity, truffle, and node and i was wondering if I am trying to make a game that allows players to browse a list of games and join the ones they want.

Would it be best to deploy many instances of a base contract for each game instance or perhaps use one contract that tracks all game instances in a linked list of structs and identifiers? I have experimented with both but right now I am writing one contract, that can handle different configurations, and be deployed many times. However, I am wondering how does web-3 track these contract instances? Can I store a contract address and use that to interact with each instance? If not, is there any other way?

// one contract to rule them all?
Contract A { 
 struct GameInstance {
   // state variables here 
 }
 mapping(bytes32 => uint256) idToIndex;
 GameInstance[] activeGames;

 // logic here
}

// many instances
Contract B {
  // state variables here

  // logic here
}

If A (one contract with an Instance struct, ...etc), could/should A inherit B? If it did would the functions in B need to be modified to return values instead of interact within contract state variables? That way they can pass the value to a function in A that interact with a GameInstance struct's state variables?

Contract A is B {

  Contract A { 
   struct GameInstance {
     // state variables here 
   }

  mapping(bytes32 => uint256) idToIndex;
  GameInstance[] activeGames;

  function ex(bytes32 instanceId) {
    uint256 index = idToIndex[instanceId];
    activeGames[index].example = super.ex(activeGames[index]) ;
  }   
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.