question

jacob avatar image
jacob asked

server.GetPlayersInSegment returns successfully, but *Empty* function result

Hello,

My problem is this: I am trying to make a Global Leaderboard, where I acquire all the users in my Playfab game and compare them via one of their Virtual Currencies via the "server.GetPlayersInSegment". I've got this working well and my code does indeed work perfectly the first time the player starts the game. The problem occurs on the second call when I attempt to execute my Cloud Script the same way. The CloudScript hits its OnSuccess delegate properly, but its FunctionResult is null. I'm not sure why this would occur and have been trying to figure it out for a while now.


This is not a time issue, as I can wait a minute and the same result occurs. There are not other calls going out at the same time, I am not overloading Playfab API in anyway that I know (and it works the first time perfectly, like I said).

My Title ID: 59E9

My SegmentId: "D53793B198C24BA0" (All Players SegmentID)

UE Engine: 4.15.0 VR Works

Playfab Script:

// Get the leaderboard serverside so we can get the player's tags too (their full displaynames) //
handlers.getLeaderboardWithTags = function (args, context) 
{
    var resultLeaderboard = server.GetPlayersInSegment({
                 SegmentId: "D53793B198C24BA0", // All Players SegmentID //
                 SecondsToLive: 300,
                 MaxBatchSize: 10000
                 //ContinuationToken: false // *Set to "true" when we need to call again and reach over 10,000 Players //
    });
  
    if(resultLeaderboard == null)
        log.debug("resultLeaderboard is null!");
    return { messageValue: resultLeaderboard }; // Return the resultLeaderboard //
};

My Blueprint structure:


My Log:

-------------- BEGIN LOG --------------

- Successful at the start of the game:

Length of array which contains all players in Playfab: 3900 
*DIFFERENT WAY* Length of array which contains all players in Playfab: 0
*DIFFERENT WAY* Warning: 0 players found in Global Leaderboard Gathering process 

- An error in the middle of the game where the function "getLeaderboardWithTags" returns a null FunctionResult:

Warning: RecievedAllLeaderboardPlayers returned Null FunctionResult in Global Leaderboard Gathering process 
LogJson:Warning: Field messageValue was not found. 
LogJson:Error: Json Value of type 'Null' used as a 'Object'.
LogJson:Warning: Field PlayerProfiles was not found. 
LogJson:Error: Json Value of type 'Null' used as a 'Array'. 
*DIFFERENT WAY* Length of array which contains all players in Playfab: 0 
*DIFFERENT WAY* Warning: 0 players found in Global Leaderboard Gathering process

-------------- END LOG --------------

The Json warnings/errors are related to the "Different Way" method.

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

·
brendan avatar image
brendan answered

Well first, GetPlayersInSegment is meant to be used for server-side operations which are not responses to clients. That API call (without a continuation token) does a re-evaluation of the full segment, and so should never be triggered by a client operation. Can you describe the actual game feature you're attempting to enable? The existing leaderboard API queries do return the profile information for the user. What is different about what you're doing that requires the list of all users in the title?

2 comments
10 |1200

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

jacob avatar image jacob commented ·

Hey Brendan, thanks for the fast response!

I am trying to make a Global Leaderboard which takes every Playfab user in my game, and then using their Player Profile, will look at their Virtual Currencies. From that, I can display their VCs, but I also want their name to be displayed along side their VC (as is custom in most leaderboard designs). The reason I'm using "server.GetPlayersInSegment" and not "client.GetLeaderboard" is because I need to be able to get the Player's Tags which is where I store the player's actual Display Name, which can be gathered from the Player Profile in "server.GetPlayersInSegment", but the tags of a player are not given in "client.GetLeaderboard".

Now you may be asking why would I keep the Display Name in a tag and not where it is supposed to be located. The reason for this is because I create a unique ID for each player to guarantee every user has their own PlayFab account, and then we store their Display Name as a tag so that in the event there are duplicate display names, the accounts stay separate.

Do you have any suggestion for making sure my FunctionResult is not null when I call "server.GetPlayersInSegment"?

0 Likes 0 ·
brendan avatar image brendan jacob commented ·

Actually, Tags are returned by the leaderboard call, so you can simply use that for this.

However, I have to advise against using Tags that way, as that's not supported. Tags are meant to be terms that are used to Tag information for groups of users who share aspects you want to track. Having each user have potentially unique Tags isn't what it was designed for. If the issue is that you want to allow players to have non-unique Title Display Names, please turn on that option in the Settings tab ("Allow non-unique player display names"). Each player already has a unique identifier - their PlayFab ID - which can be used to locate their specific info. There's no need to generate another unique identifier.

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.