question

Keith Anderson avatar image
Keith Anderson asked

,How to grab a friends statistic by the name of the statistic.

,

Is there a way to get the name of the Statistic instead of the Index. The index could be unreliable as far as its position within the array if you ever alter the statistics. For instance the stat that im looking for is PlayerStatus. I would like to simply grab the name from the List and then get its value from that.

Thanks

10 |1200

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

Keith Anderson avatar image
Keith Anderson answered
  public void GetFriends()
    {
        foreach (Transform child in friendListWindow)
        {
            Destroy(child.gameObject);
        }


        PlayFabClientAPI.GetFriendsList(new GetFriendsListRequest
        {
            ProfileConstraints = new PlayerProfileViewConstraints
            {
                ShowStatistics = true
            },


            IncludeSteamFriends = false,
            IncludeFacebookFriends = false,
            XboxToken = null
        },
        result =>
        {
            friendsList = result.Friends;
            StartCoroutine(DisplayFriends()); // triggers your UI
        },
        DisplayPlayFabError);
    }

    IEnumerator DisplayFriends()
    {

        foreach (FriendInfo friend in friendsList)
        {
            yield return new WaitForSeconds(.05f);
            GameObject friendObj = Instantiate(friendButtonPrefab, friendListWindow);
            FriendsListButton friendsButtonScript = friendObj.GetComponent<FriendsListButton>();
            friendsButtonScript.friendUsernameText.text = friend.Username;
            friendsButtonScript.UpdatePlayerStatus(friend.Profile.Statistics[8].Value);
            chatToList.Add(friend.Username); // add each friend's username to the list
        }
        chatManagerScript.chatToDropdown.AddOptions(chatToList);  // add the entire list to the dropdown list in ChatTo Dropdown in ChatManager
    }
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.

Keith Anderson avatar image Keith Anderson commented ·

Line 38 is where im using the suggested method of the index to grab the stat. Instead of the index, i would like to grab the name of the stat. That way, it will never be wrong if the array element changes.

0 Likes 0 ·
Rick Chen avatar image Rick Chen ♦ Keith Anderson commented ·

The PlayFabClientAPI.GetFriendsList function with statistic enable returns all statistics, which is a list of object that contains statistic name, version and value. It should be client to filter the name from this statistic list.

For example, you could replace your line 38 with:

  foreach(var stat
in friend.Profile.Statistics)
{
if(stat.Name=="Your Statistic Name Here") //replace the statistic name you want
{
friendsButtonScript.UpdatePlayerStatus(stat.Value);
}
}
1 Like 1 ·
Keith Anderson avatar image Keith Anderson Rick Chen ♦ commented ·

Perfect, thank you. This solved the issues of having to get the value by [index]. Much appreciated!

0 Likes 0 ·
Rick Chen avatar image
Rick Chen answered

Could you please describe how you get the statistic by index? To get a friend’s statistic by name, you could use the CloudScript or your server to call the server API GetPlayerStatistics, and specify the “StatisticNames” in the request body.

10 |1200

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

Keith Anderson avatar image
Keith Anderson answered

I would like to grab the name of the Statistic rather than the [index] of the statistic for this among other reasons. The PlayDayScore somehow duplicated itself and pushed the [index] for PlayerStatus to a different index. This of course is causing issues because im looking for the [index] of Profile.Statistics[index].value. I would like to Profile.Statistics."Statistic_Name".value. That way if the following occurs, I can still get the correct information.

This is on Test2 player.

This is on Test3 Player

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.