Sign In Register

How can we help you today?

Start a new topic
Answered

How to submit and retrieve extra info to a leaderboard

Hi


I'm trying to create a time-based leaderboard where the boards are split into levels. That much I managed to get working, but I also want to be able to submit extra info (such as the gear the player was using when the time was achieved) and be able to to get that info back when retrieving the leaderboards. I've tried all the combinations of options for the event attributes and the leaderboard fields that I can think of to get that to work but just can't. The best I can get is retrieving the last hat that was submitted regardless of whether it was a new highscore or not. 


Should I rather be keeping track of the current players best score for that level and only submit an event when a new highscore is achieved? I assumed that I could submit scores and let the server decide if they're new highscores or not, but I'm less sure now.


Any help would be greatly appreciated.

Thanks

Gavin


Best Answer

So, i have a solution for you.
Im going to put down the setups for the event and leaderboard. I know you know how to do those, but just in case anyone else comes across this post it might help them.


So, first i have an event which will later push time/score to the leaderboard...

The important thing here is that the items you dont want to count towards the leaderboard are set to 'LAST' so they always record the attribute when the player gets into the board.


Then i created a leaderboard which will be updated from the event above and store three attributes...


Then on the client-side you need to call the leaderboard data using the LeaderBoardDataRequest() function and then run through response data to get the time, gear and item info back.


In this case the response.Data will get you a list of LeaderBoardData. A few things will be recognizable there, like the rank and player name but you will need to reference your data with the right keys, in this case the short-code for the attributes you entered for your event...

(For example, in C#...)


 

new GameSparks.Api.Requests.LeaderboardDataRequest()
			.SetLeaderboardShortCode("RACE_LB")
				.SetEntryCount(100)
				.SetDurable (true)
				.Send ((response) => {
					
					if(!response.HasErrors)
					{
						// loop through each element of the data returned. Each of these are of LeaderboardData type //
						foreach(GameSparks.Api.Responses.LeaderboardDataResponse._LeaderboardData lb in response.Data)
						{ 
							int rank = int.Parse(lb.Rank.ToString()); // parse the rank as an int in case you need to, here is an example
							string playerName = lb.UserName;
							string time = lb.JSONData["TIME"].ToString();
							string gear = lb.JSONData["GEAR"].ToString();
							string item = lb.JSONData["ITEM"].ToString();
							// this is just a test to print the data to the console, you can do whatever you want with the data once you have it //
							string outPutConcat =  "Rank:"+rank+"\n  "+"Name: "+playerName+"  "+"Time: "+time+"  "+"Gear: "+gear+"  "+"Item: "+item;
							Debug.Log(outPutConcat); 
						}
					}
				});

 

And you will get the following response in your console...



Hope that helps,
Sean



Hey Gavin,

Is it that you are having problems getting the leaderboard info back out on the client end? Or are you just wondering how to submit extra data into the leaderboard that is not necessary counted towards the high-score (like the gears would be nice to see, but you dont want that number to set the leaderboard rank )?

Thanks,
-Sean

Hi Sean 


I'm able to submit extra data to the leaderboard, that's not a problem, but getting that extra info back on the client end I can't seem to do. As you said, I don't want that info to count towards the rank or to be modified in any way, just stored and then retrieved. So when I log a "new time" event i pass through the new time and the item the player was wearing at the time. If it's a new highscore for that player, I want the entry in the leaderboard to have his best time and what item he was wearing at the time he achieved that time so that when I retrieve that info I can represent it visually.


Hope that makes sense.


Thanks

Gavin

Answer

So, i have a solution for you.
Im going to put down the setups for the event and leaderboard. I know you know how to do those, but just in case anyone else comes across this post it might help them.


So, first i have an event which will later push time/score to the leaderboard...

The important thing here is that the items you dont want to count towards the leaderboard are set to 'LAST' so they always record the attribute when the player gets into the board.


Then i created a leaderboard which will be updated from the event above and store three attributes...


Then on the client-side you need to call the leaderboard data using the LeaderBoardDataRequest() function and then run through response data to get the time, gear and item info back.


In this case the response.Data will get you a list of LeaderBoardData. A few things will be recognizable there, like the rank and player name but you will need to reference your data with the right keys, in this case the short-code for the attributes you entered for your event...

(For example, in C#...)


 

new GameSparks.Api.Requests.LeaderboardDataRequest()
			.SetLeaderboardShortCode("RACE_LB")
				.SetEntryCount(100)
				.SetDurable (true)
				.Send ((response) => {
					
					if(!response.HasErrors)
					{
						// loop through each element of the data returned. Each of these are of LeaderboardData type //
						foreach(GameSparks.Api.Responses.LeaderboardDataResponse._LeaderboardData lb in response.Data)
						{ 
							int rank = int.Parse(lb.Rank.ToString()); // parse the rank as an int in case you need to, here is an example
							string playerName = lb.UserName;
							string time = lb.JSONData["TIME"].ToString();
							string gear = lb.JSONData["GEAR"].ToString();
							string item = lb.JSONData["ITEM"].ToString();
							// this is just a test to print the data to the console, you can do whatever you want with the data once you have it //
							string outPutConcat =  "Rank:"+rank+"\n  "+"Name: "+playerName+"  "+"Time: "+time+"  "+"Gear: "+gear+"  "+"Item: "+item;
							Debug.Log(outPutConcat); 
						}
					}
				});

 

And you will get the following response in your console...



Hope that helps,
Sean


That's great. Thanks a lot.