question

Douglas Winning avatar image
Douglas Winning asked

Get Shared Group Data and add to List of Group Data Syntax for Turn Based Game

Hello PlayFab Community,

I have a question about the syntax of storing Shared Group Data. I am staring off using Shared Group Data to store the gamestate of a persistent asynchronous turn-based game in Unity.

Currently my solution is to create a Shared Group Data that has keys of "Player1" and "Player2" and those values contain their playfabIDs. The Shared Group Data also contains a blank "GameState". At the same time, I add the ID of that Shared Group Data to both players's User Data in a comma-separated value called "Games"

If I want to retrieve a list of Shared Group Datas as a list of dictionaries, what would the syntax for that be? I already have declared and parsed a List<string> called myGamesList that contains all the individual game names in "Games" as their own strings. Then for redundancy, I want to add a Key&Value pair to this dictionary like this: {"GroupID", SharedGroupId} that stores its own name of the game;

In addition, are there any limitations to using Shared Group Data in this way that I should know about?

public List<string> myGamesList = new List<string>();

// public List<Dictionary<string, string>> myGamesDetails = new List<Dictionary<string, string>>();
// What is the proper way to declare this?

public void GetMyGamesDetails()
    {
        foreach (var game in myGamesList)
        {
            PlayFabClientAPI.GetSharedGroupData(new GetSharedGroupDataRequest
            {
                SharedGroupId = game,
                Keys = null


            }, gotSharedDataResult =>
            {
                //myGamesDetails.Add(gotSharedDataResult.Data as Dictionary<string, string>);
		// How do I convert this?
		// 
		// Then I want to add a Key & Value to this dictionary called {"GroupID", SharedGroupId}


            }, getSharedDataError =>
            {

		Debug.Log("Error Getting Shared Group Data")
            });
        }

Thank you for your help :)

-Doug

Player DataShared Group Data
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

·
Seth Du avatar image
Seth Du answered

May I ask can you provide your data in JSON format so that I can help?

Is it like the below?

{
    "Player1": "xxxxxxxxxxx",
    "Player2": "xxxxddddddd",
    "GameState":[{
    	"turn1": "asdasdasdasd",
    	"turn2":"asdasdasdasdads",
    	"turn3":"asdasdasddsfsdf"
	}]
}<br>

Basically, if it is in C#/Unity, You cannot not store another object inside the value of a dictionary key, but you can store multiple objects as list in a value field and GetSharedGroupData API will return a string for this value:

"GameState[0]": {
  "Value": "{\r\n  \"turn1\": \"asdasdasdasd\",\r\n  \"turn2\": \"asdasdasdasdads\",\r\n  \"turn3\": \"asdasdasddsfsdf\"\r\n}",
  "LastUpdated": "2020-04-01T03:13:10.362Z",
  "Permission": "Public"
},
"Player1": {
  "Value": "xxxxxxxxxxx",
  "LastUpdated": "2020-04-01T03:13:10.347Z",
  "Permission": "Public"
},
"Player2": {
  "Value": "xxxxddddddd",
  "LastUpdated": "2020-04-01T03:13:10.362Z",
  "Permission": "Public"
}
3 comments
10 |1200

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

Seth Du avatar image Seth Du ♦ commented ·

In this scenario, you can get each value via, for example, OnSuccessCallback.Data["Player2"].Value

In addition, "GameState[0]" is, in fact, an issue because it should be simply "GameState", I will inform the team about it.

1 Like 1 ·
Douglas Winning avatar image Douglas Winning Seth Du ♦ commented ·

Thanks for the answer! Why didn't I think of that :)
I was hoping to be able to retrieve all of the data and store it as is, but I guess I only need a few defined individual values.

0 Likes 0 ·
Douglas Winning avatar image Douglas Winning commented ·

SethDu,

Yes, that is exactly the intended data. Is there a convenient way to get and store multiple of these all in one place client-side? That way I can show the user all the games they are a part of when they sign in.

Thank you for your reply,

Doug

0 Likes 0 ·

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.