salman-hoseini avatar image
salman-hoseini asked

How to get player data (title) with a specific key value

Is there a way to make a server call to fetch players with a specific key value in their stored player data?
To clarify, let's say I'm collecting the last stage a player has visited in a title key called "LastStage". And then I want the current player to see an avatar of other players who have made it through the current stage the player is at using the key "LastStage." To clarify more, the SQL equivalent of what I'm looking for would be something like this:

SELECT TOP 5 p.displayName from PlayerData p where p.LastStage = :currentStage Order By p.displayName

I suspect that I should use a cloud script to get all user data and then filter the desired data from the returned list, but that would be a costly task if the number of players is high.

I was not able to find a server request to get all player data or a request which enables me to filter player data. I am pretty new to Microsoft Azure and Playfab and not sure if this sort of action is even possible. Could you please help me with executing this task and acheiving the desired outcome?

Thanks in advance.

apisCloudScriptPlayer DataPlayStream
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

Seth Du avatar image
Seth Du answered

To be clear, PlayFab doesn't support customized query like database. If the data value is string or JSON, you may need to iteratively call APIs to retrieve data. It is not recommended as you have mentioned, it is costly. Meanwhile, your requirement is more be like something that can be achieved in Leaderboard.

When calling GetLeaderboard API, you can specify ProfileConstraints in the request, and set ShowDisplayName as true to get a list of statistics with additional display name data within. As statistics only allows Int value, you may locally cache a dictionary or mapping data in any other forms so that the client can translate the Int value to the Stage details.

10 |1200

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

salman-hoseini avatar image salman-hoseini commented ·

@SethDu thanks for your reply. I did consider using GetLeaderBoard, but then encountered some blockers. Since Leaderboards are not filterable and I would end up getting all the player names from the leaderboard (with the use of ProfileConstraints) and then filter through them to get those entries with the stage number equal to the current stage, which is not different from the initial solution, am I right? or is there a way to control the result set of GetLeaderboard to return leaderboard entries with a specific value (score)? Like, include a minimum or maximum score in the request.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ salman-hoseini commented ·

Because there is no API that can retrieve a list of all players' Player Data, leaderboard should be a better way than iteratively calling APIs. However, you still need to get all data then filter locally. Using Cloud Script/ Azure Function will make this process low perceived to players, but in my opinion, it is unnecessary due to extra cloud computing hours.

1 Like 1 ·

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.