question

Kim Strasser avatar image
Kim Strasser asked

How can I get a player's tags when I call server.GetFriendsList?

I want to find out if the player has a certain player tag("blocked") but I don't know how to get the player's tags in CloudScript. My code returns 1 for element.Tags.length. This is correct because the player has 1 tag. But element.Tags is always empty, it doesn't return the player's tag.

How can I get the player's tags when I call server.GetFriendsList? I need to find out if the player has a certain tag.

var result = server.GetFriendsList( 
{ 
  "PlayFabId":friendid, 
  "ProfileConstraints":
  {"ShowTags":true
  }
});

if ((result != null) && (result.Error == null))
{ 
  result.Friends.forEach(element => {
  if (element.FriendPlayFabId == currentPlayerId)
  {
    log.info("element.Tags.length: " + element.Tags.length + " " + element.Tags);
    if ((element.Tags.length > 0) && (friendblocked == false))
    {
      element.Tags.forEach(tag => {
      log.info("current tag: " + tag);
      if (tag == "blocked")
      {
        friendblocked = true;
      }
      });
    }
  }
  });
}
else
{
  log.info("error");
  errorcode = result.Error;
}
CloudScript
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

·
Made Wang avatar image
Made Wang answered

In my test the script reported an error on line 15, the error is that friendblocked is not defined. After adding "var friendblocked=false;" the script works as expected.

You can set GeneratePlayStreamEvent to true when calling ExecuteCloudScript to check whether the script runs successfully in Game Manager->Data->Data Explorer (basic), and you can add "return result;" to get all the information returned.

Also, to clarify, there are two kinds of tags in the result of GetFriendsList, FriendInfo.Tags is added by SetFriendTags, PlayerProfileModel.Tags is added by AddPlayerTag, please make sure which one you are using.

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.

Kim Strasser avatar image Kim Strasser commented ·

I use SetFriendTags to update the players friend tags. I found out that the problem was on the client side. The friend tags were not updated in the client and therefore it displayed different friend tags in the client than in the server code. It was correct that element.Tags was empty in CloudScript.

0 Likes 0 ·

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.