Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by Muhammad Roshaan Tariq · Mar 23, 2020 at 07:43 PM · CloudScriptapissdksentities

How to check if User is part of a group at the same time when using ListMembership function

Hi,

I have developed Clan System in my game and I have coded everything on server-side to make it more secure and I have used ListMembership function in which Title is the admin and using this function I am listing all the available or created groups to my players.

here's my server side code:

handlers.getAllGroupsList = function(args,context){
  var groupMembersList = entity.ListMembership({
          Entity:{
              Id: args.Id,
              Type: "title",
              TypeString: "title"
          }
      });
       
      return groupMembersList;
};


handlers.checkIfGroupMember = function(args,context){
  var checkMemberRequest = {
      "Group": {
          "Id": args.groupID
      },
      "Entity":{
          "Id": args.userID,
          "Type": "title_player_account",
          "TypeString": "title_player_account"
      }
  };
  
  var response = entity.IsMember(checkMemberRequest);
  return response;
};

The next step I am doing is to show the users if they are part of the group or not? So I used IsMember function and it returns the value on which I modify my UI/UX

Now when I am doing this on client side using a loop in which I call my function against each groupID and check if the current player is the member or not.

here's my client side code:

public void ShowAvailableClans()
{
    ObjectUtilities.Instance.DeleteAllInstantiatedObjects(clanPrefabList);
    StartCoroutine(ShowClanAsync());
}


private IEnumerator ShowClanAsync()
{
    Home.Instance.BlurCanvasForBlocking(true);
    PlayfabClan.Instance.GetAllGroupsList();
    yield return new WaitUntil(() => PlayfabClan.Instance.requestCompleted == true);


    for(int i = 0; i < PlayfabClan.Instance.myGroups.Groups.Count; i++)
    {
        int index = i;
        GameObject temp = Instantiate(joinClanPrefab, joinClanParent);
        clanPrefabList.Add(temp);


        temp.transform.GetChild(0).GetComponent<Text>().text = PlayfabClan.Instance.myGroups.Groups[index].GroupName;
        PlayfabClan.Instance.CheckGroupMembership(PlayfabClan.Instance.myGroups.Groups[index].Group.Id);
        yield return new WaitUntil(() => PlayfabClan.Instance.requestCompleted == true);


        if (PlayfabClan.Instance.groupMemberInfo.IsMember)
        {
            temp.transform.GetChild(1).GetComponentInChildren<Text>().text = "Leave";


            Button button = temp.GetComponentInChildren<Button>();
            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() => LeaveGroup(PlayfabClan.Instance.myGroups.Groups[index].Group.Id));
        }


        else
        {
            temp.transform.GetChild(1).GetComponentInChildren<Text>().text = "Join";


            Button button = temp.GetComponentInChildren<Button>();
            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() => JoinGroup(PlayfabClan.Instance.myGroups.Groups[index].Group.Id));
        }
    }


    Home.Instance.BlurCanvasForBlocking(false);
    StopCoroutine(ShowClanAsync());
}

Now it is a time taking process and I want to do something in which I send the list of groupID and it returns me the list of booleans indicating my player's membership in each group.

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Sarah Zhang · Mar 25, 2020 at 08:11 AM

Currently, IsMember is the only PlayFab API that can directly check to see if an entity is a member of a group or role within the group. You can combine it with your custom code to encapsulate your own functions on CloudScript to implement the batch checking feature. Please refer to the limitations of Cloud Script of your title(navigate to https://developer.playfab.com/en-US/[TitleId]/limits to check them)to design this method.

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Muhammad Roshaan Tariq · Mar 25, 2020 at 11:41 AM

@Sarah Zhang

Can you please guide me through how can I combine APIs?

Comment

People who like this

0 Show 5 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sarah Zhang · Mar 26, 2020 at 08:31 AM 0
Share

I checked your question again. Actually, if what you are concerned about is the long execution time. Writing a custom method on CloudScript cannot solve the problem. To improve execution efficiency, we should play multithreaded performance on the client or server. Could you please tell us which is the platform of the client? Is it Unity? Besides, please provide the current execution time as a reference.

avatar image Muhammad Roshaan Tariq Sarah Zhang · Mar 26, 2020 at 10:48 AM 0
Share

@Sarah Zhang

Yes the platform is Unity and about execution time is 19 seconds approx on my PC. And total number of groups loaded are 19 which makes it 1 second per group

(This is the time in which I load the group from server and then also check it's membership from server)

This is why I'm looking for a way to combine these two functions into one so that I don't have to use a loop as mentioned above in question

avatar image Sarah Zhang Muhammad Roshaan Tariq · Apr 13, 2020 at 04:39 PM 0
Share

We test to call the getAllGroupsList function once on the client, add the GroupID to a list manually then call checkIfGroupMember asynchronously (just call this function in the loop but don't use WaitUntil). The execution time can be greatly reduced.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    4 People are following this question.

    avatar image avatar image avatar image avatar image

    Related Questions

    Sending Telemetry events from Server 1 Answer

    Cloudscript returning NULL in Response 1 Answer

    How to create a custom Group system using CloudScript? 1 Answer

    What should be used to integrate Chat System in Playfab Groups/Clans? 3 Answers

    How to get List of Clans/Groups available to Join? 2 Answers

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges