2013-03-29 2 views
0

내 iPhone 응용 프로그램에 GameCenter를 통합하려고합니다. 내가하려는 것은 NSString highScore를 내 게임 센터 리더 보드에 업로드하는 것입니다. 문자열 호환성에 대한 문제가 발생하며 여기에서 무엇을해야할지 모르겠습니다. 내가 게임 센터에 최고 점수는 NSString을 업로드 할 때 여기에 내가 부르는 무효Game Center 통합 오류

는 최고 점수는 NSString의 값이 여기에 6있다하더라도, 나는 게임 센터에있는 거대한 번호 (803089816)를 얻을 제출
-(void)submitScore { 
int x = [highScore floatValue]; 
score=&x; 
GKScore *myScoreValue = [[GKScore alloc] initWithCategory:@"grumpyEscapeHighScoresLeaderboard"]; 
myScoreValue.value = score; 

[myScoreValue reportScoreWithCompletionHandler:^(NSError *error){ 
    if(error != nil){ 
     NSLog(@"Score Submission Failed"); 
    } else { 
     NSLog(@"Score Submitted"); 
    } 

}]; 
} 

오류 메시지 : 여기 내 ViewController.h에서

Incompatible pointer to integer conversion assigning to 'int64_t' (aka 'long long') from 'int*' 

내가

int *score; 

내가 목표 C에 매우 새로운 오전, 일반 코딩으로 점수를 정의하는 것입니다. 죄송합니다.이 질문이 다른 사람들에게는 어리석은 것처럼 보입니다. 나는 이것을 오랫동안 연구하는 방법을 시도해 왔으며 어떤 답을 찾지 못했습니다. Here은 코드를 가져온 튜토리얼이며 내 프로젝트 용으로 수정했습니다.

+0

사이드 노트 - 'floatValue'를 호출하면 결과는'int '가 아닌'float' 유형의 변수에 지정해야합니다. 'int'에 할당하려면'floatValue' 대신'intValue'를 호출하십시오. – rmaddy

답변

1

이 아무 이유 없어 여기 당신의 점수 값에 대한 int보다는 int *를 사용하고, 유사 이유는 단지 -submitScore 방법을 사용하는 경우 score 인스턴스 변수로 저장 할 수 없습니다.

- (void)submitScore { 
    GKScore *myScoreValue = [[GKScore alloc] initWithCategory:@"grumpyEscapeHighScoresLeaderboard"]; 
    myScoreValue.value = [highScore integerValue]; 

    [myScoreValue reportScoreWithCompletionHandler:^(NSError *error){ 
     if(error != nil){ 
      NSLog(@"Score Submission Failed"); 
     } else { 
      NSLog(@"Score Submitted"); 
     } 

    }]; 
} 
+0

정말 고마워요. 완벽하게 내 문제를 해결! – user2201063