question

My Studio avatar image
My Studio asked

Check if the title data exist

I was running into a issue while working on my game. Im getting the players Title Data through the GetUserDataRequest

public void GetUserData()
    {
        GetUserDataRequest request = new GetUserDataRequest()
        {
            PlayFabId = myID,
            Keys = null
        };


        PlayFabClientAPI.GetUserData(request, (result) =>
        
         {
            Level = result.Data["Level"].Value;
            


         }, (error) => {
             Debug.Log("Got error retrieving user data:");
             Debug.Log(error.ErrorMessage);
         });


    }
	

Now my problem is that the Key "Level" does not exist in the players Title Data. But if the Key does not exist on the plyers Title Data i want to create the Key in the players Title Data. Sadly i can not find any documentation about checking if the Title Data exist request. Is there any way to check if the Key exist on the players Title 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

·
brendan avatar image
brendan answered

Looking up the key/value pair in the data is the majority of the work on the backend, so the best way to do this would be to poll for the player data, and then check it in the client code to see if it exists.

Alternately, you could use a Cloud Script to pull the user data, check if the values are there, update any missing keys, and then return the full set to the client.

Or you could use a PlayStream action to set starting data/statistics for players, as discussed in this thread: https://community.playfab.com/questions/7056/start-off-every-player-with-certain-player-data-an.html.

2 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.

My Studio avatar image My Studio commented ·

How can i do this to see if they Key exist in the play data before executing a command like ->

If(key exist)

{

]

elseIf(key does not exist)

{

create key in the title data

]

0 Likes 0 ·
brendan avatar image brendan My Studio commented ·

What I was saying was that there is no DoesUserDataExist API call, as it would take almost exactly the same amount of work on the backend to service that call as does the GetUserData call. Your best bet would be to get the user data (specifying that key or not) and then check if the results contain data for that key. Have a look at the basic Cloud Script example (revision 1 in all new titles) - specifically, where we query for the key "last_move_timestamp", checking to see if the key is in the response before trying to use the value.

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.