3

I want to develop a multi step gambling game, my question is can several transactions be sent to the game contract separately(some first, some after) but all contribute to the result?

3

I've been pondering a similar question. As I see it, the first transaction would instantiate the game, and transactions coming afterwards would advance the game state one step per transaction. Each step would need to be verified (one new block would need to be mined) between each round.

Example:

contract Game {

  mapping (address => uint) playerSteps;

  function NewGame() {
    playerSteps[msg.sender] = 0;
  }

  function NextRound() {
    playerSteps[msg.sender] = playerSteps[msg.sender] + 1;

    if (playerSteps[msg.sender] == 1) {
      // Do stuff in round one
    }

    if (playerSteps[msg.sender] == 2) {
      // Do stuff in round two
    }

    // Etc…

  }

}

Corret me if i'm wrong, still very new to Solidity and not so confident with syntax and variable types.

  • where do you store your game data when the game is not entirely over, and due to your method the block time will considerably affect the game feeling, BTW can you give me some advice about learning the syntax, thank U! – Wang Apr 8 '16 at 1:50
  • In the example above the data is stored in the the variable playerSteps. It is stored there indefinetly and only changes when NextRound() is called. We could clear this the game state when the game ends. If you're totally new to programming I would recommend you learn Javascript before Solidity, because 1) If you want to create a dApp, you need to learn Javascript anyway. It's what makes the app talk to ethereum 2) Javascript has a similar syntax 3) There are a ton of great ways to learn Javascript. I learned through CodeAcademy: codecademy.com/learn/javascript – max Apr 8 '16 at 8:27
  • the game data is saved in the contract's storage? – Wang Apr 8 '16 at 11:26
  • Yes, the data in the variable playerSteps is stored on the blockchain. – max Apr 9 '16 at 17:00
3

Yes, there's nothing stopping you from having multiple turns, with each new transaction on a block being a new turn. You do have to be mindful that all data from previous turns will be public, so make sure you're not leaking information that other players shouldn't see.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.