question

Kamil avatar image
Kamil asked

Groups: Wrong number of members on ListGroupMembersResponse

Hello,

I have a strange problem. When I try to get the number of members of a specific group, it always gets a number different from the actual value. I attach the code used below:

public void ListGroupMembers(string groupId)
        {
            var request = new ListGroupMembersRequest { Group = EntityKeyMaker(groupId, "group") };
            PlayFabGroupsAPI.ListGroupMembers(request, OnListGroupMembers, OnSharedError);
        }

        private void OnListGroupMembers(ListGroupMembersResponse response)
        {
            Debug.Log("Count: " + response.Members.Count.ToString());


            for (int i = 0; i < response.Members.Count - 1; i++)
            {
                Debug.Log("Member: " + response.Members[i].Members[i].Key.Id);
            }
        }

The code used under the function start button is as follows:

 PlayFabGroupsAPI.GetGroup(new GetGroupRequest { GroupName = groupName },
               result => { groupEntity = result.Group; Debug.Log(groupEntity.Id); },
               fail => { Debug.Log(fail.GenerateErrorReport()); });


ListGroupMembers(groupEntity.Id);

The result of the above code is:

But on the PlayFab Dashboard, the same group has more members:

Do you have any idea where this error might come from? I have similar problem with ListMemershipRequest (Not all player's groups are displayed, e.g. seven groups from fourteen from simple test - I wrote the code in a similar way as above with ListGroupMemebersRequest).

Thank you in advance for your answer.

unity3d
unitydebug.jpg (7.5 KiB)
10 |1200

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

Gosen Gao avatar image
Gosen Gao answered

There is a mistake in your ‘for’ loop. It can only print one Member of each response.Member. As response.Member is the roles of this group, the number of members will equal to(less than) the number of rules.

You may try the code below.

foreach (var role in response.Members){
    foreach (var member in role.Members){
        Debug.Log("Member:" + member.Key.Id);
    }
}
1 comment
10 |1200

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

Kamil avatar image Kamil commented ·

I tested it and this time I got a full list of group members. Thank you.

0 Likes 0 ·
contrejo27 avatar image
contrejo27 answered

the listgroupmembers response Members is an entity member roles, you might be counting the number of roles you have. you have to go into the role you want and count those.

I'm sure there's a way better way of doing this and I'd love to know how to traverse this object but this is what I'm doing in cloudscript.

    


    var groupMembers =  entity.ListGroupMembers({
            Group:  tournamentEntity,
    });

    for(var role of groupMembers.Members){
        if(role.RoleId == "members"){
            for (var member of role.Members) {
                if(member.Key.Id == playerID){
                  currentPlayerIndex = playerIndex;
                }
                playerIndex++;
            }
        }
    }
    
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.