question

andalexopoulos@gmail.com avatar image
andalexopoulos@gmail.com asked

Can't seem to understand how Shared Group Data work

I am having trouble understanding exactly how SharedGroupData works, so i have a couple of questions to help me clear things up in my head, but first i will write what I (think) I know:

  1. When i use CreateSharedGroup (client call), a group is made with whatever SharedGroupId I give it (let's say FriendRequests)
  2. So now the player that was logged in and called this method is now in a SharedGroup FriendRequests
  3. I log in with another player and try to Create the same Shared group but it is not possible, so i think i have to add a member in order to have that player be in that SharedGroup.

If the above are correct, i would like to know how it is possible to use the two-way friend request as mentioned in this post, because my first understanding was that every player has his own SharedGroupData.

10 |1200

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

Hamza Lazaar avatar image
Hamza Lazaar answered

I think Brendan missed this topic. Otherwise he would have been the first to answer.

You are asking two different questions:

1. How to use SharedGroups:

What you mentioned in your question is correct. A SharedGroupID should be unique and a SharedGroup can't be created with an ID already used unless the other SharedGroup is deleted. 

PlayFab recommends using SharedGroups from CloudScript only. But the Client API methods exist for a reason.

2. How to make "two-way consent" friend system:

This better be done via CloudScript.

Each player must have a pre existing SharedGroup created when signing in for the first time or just after sign up. 

To make the SharedGroup ID unique per player you should include the PlayFabID in it: "{currentPlayerId}_FriendRequests".

Then you can have at least 3 handlers for this friend system:

  • sendFriendRequest: add a request in the friend requests list of the player to be friend with 
  • updateFriendRequest (this can be split into "acceptFriendRequest" and "declineFriendRequest"): update the request inside current player's list. In both cases, the request should be deleted to clear space for more friends.
  • getFriendRequests: return all friend requests from current player's list

A request is a key/value that can be this way:

  • key: PlayFabId of the player requesting friendship
  • value: JSON with properties like timestamp, custom message, etc.

I wanted to simplify the system but you may also:

  • keep the list of pending friendship requests (invitations sent). You'll have to choose whether store incoming and outgoing requests in the same SharedGroup or make 2. 
  • add an expiration to the requests
  • push notifications

You need to take into consideration PlayFab limits:

  • you need to optimize  handlers to not exceed 10API calls per CloudScript call.
  • you can't have more than 100 pending friend requests
  • you can't have more than 256 friends
10 |1200

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

brendan avatar image
brendan answered

Thanks, Hamza - yes, it would appear that my subscription to this forum is occasionally turning off on its own. I've submitted a ticket with ZenDesk to get that cleared up.

And yes, exactly so - each Shared Group Data must have a unique ID, and the best practice is to use the PlayFab ID of the user as part of the ID, for a Shared Group Data which is meant to be unique to that user.

10 |1200

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

andalexopoulos@gmail.com avatar image
andalexopoulos@gmail.com answered

Ah I see! For some reason I though that SharedGroupData was unique to each user so every user could have a for example "Test" SharedGroupData, my mistake. Thank you for your reply!

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.