2012-09-09 4 views
0

내 게임에서 여전히 작동하고 난이도가 높은 "gameSpeed"가있는 각 난이도는 어려운 선택에 따라 설정됩니다.중복 기호

duplicate symbol _gameSpeed in: 
/Users/Ashley/Library/Developer/Xcode/DerivedData/Whack-etfeadnxmmtdkgdoyvgumsuaapsz/Build/Intermediates/Whack.build/Debug-iphonesimulator/Whack.build/Objects-normal/i386/TimedGameLayer.o 
/Users/Ashley/Library/Developer/Xcode/DerivedData/Whack-etfeadnxmmtdkgdoyvgumsuaapsz/Build/Intermediates/Whack.build/Debug-iphonesimulator/Whack.build/Objects-normal/i386/GameInfo.o 
ld: 1 duplicate symbols for architecture i386 
collect2: ld returned 1 exit status 
Command /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1 

난 단지 한 위치에 gameSpeed을 사용하고 있습니다 : 내 응용 프로그램을 실행하려고 할 때

그러나 나는 다음과 같은 오류가 발생합니다.

여기에 있습니다 :이 내 TimedGameLayer.m gameSpeed ​​var에 내 GameInfo.h에

안에

[self schedule:@selector(tryPopMoles:) interval:gameSpeed]; 

내가 헤더과 같이 가져옵니다

#import "GameInfo.h" 

내 GameInfo.h는 다음과 같습니다.

(내 GameInfo.m 파일에)
@interface GameInfo : NSObject 
+(void)setupGame:(enum GameType)type withArg2:(enum GameDifficulty)difficulty; 
+(void)resetGame; 
+(void)togglePause; 

@end 

//Game Type 
enum GameType gameType; 
enum GameDifficulty gameDifficulty; 

//Release Version 
NSString *version; 

//Settings 
int gameSpeed = 1.5; 

//Stats 
int touches = 0; 
int score = 0; 
int totalSpawns = 0; 

//usables 
bool gamePaused = FALSE; 

typedef enum GameType { 
    GameTypeClassic = 0, 
    GameTypeUnlimited, 
    GameTypeTimed, 
    GameTypeExpert, 
} GameType; 

typedef enum GameDifficulty 
{ 
    GameDifficultyEasy = 0, 
    GameDifficultyMedium, 
    GameDifficultyHard, 
} GameDifficulty; 

내 setupGame 기능은 다음과 같습니다 :

+(void)setupGame:(enum GameType)type withArg2:(enum GameDifficulty)difficulty 
{ 
    gameType = type; 
    gameDifficulty = difficulty; 

    switch(gameDifficulty) 
    { 
     case GameDifficultyEasy: 
      gameSpeed = 1.5; 
      break; 
     case GameDifficultyMedium: 
      gameSpeed = 1.0; 
      break; 
     case GameDifficultyHard: 
      gameSpeed = 0.5; 
      break; 
    } 
} 

임은 완전히 여기 손실 ...

어떤 아이디어? 아래에 여러분의 의견과 귀하의 예제 코드를 기반으로

감사

답변

1

:

여러 그래서, 여러 번 당신은 .H 파일에 선언 된 일련의 변수를 가지고 있고, .H 파일이 포함되어 있습니다 같은 이름의 변수. constants.h 및 constants.m 파일을 만들고이 목록을 상수 파일에서 상수로 선언해야합니다. 그런데

constants.h: 
extern const int gameSpeed; 

constants.m: 
const int gameSpeed = 1; 

, 당신은 int로 gameSpeed를 선언하지만 gameSpeed는 플로트 식 대신 1. 동일 할 것이다, 그래서 그것에 부동 소수점 값을 할당하고 있습니다.

+0

두 군데에 포함됩니다. 1) 내 @implementation TimedGameLayer 바로 위, 다른 수입과 함께. 그리고 2) 내 다른 게임들과 함께 내 GameInfo.m – Ryuk

+0

실수로 .m 파일을 가져 오지 않았습니까? – Asciiom

+0

아니, 확인했습니다. TeamViewer가 있으면 다음을 볼 수 있습니다 :) – Ryuk