iosobjective-cgame-centergamekitgkscore

iOS Game Center submit float instead of int64_t


I am trying to submit a float of two decimal length to my Game Center leaderboard, however the only format allowed to submit with is int64_t. I am using the default Apple report score method:

- (void)reportScore:(int64_t)score forCategory:(NSString *)category {
    GKScore *scoreReporter = [[GKScore alloc] initWithCategory:category];   
    scoreReporter.value = score;
    [scoreReporter reportScoreWithCompletionHandler: ^(NSError *error) {
        [self callDelegateOnMainThread: @selector(scoreReported:) withArg: NULL error: error];
    }];
}

I am trying to use this method to provide the score to the report score method:

- (IBAction)increaseScore {
    self.currentScore = self.currentScore + 1;
    currentScoreLabel.text = [NSString stringWithFormat: @"%lld", self.currentScore];
    NSLog(@"%lld", self.currentScore);
}

Please help, I have been googling like crazy and cannot find the answer to this.


Solution

  • You can only submit 64 bit integers as scores to a leaderboard. From the documentation:

    To Game Center, a score is just a 64-bit integer value reported by your application. You are free to decide what a score means, and how your application calculates it. When you are ready to add the leaderboard to your application, you configure leaderboards on iTunes Connect to tell Game Center how a score should be formatted and displayed to the player. Further, you provide localized strings so that the scores can be displayed correctly in different languages. A key advantage of configuring leaderboards in iTunes Connect is that the Game Center application can show your game’s scores without you having to write any code.

    That doc page should tell you about formatting your score. It sounds like in order to display float-like scores you will have to tinker with the format settings in iTunes Connect.

    Update

    Try this for increaseScore:

    - (IBAction) increaseScore {      
         self.currentScore = self.currentScore + 5; 
         float score = (float)self.currentScore / 100.0f;
         currentScoreLabel.text = [NSString stringWithFormat: @"%f", score]; 
         NSLog(@"%lld", self.currentScore);
    }