Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-28-2010, 12:19 PM   #1 (permalink)
Ubermatik
Registered Member
 
Join Date: Jul 2010
Posts: 19
Default Coding problem ("Expected identifier or '(' before 'if'")

Hello,

First off, I'm new here (as you may be able to tell!) so I'm sorry if this is the wrong section...

I have a problem and was wondering if you could help me: I'm following a tutorial at the moment, which involves building a simple Pong-style game. I've followed it letter for letter (apart form the fact I have changed the names of a few objects etc.), but have come across a problem - it's an error that reads: "Expected identifier or '(' before 'if'.
Do you have a solution to the problem, or know of a way in which I could solve it? I'm really eager to become familiar with the SDK, so I'd love to know what the problem is too. Thanks in advance! (the problem line is highlighted in red) (the tutorial is here, if needed)

Code:
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	self.gameState = kGameStatePaused;
	pucVelocity = CGPointMake(kPucSpeedX,KPucSpeedY);
	[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
}

-(void) gameLoop {
	if(gameState == kGameStateRunning) {
		
		puc.center = CGPointMake(puc.center.x + pucVelocity.x , puc.center.y + pucVelocity.y);
		
		if(puc.center.x > self.view.bounds.size.width || puc.center.x < 0) {
			pucVelocity.x = -pucVelocity.x;
		}
		
		if(puc.center.y > self.view.bounds.size.height || puc.center.y < 0) {
			pucVelocity.y = -pucVelocity.y;
		}
	} else {
		if (tapToBegin.hidden) {
			tapToBegin.hidden = NO;
		}
	}
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	if (gameState == kGameStatePaused) {
		tapToBegin.hidden = YES;
		gameState = kGameStateRunning;
	} else if(gameState == kGameStateRunning) {
		[self touchesMoved:touches withEvent:event];
	}
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [[event allTouches] anyObject];
	CGPoint location = [touch locationInView:touch.view];
	CGPoint xLocation = CGPointMake(location.x,paddleblue.center.y);
	paddleblue.center = xLocation;
}

if (CGRectIntersectsRect(puc.frame,paddleblue.frame)) {
	if(puc.center.y < paddleblue.center.y) {
		pucVelocity.y = -pucVelocity.y;
		NSLog(@"%f %f",puc.center,paddlegreen.center);
	}
}

if (CGRectIntersectsRect(puc.frame,paddlegreen.frame)) {
	if(puc.center.y > paddlegreen.center.y) {
		pucVelocity.y = -pucVelocity.y;
	}
}

//AI
if (puc.center.y <= self.view.center.y) {
	if(puc.center.x < paddlegreen.center.x) {
		CGPoint compLocation = CGPointMake(paddlegreen.center.x - kCompMoveSpeed, paddlegreen.center.y);
		paddlegreen.center = compLocation;
	}
	
	if(puc.center.x > paddlegreen.center.x) {
		CGPoint compLocation = CGPoint(paddlegreen.center.x + kCompMoveSpeed, paddlegreen.center.y);
		paddlegreen.center = compLocation;
	}
}
Ubermatik is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,852
Threads: 89,216
Posts: 380,666
Top Poster: BrianSlick (7,129)
Welcome to our newest member, syrreintyia1
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:59 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.