Score board save time as score

0 votes
Hi! I'm creating a memory card game and the score is the time of play
 
How can I save time as score with app24 score board?
asked Jul 30, 2014 in App42 Cloud API-BaaS by alissonsalin (30 points)

1 Answer

0 votes
 
Best answer

Hi Alissonsalin,

You can use saveUserScore method to save the leaderboard. Use currentTimeMills to find the current time during the beginning and end of the game. The result will be time in milliseconds. If you want you can further convert it into seconds or minutes and save that using saveUserScore.

You can use the following code snippet for saving your user's score:

 

App42API.initialize("API_KEY","SECRET_KEY");
ScoreBoardService scoreBoardService = App42API.buildScoreBoardService();
GameService gameService = App42API.buildGameService();
gameService.createGame("Your Game Name", "Your Game Descrption");
long startTime = System.currentTimeMillis();
long endTime = System.currentTimeMillis();
long timeDiff = (endTime-startTime);
Game game = scoreBoardService.saveUserScore("Your Game Name", "Alissonsalin", new BigDecimal(timeDiff));
System.out.println("Game Response is :"+ game);
 
// Naresh

 

answered Jul 30, 2014 by naresh (350 points)
selected Jul 31, 2014 by alissonsalin
Thank you! One more question: The best score is the lowest time. How can I get top 10 lowest score?
Get top 10 score time
Hi Alissonsalin,
 
To get the top 10 lowest scores, you need to call getTopNRankers API.
And before that you need to set other meta headers by calling setOtherMetaHeaders API on scoreboardService and in those meta headers, you have to put orderByAscending as key and score as value.

For more details see our API Docs (http://api.shephertz.com/app42-docs/leaderboard-service/#get-top-n-rankers-by-sorting)
It works! Thank you!
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
...