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 > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-01-2010, 10:25 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 1
Question method call not working - objective C

Hi there, i have been in the process of learning objective C and I had gotten stuck on a rather easy problem I am sure. I am making a game. But I wanted to put all the game logic that wouldnt change between the levels in the same object. Called gamelogic.m But for some reason when I make the object then run its methods in my scene the methods seem to get skipped over. None of my break points in the gamelogic object get hit. Here are my definitions..

gamelogic.h

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "SpaceManager.h"
#import "cpSprite.h"

@interface gameLogic : NSObject {

}
- (void) sharkFearCheck: (cpShape*)shark shape: (cpShape*)person;
- (BOOL) callingTest;

@end


gamelogic.m
#import "gameLogic.h"
#import "cpConstraintNode.h"
#import "cpShapeNode.h"
@interface gameLogic (PrivateMethods)

@end
@implementation gameLogic

- (id) init
{
if ( self = [super init])
{
}

return self;
}



- (void) dealloc
{

[super dealloc];
}


- (BOOL) callingTest
{


return YES;
}
@end


Delcared in Gamelayer.h

gameLogic *gameRules;

And where its called...


GameLayer.m


BOOL runtest = [gameRules callingTest];
if (runtest == YES)
{
[label setString:@"IT RAN"];
}
else
{
[label setString:@"It didnt run!"];
}


I also tried declaring the object right before callingTest with.

gameLogic *gameRules = [gameLogic];
But I couldnt get it to work... so what am I doing wrong?
bagellad is offline   Reply With Quote
Old 01-01-2010, 10:37 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Post

I think you didn't alloc and init your object; try this.

Code:
gameLogic *gameRules = [[gameLogic alloc] init];
BOOL runtest = [gameRules callingTest];

if (runtest == YES){
    [label setString:@"IT RAN"];
}
else{
    [label setString:@"It didnt run!"];
}
BTW it's standard practice to start objects with upper case letter, and variables with a lower case letter. Then when other people read your code they'll know which is which.

Also, you can pretty up your posts by putting [code] and [ /code] before and after your code blocks - that's what I did you get that blue monospaced area there. Easier to read.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 237
12 members and 225 guests
ADY, CKAmike, Dani77, Duncan C, HemiMG, nick.keroulis, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:21 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0