edhog
edhog

Reputation: 513

Game Center posting bogus scores - iPhone

I'm trying to get Game Center working and it's almost there. The only problem is that the scores posted don't make any sense. This is my post score code:

-(IBAction)subScore
{
    {
        GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:@"katplay"] autorelease];

        scoreReporter.value = gcPost;
        NSLog(@"posted");
        NSLog(gcPost);

        [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
            if (error != nil)
            {
                NSLog(@"failed!!!");
                NSLog(gcPost);
            }
        }];
    }
}

So I play the game and get my score and view the console where the log says that gcPost = 2500. When I view the leaderboard my score is 100,929,392 Points. I have no idea where that number could have come from.

Am I just missing something basic?

Chris

Upvotes: 2

Views: 1667

Answers (3)

Robotic Cat
Robotic Cat

Reputation: 5891

You mention that gcPost is "int *gcPost". Surely this should just be "int gcPost"? You want the actual integer rather than a pointer.

Upvotes: 2

Moshe
Moshe

Reputation: 58097

Just implemented Game Center in my app. You need to convert your integer onto a int64_t. In Objective-C terms, thats a LongLong. You can change this:

scoreReporter.value = gcPost;

to this:

scoreReporter.value = [[NSNumber numberWithInt:gcPost] longLongValue];

I strongly urge you to read the Apple Documentation on Game Center. It's a quick and easy read. You can copy most of the code out of there as well.

Upvotes: 2

Dan K.
Dan K.

Reputation: 1532

What type is gcPost? The GKScore.value property expects a value of type int64_t. My guess is whatever type gcPost is doesn't play nicely with that. Try doing an explicit conversion from the original type to int64_t.

Upvotes: 0

Related Questions