Leaderboard unique usernames

0 votes

Hello,

When i would call following twice:

scoreBoardService.SaveUserScore(leveluserNamescorenew SaveUserScoreCallBack());

Then it would add the same user twice in the leaderboard but for our game i would like to ensure that the same user only exists once in the leaderboard. Basically simply updating his score.

i know that there is:

scoreBoardService.GetLastScoreByUser(leveluserNamenew LastScoreByUserCallBack());

So i would query first "GetLastScoreByUser" and if i get a return value from that i would change that score.But i am unsure how this callback system works. Where would use the "GetLastScoreByUser" function?
In the SaveUserScoreCallBack class?

Any example for this case would be highly appreciated.

 

 

asked Nov 26, 2014 in App42 Cloud API-BaaS by rainer (10 points)

1 Answer

0 votes

Hello Rainer,

 
First you have to call the get last score by user and if user score exist for the game you can edit that score using his score id by using editScoreValueById method as shown in the below code snippet:
 
 
String gameName = "<Enter_your_game_name>";
String userName = "Nick";
App42Log.SetDebug(true); //Print output in your editor console
scoreBoardService.GetLastScoreByUser(gameName, userName, new UnityCallBack()); 
public class UnityCallBack : App42CallBack
{
public void OnSuccess(object response)
{
Game game = (Game) response;     
if(game.GetScoreList()[0].GetScoreId() != null){
double newScore = game.GetScoreList()[0].GetValue() + 3500;
String scoreId = game.GetScoreList()[0].GetScoreId();
scoreBoardService.EditScoreValueById(scoreId, newScore, new EditUserScoreCallBack()); 
}
}
 
public void OnException(Exception e)
{
 
double gameScore = 3500;
scoreBoardService.SaveUserScore(gameName, userName, gameScore, new SaveUserScoreCallBack()); 
}
}
 
 
Let us know if it helps.
Himanshu Sharma

 

answered Nov 27, 2014 by hs00105 (2,005 points)
Thanks for your Support.

That's also how far i got but how would i go about passing the score to the callback class? You currently tell the class to add 3500 but i would like to pass this value to the class.

I was also wondering if there would be a more easy way around those callbacks as i would need to write a custom callback class for most of my API calls?
You can pass this value to call back using static/instance variable from other class. It is hard coded just in the snippet though.
Yes, you have to write a callback for each of your method call. Either you can have single callback class and do the handling for all return value or you can create separate call back for each of the method call.
Let me know if this answers your question.
Himanshu Sharma
I hope your query has been resolved. Let us know if you have more questions for us.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...