How i can make a leaderboard = smaler is better

0 votes
Hi,

how can i make the leaderboards top ranker by smaler is better?

 

My Score is a timescore and the top Ranker is this one with the smalest score. But in my leaderboard the guy with the largest Time is the Best.

Can anyone help me?

 

Sorry for my english :/

 

Regards Achim
asked Feb 22, 2015 in App42 Cloud API-BaaS by achim1909 (10 points)

1 Answer

0 votes

Hello Achim,

You can sort your leaderboard according to the requirement. Please have a look at this link for the code snippet, It will help you to achieve your goal. Please check and let me know if it helps.

Thanks,

Himanshu Sharma

answered Feb 23, 2015 by hs00105 (2,005 points)
Hello,

thanks for your answer.

I tried this, but at the end, the biggest score stands.

I tried: otherMetaHeaders.put("orderByDescending", "score");

and: otherMetaHeaders.put("orderByAscending", "score");

Always the same Score :(

Achim

PS: There are only entries in "Leaderboard" not in "Scoring"
Could you please share your sdk version in which you are working on?

Thanks,
Himanshu Sharma
I used the App42_ANDROID_SDK_3.2.

Achim
Hello Achim,

Please find a below code snippet and check if you still not able to fetch the desired result then please share your code file with us at support@shephertz.com, it will help us to debug the same at our end:

String gameName = "<Enter_your_game_name>";
int max = 10;
App42API.initialize("ANDROID_APPLICATION_CONTEXT","API_KEY","SECRET_KEY");
ScoreBoardService scoreBoardService = App42API.buildScoreBoardService();
HashMap<String, String> otherMetaHeaders = new HashMap<String, String>();
otherMetaHeaders.put("orderByAscending", "score");// Use orderByDescending for Descending or orderByAscending for Ascending
scoreBoardService.setOtherMetaHeaders(otherMetaHeaders);
scoreBoardService.getTopNRankers(gameName, max, new App42CallBack() {
public void onSuccess(Object response)
{
    Game game = (Game)response;
    System.out.println("Game Name is : "+game.getName());
    for(int i = 0;i<game.getScoreList().size();i++)
    {
        System.out.println("userName is : " + game.getScoreList().get(i).getUserName());
        System.out.println("score is : " + game.getScoreList().get(i).getValue());
        System.out.println("Created On is  :"+game.getScoreList().get(i).getCreatedOn());
        System.out.println("scoreId is : " + game.getScoreList().get(i).getScoreId());
    }
}
public void onException(Exception ex)
{
    System.out.println("Exception Message"+ex.getMessage());
}
});

Thanks,
Himanshu Sharma
Hi,

thats exact the code that i use.

Are entries in the Scoring list needed or in the Leaderboard?

Leaderboard has entries, scoring nothing, no entries.

In the Leaderboard, on the Homepage by api, i can not sort the table, is this correct?

Here, the code for saveing score and getTopNRankers:

Write the Score:

private void highscoreSchreiben() {
        String gameName = "alltime_normal";
        BigDecimal gameScore = new BigDecimal(zeit2 - zeit1);
        scoreBoardService.saveUserScore(gameName, userName, gameScore, new App42CallBack() {
            public void onSuccess(Object response) {
                Game game = (Game) response;
                for (int i = 0; i < game.getScoreList().size(); i++) {
                    System.out.println("userName is : " + game.getScoreList().get(i).getUserName());
                    System.out.println("score is : " + game.getScoreList().get(i).getValue());
                    System.out.println("scoreId is : " + game.getScoreList().get(i).getScoreId());
                    System.out.println("Created On is  :" + game.getScoreList().get(i).getCreatedOn());
                }
            }

            public void onException(Exception ex) {
                System.out.println("Exception Message" + ex.getMessage());
            }
        });
    }

Get the Scores:

public void highScore() {
        int max = 10;
        String gameName = "alltime_normal";
        HashMap<String, String> otherMetaHeaders = new HashMap<String, String>();
        otherMetaHeaders.put("orderByAscending", "score");// Use orderByDescending for Descending or orderByAscending for Ascending
        scoreBoardService.setOtherMetaHeaders(otherMetaHeaders);
        ScoreBoardService scoreBoardService = App42API.buildScoreBoardService();
        scoreBoardService.getTopNRankers(gameName, max, new App42CallBack() {
            public void onSuccess(Object response) {
                Game game = (Game) response;
                System.out.println("Game Name is : " + game.getName());
                for (int i = 0; i < game.getScoreList().size(); i++) {
                    System.out.println("userName is : " + game.getScoreList().get(i).getUserName());
                    System.out.println("score is : " + game.getScoreList().get(i).getValue());
                    System.out.println("Created On is  :" + game.getScoreList().get(i).getCreatedOn());
                    System.out.println("scoreId is : " + game.getScoreList().get(i).getScoreId());
                    highscore[i][0] = game.getScoreList().get(i).getUserName();
                    highscore[i][1] = game.getScoreList().get(i).getValue().toString();
                    spiele = i;
                }
                runThredHighscoreCreation();
            }

            public void onException(Exception ex) {
                System.out.println("Exception Message" + ex.getMessage());
            }
        });
    }



The App42API.initialize("ANDROID_APPLICATION_CONTEXT","API_KEY","SECRET_KEY"); is initialized in the onCreate()-methode.

Thanks,

Achim
Hello Achim,

Please put this(      scoreBoardService.setOtherMetaHeaders(otherMetaHeaders);) code snippet after (ScoreBoardService scoreBoardService = App42API.buildScoreBoardService();) as shown below and see are you able to fetch the desired result or not.
ScoreBoardService scoreBoardService = App42API.buildScoreBoardService();
scoreBoardService.setOtherMetaHeaders(otherMetaHeaders);

Thanks,
Himanshu Sharma
THANK YOU!!!

This was the right thing. Now its working.

Much greetings

Achim
Hello Achim,

Thanks for your acknowledgement. Let us know if you have more questions for us.

Himanshu Sharma
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
...