Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
DaffyTheBunny's avatar
DaffyTheBunny
Start Member
1 year ago
Solved

Friend Leaderboards - Request "after rank"

Hi, I am currently implementing leaderboards (in a Unity project). When displaying all data, I can use the "GetEntriesAfterRank" function to allow the user to 'page up' and 'page down' through the ...
  • DaffyTheBunny's avatar
    1 year ago

    I managed to solve the problem. I will share my solution here in case it helps anyone else.

    When dealing with the Friends Leaderboard, I download the entire leaderboard and then selectively show whatever I want. To download the entire leaderboard:

    Leaderboards.GetEntries( szLeaderboardName, 100, LeaderboardFilterType.Friends, LeaderboardStartAt.Top ).OnComplete( OnFriendLeaderboardDataReceived );

    100 is the maximum entries you can request at a time so, we must handle the possibility that the user has more than 100 friends (lucky):

    void OnFriendLeaderboardDataReceived( Message<LeaderboardEntryList> msg )
    {
    	if( !msg.IsError )
    	{
    		LeaderboardEntryList entries = msg.Data;
    
    		// Store the entries here (code removed for brevity)
    
    		// We need to check if there is more data...
    		if( m_NumItemsDownloaded < (int)entries.TotalCount )
    		{
    			// Request more data
    			Leaderboards.GetNextEntries(entries).OnComplete( OnFriendLeaderboardDataReceived );
    		}
    		else
    		{
    			// All data downloaded
    		}
    	}
    	else
    	{
    		Error error = msg.GetError();
    	}
    }

    The nice thing is - you can test the code by limiting the initial call to GetEntries to just 1.

    Hope that helps someone.