0

My game center achievements are appearing in Game Center, so I know my implementation is correct in reporting.

Couple of questions on that.

First, in Game Center it is not showing the percentage view on the image... ie 2% complete next to the achievement, even though I have reported .02. I know the achievement is being reported because if I throw the 100 at it, it records the achievement.

Second, my achievements are not appearing to the user upon reward. As I understood, this functionality was suppose to be handled automatically by gamekit. I was under the impression the the small modal would appear letting the user know they completed an achievement. I now think there is something I have to do, because no small modal is appearing.

I will attach my code, but most of it stock.

My last problem is retrieving scores. I believe I am going to have to store my own scores because my current implementation does not look like it will mesh well.

Thanks in advance...

- (void) loadAchievements
{    [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements,        NSError *error) {
if (error != nil)
{
    // handle errors
}
if (achievements != nil)
{
    // process the array of achievements.
}
}];
}

-(float)getAchievementPercentageForIdentifier:(NSString *)identifier {

__block float percentage = 0;

[GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) {
    if (error != nil)
    {
        // handle errors
    }
    if (achievements != nil)
    {
        // process the array of achievements.

        for (GKAchievement *achievement in achievements) {

            if ([achievement.identifier isEqualToString:identifier]) {

                percentage = achievement.percentComplete;
                NSLog(@"percent complete --> %f", achievement.percentComplete);

            }

        }

    }
}];

NSLog(@"Percentage --> %f", percentage);

return percentage;

}

- (void) reportAchievementIdentifier: (NSString*) identifier percentComplete: (float) percent
{
GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier: identifier]   autorelease];
if (achievement)
{
    achievement.percentComplete = percent;
    [achievement reportAchievementWithCompletionHandler:^(NSError *error)
     {
         if (error != nil)
         {
             // Retain the achievement object and try again later (not shown).
         }
     }];
}
 }

 -(void) addCompletedGameToAchievements {

float oneGamePercentage = 0;
float tenGamePercentage = 0;
float fiftyGamePercentage = 0;
float hundredGamePercentage = 0;
float fivehundredGamePercentage = 0;
float thousandGamePercentage = 0;

int gamesComplete = 0;

oneGamePercentage = [self getAchievementPercentageForIdentifier:kAchievementGamesCompletedOne];
tenGamePercentage = [self getAchievementPercentageForIdentifier:kAchievementGamesCompletedTen];
fiftyGamePercentage = [self getAchievementPercentageForIdentifier:kAchievementGamesCompletedFifty];
hundredGamePercentage = [self getAchievementPercentageForIdentifier:kAchievementGamesCompletedHundred];
fivehundredGamePercentage = [self getAchievementPercentageForIdentifier:kAchievementGamesCompletedFivehundred];
thousandGamePercentage = [self getAchievementPercentageForIdentifier:kAchievementGamesCompletedThousand];

if (oneGamePercentage != 100) {

    [self reportAchievementIdentifier:kAchievementGamesCompletedOne percentComplete:100];

}

if (tenGamePercentage != 100) {

    gamesComplete = tenGamePercentage * 10;
    gamesComplete++;

    [self reportAchievementIdentifier:kAchievementGamesCompletedTen percentComplete:(gamesComplete * .10)];

}

if (fiftyGamePercentage != 100) {

    gamesComplete = fiftyGamePercentage * 50;
    gamesComplete++;


    NSLog(@"fifty game reported %f ",(gamesComplete * .02));
    [self reportAchievementIdentifier:kAchievementGamesCompletedFifty percentComplete:(gamesComplete * .02)];

}

if (hundredGamePercentage != 100) {

    gamesComplete = hundredGamePercentage * 100;
    gamesComplete++;

    [self reportAchievementIdentifier:kAchievementGamesCompletedHundred percentComplete:(gamesComplete * .01)];

}

if (fivehundredGamePercentage != 100) {

    gamesComplete = fivehundredGamePercentage * 500;
    gamesComplete++;

    [self reportAchievementIdentifier:kAchievementGamesCompletedFivehundred percentComplete:(gamesComplete * .002)];

}

if (fivehundredGamePercentage != 100) {

    gamesComplete = thousandGamePercentage * 1000;
    gamesComplete++;

    [self reportAchievementIdentifier:kAchievementGamesCompletedThousand percentComplete:(gamesComplete * .0001)];

}

NSLog(@"100 game percentage -- > %f", hundredGamePercentage);

}
Calm Turtle
  • 292
  • 3
  • 18

1 Answers1

1

Many problems...

  • I'm confused by the logic behind incrementing gamesComplete
  • You should store them locally instead of asking GameCenter every time.
  • -getAchievementPercentageForIdentifier: will always return 0 because GameKit methods are asynchronous.
  • GKAchievement.percentageComplete is a percentage. You need to multiply by 100.

I think you have to do your own achievement notifications.

tc.
  • 33,468
  • 5
  • 78
  • 96
  • gamesCImports is how I convert from a percentage to knowing how many games they completed. That way I can turn around and report an updated percentage. I don't multiply by 100 because the number of values change. I did move the decimal spot though based upon how many total games in the achievement. The more I look at it it does seem like I am going to have to store locally. I was really hoping for cross device sync though. – Calm Turtle Jun 28 '11 at 09:59
  • You can probably do a bad attempt at "cross-device sync", but you'll have to handle the fact that Game Center calls are asynchronous. ("Bad" because updating involves a race condition and painful error handling, and you still need to store something locally anyway.) – tc. Jun 28 '11 at 21:50