question

Ryan Ross avatar image
Ryan Ross asked

Saving, reading, and writing game state

I'm making a collectible card game like hearthstone.  I'd like to save players, hand, deck, and minions for server side validation and persistence (in case of disconnect). Ideally I want to save a 'room' and state where I'm reading and writing to it.  I think I would save it in json format as follows.

{ room: someid,

      state: [  {player1Id: PlayFabId,

                    health: 30

 

                    deck: Id's,

                    hand: Id's,

                    board: [array of minions]

                },  {player2Id:PlayFabId,

                    health: 30

                    deck: Id's,

                    hand: Id's,

                    board: [array of minions]

                 }

   ] 

}

 

What is the most optimal way for updating/editing this information?  

1. Player plays a card from hand, remove card from hand

2. Card creates a minion, add minion to player's board

3. Player1 uses minion to attack Player2 minion

Am I right in thinking to use one json string to represent the data? and if so, where should I store it (Title Data) ?

Thank you for your time.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

It really depends upon the specifics of what you're writing, but yes, you could store this as a single JSON object, stringified. In particular, since many of the elements of the player's own data would change each hand, and that each player likely affects the health and board status for the other, it does make sense to do so.

Title Data is used for global data that all players need to be able to read - things like configuration data for the title and the like.

In this case, it would make more sense to use Shared Group Data, updating it with the state of the game each time a player finishes a move. There's a write-up of one potential way to do this (as well as some info on using Photon as part of the solution) in this thread: https://community.playfab.com/hc/en-us/community/posts/207129407-Persistent-turn-based-games-

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.