iOS Undeclared Identifier (Objective-C)

G-Man118

macrumors newbie
Original poster
Mar 25, 2014
2
0
Hi Everyone,

This's my first time creating an app and am having trouble understanding why I'm getting an "undeclared identifier 'PlaceTunnels' " message in my Game.m file when it comes to this code: -(void)PlaceTunnels

Here is the code from the two files:

Code:
// Game.h

#import <UIKit/UIKit.h>

int BirdFlight;

int RandomTopTunnelPosition;

int RandomBottomTunnelPosition;

int ScoreNumber;

NSInteger HighScoreNumber;

@interface Game : UIViewController
{
    
    IBOutlet UIImageView *Bird; 
    IBOutlet UIButton *StartGame;
    IBOutlet UIImageView *TunnelTop; 
    IBOutlet UIImageView *TunnelBottom;
    IBOutlet UIImageView *Top; 
    IBOutlet UIImageView *Bottom; 
    IBOutlet UILabel *ScoreLabel;
    NSTimer *BirdMovement;
    NSTimer *TunnelMovement; 
}

-(IBAction)StartGame:(id)sender; 
-(void)TunnelMoving; 
-(void)PlaceTunnels; 
-(void)Score;
-(void)GameOver; 

@end
Code:
// Game.m

#import "Game.h"

@interface Game ()

@end

@implementation Game

-(void)GameOver {

    if (ScoreNumber > HighScoreNumber) {
        [[NSUserDefaults standardUserDefaults] setInteger:ScoreNumber forKey:@"HighScoreSaved"];
    }

    [TunnelMovement invalidate];

    [BirdMovement invalidate];

    Exit.hidden = NO;
    TunnelTop.hidden = YES;
    TunnelBottom.hidden = YES;
    Bird.hidden = YES;
}

-(void)Score {
    
    ScoreNumber = ScoreNumber + 1;

    ScoreLabel.text = [NSString stringWithFormat:@"%i", ScoreNumber];
    
}

-(IBAction)StartGame:(id)sender{

    TunnelTop.hidden = NO;
    TunnelBottom.hidden = NO;
    
    StartGame.hidden = YES; 

    BirdMovement = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(BirdMoving) userInfo:nil repeats:YES];

    [self PlaceTunnels];

    TunnelMovement = [NSTimer scheduledTimerWithTimeInterval: 0.01 target:self selector:@selector(TunnelMoving) userInfo:nil repeats:YES];

}

-(void)TunnelMoving {

    TunnelTop.center = CGPointMake(TunnelTop.center.x - 1, TunnelTop.center.y);

    TunnelBottom.center = CGPointMake(TunnelBottom.center.x - 1, TunnelBottom.center.y);

    if(TunnelTop.center.x < -28) {
        [self PlaceTunnels];

    if(TunnelTop.center.x == 30) {
        [self Score];
    }

    if(CGRectIntersectsRect(Bird.frame, TunnelTop.frame)) {
        [self GameOver];
    }
    
    if(CGRectIntersectsRect(Bird.frame, TunnelBottom.frame)) {
        [self GameOver];
    }
        
    if(CGRectIntersectsRect(Bird.frame, Top.frame)) {
        [self GameOver];
    }
        
    if(CGRectIntersectsRect(Bird.frame, Bottom.frame)) {
        [self GameOver];
    }
        
}

-(void)PlaceTunnels { // "Use of undeclared identifier 'PlaceTunnels' 
    
    RandomTopTunnelPosition = arc4random() %350;
    
    RandomTopTunnelPosition = RandomTopTunnelPosition - 228;

    RandomBottomTunnelPosition = RandomTopTunnelPosition + 655;

    TunnelTop.center = CGPointMake(340, RandomTopTunnelPosition);
    TunnelBottom.center = CGPointMake(340, RandomBottomTunnelPosition);
    
}

-(void)BirdMoving{

    Bird.center = CGPointMake(Bird.center.x, Bird.center.y - BirdFlight);

    BirdFlight = BirdFlight -5;

    if( BirdFlight < -15) {
        BirdFlight = -15;
    }

    if (BirdFlight > 0) {
        Bird.image = [UIImage imageNamed:@"BirdUp.png"];
    }

    if (BirdFlight > 0) {
        Bird.image = [UIImage imageNamed:@"BirdDown.png"];
    }
    
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    BirdFlight = 30;
    
}



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    
    TunnelTop.hidden = YES;
    TunnelBottom.hidden = YES;
    
    Exit.hidden = YES;

    ScoreNumber = 0;
    HighScoreNumber = [[NSUserDefaults standardUserDefaults] integerForKey=@"HighScoreSaved"]
    
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

}

@end
I would greatly appreciate any kind of help. Thanks.

-Taleb
 
Last edited by a moderator:

G-Man118

macrumors newbie
Original poster
Mar 25, 2014
2
0
However -- I believe the problem may be caused by a missing closing brace, above. Good luck :)
It works. I had a couple of more errors in my code that I was able to fix. Thank you very much. :):)
 
Last edited by a moderator:

chown33

Moderator
Staff member
Aug 9, 2009
8,429
4,435
Pale blue comma
Please read and follow the naming recommendations here:
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html

When Every Single Thing Uses The Same Capitalization Strategy, Then Every Single Thing Looks Identical, And It's Much More Difficult To Distinguish Variables, Properties, And Classes From One Another. Since Human Comprehension Should Be One Of Your Goals (As Distinct From Mere Syntactic Correctness), You Should Follow The Usual Conventions For Objective-C Naming. Please. Oh God, Please. Make It Stop. Especially If There Are Few Or No Other Indications Of Context That Might Help Clarify Such As Comments Or Factoring Into Smaller Methods. And You Should Also Eliminate The Magic Numbers Like Three Fifty, Two Hundred Twenty-Eight, and Six-Fifty-Five.

http://en.wikipedia.org/wiki/Magic_number_(programming)#Unnamed_numerical_constants
 
Last edited: