GitHub | Documentation | Become a Patron

private state



  • Hi There
    I want to make a poker game, and players will have their private cards, and don't want share with other clients. can we store cards in state and only send to specific user ?



  • Maybe I can use @nosync to cards, and make a private msg to cards owner ?



  • Make the clients listen to their own cards something like:
    room.listen("cards/player1/:cards");
    room.listen("cards/player2/:cards");
    etc.


  • administrators

    Hey @gabrieltong, welcome!

    I'd suggest sending the private data you're not synching directly to the only client that should've access to it. I'm using exactly like this on a game I'm currently working on:

    Server-side:

    this.send(client, ['cards', privateCards]);
    

    Client-side:

    room.onMessage.add(function(message) {
      let [type, data] = message;
    
      if (type === "cards") {
        console.log("your cards are:", data);
      }
    });
    

    @jalu's suggestion is handy, but if the user spends some time in the developer console he might retrieve the hands of the other players in order to cheat in the game.



  • Thank you man @endel @jalu
    I think It's perfect to use
    nosync and room.send together.