cancel
Showing results for 
Search instead for 
Did you mean: 

Friend Leaderboards - Request "after rank"

DaffyTheBunny
Honored Guest

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 scores. However, when displaying "Friends only" there does not appear to be an equivalent function.

In my game, I have a "go to top", "page up", page down" and "go to bottom" button. I am not sure how to implement this functionality with the available functions.

How have other devs handled this?

It seems to me that the "GetEntries" function should allow a specific "StartAt" position.

Is there a limit to how many friends a player can have? I am guessing that I just have to request all friends and then just handle it myself?

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions

DaffyTheBunny
Honored Guest

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.

View solution in original post

1 REPLY 1

DaffyTheBunny
Honored Guest

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.