Reputation: 11
I'm pretty new to coding on Xcode (or objective-c in general) and I can't seem to get rid of these errors:
//
// HelloWorldLayer.m
// FirstGame
//
// Created by Kostas on 1/14/12.
// Copyright __MyCompanyName__ 2012. All rights reserved.
//
// Import the interfaces
#import "HelloWorldLayer.h"
#import "GamePlay.h"
// HelloWorldLayer implementation
@implementation HelloWorldLayer
+(id) scene {
CCScene *scene = [CCScene node];
HelloWorldLayer *layer = [HelloWorldLayer node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
// on "init" you need to initialize your instance
-(id) init {
if( (self=[super init] )) {
[CCMenuItemFont setFontName:@"Marker Felt"];
[CCMenuItemFont setFontSize:35];
CCMenuItem *Play = [CCMenuItemFont itemFromString:@"PLAY"
target:self
selector:@selector(gotoGameplay:)];
CCMenu *menu = [CCMenu menuWithItems: Play, nil];
menu.position = ccp(240, 160);
[menu alignItemsVerticallyWithPadding:10];
[self addChild:menu];
}
return self;
}
-(void) goToGameplay: (id) sender {
[[CCDirector sharedDirector]
replaceScene:[[CCTransitionFade
transitionWithDuration:1
scene:[GamePlay node]
]]; **<-----Here is my error it says "Expected identifier"**
}
- (void) dealloc {
[super dealloc];
}
@end
The expected identifier is just what X-Code came up with.
Upvotes: 1
Views: 172
Reputation: 23278
Change
[[CCDirector sharedDirector]
replaceScene:[[CCTransitionFade
transitionWithDuration:1
scene:[GamePlay node]
]];
to,
[[CCDirector sharedDirector] replaceScene:
[CCTransitionFade transitionWithDuration:1
scene:[GamePlay node]]];
That should fix the issue. You had an extra [
before [CCTransitionFade transitionWithDuration:1 scene:[GamePlay node]]
Upvotes: 0
Reputation: 49034
If you count your brackets, you'll see that you have two more opening brackets than closing brackets. I've indented them here so you can see the problem clearly.
-(void) goToGameplay: (id) sender {
[
[CCDirector sharedDirector]
replaceScene:
[ // <-- either this is extra
[CCTransitionFade transitionWithDuration:1
scene:[GamePlay node]
]
];
//]; <-- or this is missing
}
The compiler is trying to tell you that it wasn't expecting to find a semicolon in the middle of a message send expression. I'm not familiar enough with the Cocos2D framework to know what exactly you're trying to do, but at least you can see what problem is.
Upvotes: 1
Reputation: 318774
This line:
[[CCDirector sharedDirector]
replaceScene:[[CCTransitionFade
transitionWithDuration:1
scene:[GamePlay node]
]];
has 5 open brackets and only 4 close brackets. There needs to be the same number (and in the right places). Most likely you need to get rid of one of the two open brackets after replaceScene:
.
BTW - why are you using such and old Xcode? You should use the latest - 4.5.1.
Upvotes: 0