Reputation: 1245
i have done evrything and integrate the gamecentre in my game,My game is a runner game,so i put some achivements to my game,like best runner(500 meter),extreme runner(1000 meter),king runner(2000 meter )like that.
Everything works finebut the poblm is,if the user run exactly 500 meters it will unlock best runner badge in achivement board.but if the user runs 501 or 510 or 540 like that i is not updating the achivements,i need to unlock this badge when the user runs 500 - 999 meters .i tries a lot to solve this but no luck.
my code is its in update score method
int dismetr = self.currentScore >= 500;
self.currentScore = dismetr;
[self checkAchievements];
i here statically put the value as 500
and in switch case method
- (void) checkAchievements
{
NSString* identifier = NULL;
double percentComplete = 0;
switch(self.currentScore)
{
case 500:
{
if (self.currentScore >= 500) {
NSLog(@"ACHIVEMENT 500");
identifier= kAchievement500meter ;
percentComplete= 100.0;
break;
}
}
case 1000:
// onother statments
}
if(identifier != NULL)
{
[self.gameCenterManager submitAchievement: identifier percentComplete: percentComplete];
}
}
it is not updating the score anyway.but if i put
its in update score method
int dismetr = 500;
self.currentScore = dismetr;
[self checkAchievements];
and in this method
- (void) checkAchievements
{
NSString* identifier = NULL;
double percentComplete = 0;
switch(self.currentScore)
{
case 500:
{
NSLog(@"ACHIVEMENT 500");
identifier= kAchievement500meter ;
percentComplete= 100.0;
break;
}
case 1000:
// onother statments
}
if(identifier != NULL)
{
[self.gameCenterManager submitAchievement: identifier percentComplete: percentComplete];
}
}
it is updating the score correctly..what can i do to make solve this problem.please help me to do this.
Thanks in advance.
Upvotes: 0
Views: 86
Reputation: 26259
You are doing a switch
on self.currentScore
, so you are checking for exact values. You really should do that in an if-else
-construct, which checks if the currentScore
is in a specific range.
Just like this:
- (void) checkAchievements
{
NSString* identifier = NULL;
double percentComplete = 0;
if(self.currentScore >= 500 && self.currentScore < 1000) {
NSLog(@"ACHIVEMENT 500");
identifier= kAchievement500meter ;
percentComplete= 100.0;
}
// onother statments
if(identifier != NULL)
{
[self.gameCenterManager submitAchievement:identifier
percentComplete:percentComplete];
}
}
Upvotes: 1