Hello, first off, I'm new to the forum and, more importantly, writing C++ and working with the iPhone SDK.

I was wondering if anybody could help me - I'm really eager to keep learning, and everything has been okay until now. I'm getting an error that I can't resolve, no matter what I do...

The line it appears on is no. 33 ( if(puc.center.y <= self.view.center.y) { ), and the error message reads:
"Expected identifier or '(' before 'if'"

///////////////////////////////////////////////////////////////////////BEGIN SECTION

-(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;
		}
	}
	
	if(CGRectIntersectsRect(puc.frame,paddleblue.frame)) {
		if(puc.center.y < paddleblue.center.y) {
			pucVelocity.y = -pucVelocity.y;
		}
	}
	
	if(CGRectIntersectsRect(puc.frame,paddlegreen.frame)) {
		if(puc.center.y > paddlegreen.center.y) {
			pucVelocity.y = -pucVelocity.y;
		}
	}

	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 = CGPointMake(paddlegreen.center.x + kCompMoveSpeed, paddlegreen.center.y);
			paddlegreen.center = compLocation;
		}
	}
}
		
///////////////////////////////////////////////////////////////////////END SECTION

Thank-you in advance, and I hope you can help - my efforts so far have proved fruitless!

Wow, a very nice first post. I just wish I could help. Unfortunately, I don't see anything ATM. All of your braces seem to be paired up properly, I don't see any missing semi-colons, and all of your parentheses seem to be in order.

Perhaps you should add some parentheses that would generally be considered redundant? See if adding them clears a lingering statement somewhere that is getting the compiler out of phase with your code? I doubt it, but could the error potentially be in one of the structures / classes that the statement in question accesses?

It strikes me as extremely odd that it's flagging an error for missing information in front of an if. It makes me wonder if there is something weird in your compiler. What compiler are you using?

Edited 6 Years Ago by Fbody: n/a

Hm, I seem to have solved it! Sorry to waste your time a little... all I did to resolve the matter was swap the two 'paragraphs' (sorry, I'm not very good on technical terms at the moment!) around, at now it functions without any problems... so, in other words:

if(puc.center.x > paddlegreen.center.x) {
		CGPoint compLocation = CGPointMake(paddlegreen.center.x + kCompMoveSpeed, paddlegreen.center.y);
		paddlegreen.center = compLocation;
	}

	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;
		}
	}
}

Thanks for you help anyway! If you have time, do you have any idea why this was? Is there particular importance in the order?

No idea. Have you tested the logic of this new version? Does it still execute the way you intended, or at least some acceptable variation of it?

I'm only asking because the way you switched it resulted in removing if(puc.center.x > paddlegreen.center.x) from the conditional statement block defined for if(puc.center.y <= self.view.center.y) , which it was initially part of...

Yes, it executes fine and the game works well... why, was their any indication that it shouldn't...?

No, just wanted to make sure you didn't introduce an intent error. (About half way down the page, it's a Java-related page, but it explains the concept.)

Edited 6 Years Ago by Fbody: n/a

That page was really helpful! Thank-you so much! It explains it in easily understandable ways... ideal for a learner like myself.

Otherwise, the app works fine now - there is one bug in that if the computer scores, the app crashes... but I will try to fix that - I can only assume there's typo somewhere (possibly specified playerscore instead of computerscore)

This question has already been answered. Start a new discussion instead.