Game Center in iOS: GKScore vs. GKAchievement?

121 views Asked by At

I have a question about a topic related to "Game Center" in iOS: GKAchievement vs. GKScore ?

(1) GKAchievement

I know that in iOS Game Center, we can define the achievements and leaderboards and specify, for example, that when gamers complete the first achievement then we give gamers 10 points. That is when we use GKAchievement to submit an achievement to game center upon users successfully complete an achievement.

(2) GKScore

So, when do we need to use GKScore ? As I mention in the previous paragraph, we can give gamers a specific score when gamers complete the first achievement. Then, do we still need to use GKScore if we already use GKAchievement to give users new scores per new achievements ? What is the purpose of GKScore ?

Or perhaps, when we use GKScore, we don't need to use GKAchievement ? In other words, we only need to use 1 of these 2 classes and not both ?


Here is the typical code in C# to submit score GKScore:

    public void reportScore(long score, string category, GameCenterController controller, bool show_dialog)
    {
        GKScore scoreReporter = new GKScore (category);
        scoreReporter.Value = score;

        scoreReporter.ReportScore ((error) => {     
        ((error) => {   // original
            if(error == null){
                if(show_dialog){
                    new UIAlertView ("Score Reported to Game Center", "Score Reported Successfully", null, "OK", null).Show ();
                }
            }
            else{
                if(show_dialog){
                    new UIAlertView ("Can't Submit Score to Game Center", "Please make sure that you logon to Game Center", null, "OK", null).Show ();
                }
            }

            //NSThread.SleepFor(1);         
            controller.updateHighScore();   

        });
    } 

1

There are 1 answers

0
Job_September_2020 On BEST ANSWER

I did some testing and kind of figured out the "answer" myself.

If we use both GKAchievement and GKScore to submit both achievements and scores, then the score submitted via GKScore will be displayed in the Global Leaderboards. This score will overwrite the score that is supposed to be displayed when we submit achievements via GKAchievement

Here are my 2 test cases:

(A) Test Case 1:

Suppose that I define an achievement that is worth 100 points in Game Center. When users play the game and complete this achievement, I first submit this achievement and then submit the score of 3456 points (via my code for testing purpose).

Next, I open the Game Center, and I can see that my score displayed on the Leaderboard is 3456 (and NOT 100 points).

(B) Test Case 2:

Suppose that I define an achievement that is worth 100 points. When users play the game and complete this achievement, I only submit this achievement and then do NOT manually submit the score of 3456 points (via my code for testing purpose).

Next, I open the Game Center, and I can see that my score displayed on the Leaderboard is exactly 100.


NOTE: This following behavior happens only if developers set the "Score Submission Type" to "Best Score".

If you subsequently use GKScore to submit a score that is HIGHER than the existing score in the Leaderboard in Game Center, then this new HIGHER score will be automatically posted in the Leaderboard (by Apple Game Center and we don't have to do any thing else).

Now, if you subsequently use GKScore to submit a score that is LOWER than the existing score in the Leaderboard in Game Center, then this new LOWER score will NOT be posted in the Leaderboard.


(On the other hand, if if developers set the "Score Submission Type" to "Most Recent Score", then only the "Most Recent Score" and NOT the Highest score is posted on Game Center.)