question

gage avatar image
gage asked

OnGetDataSuccess(GetUserDataResult result) iteration and looping

Hi,

Just trying to iterate though the:

GetUserDataResult result

Below is my current methods:

public void GetPlayerData() {
    Debug.Log("GetPlayerData");
    var data = new GetUserDataRequest { PlayFabId = PlayFabSettings.TitleId };
    PlayFabClientAPI.GetUserReadOnlyData(data, OnGetDataSuccess, OnGetDataFailure);
}
private void OnGetDataSuccess(GetUserDataResult result) {
    Debug.Log("OnGetDataSuccess");
    foreach (KeyValuePair<string,UserDataRecord> entry in result.Data) {
        Debug.Log("Key: " + entry.Key + " | Value: " + entry.Value.Value);
    }  
}

However, the Success methods foreach doesnt even fire on success. Am i doing something wrong? Not getting any errors and i do reach that success state.

Player 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

·
pfnathan avatar image
pfnathan answered

You might want to modify the first log line to this:

Debug.Log("OnGetDataSuccess " + result.Data.Count);

**Just to ensure you know why you might not get into the for loop (length == 0)**

As long as you are getting; result.Data.Count > 0 ,It is valid if PlayFab returns an empty dictionary.

Note: You may not have saved any read-only-data yet

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.

gage avatar image gage commented ·

Wow, thanks for pointing that out because the data im setting isnt readonly its normal. Sorry for that. Thats what happens when you are excited for a new solution and just dive into an api.

Side question though, i know i can use the standard get/set data callbacks, but what is the benefit of readonly other than the client cant push to it? I mean the game client still can push to readonly but im just confused on if you would only put the readonly code on a separate client or what, just confusing for my tired brain.

0 Likes 0 ·
brendan avatar image brendan gage commented ·

The benefit is that it's not possible for the client to update it directly, so a hacked client can't write whatever it wants to there. You only write to it from a custom game server or Cloud Script - that way, you can have the server-side logic checking any data sent from the client for validity.

1 Like 1 ·

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.