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; }
Answer by Made Wang · Jun 09 at 07:35 AM
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.
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.