Problems with Obj-C

Member
Posts: 116
Joined: 2005.02
Post: #1
I'm in the middle of learning Obj-C through the FlipSquare tutorial because I've learned C++ and Lua already...I only have 3 problems/errors. Sad The problems are in italics and this is the Game.h file, can anyone help me?

/* Game */

#import <Cocoa/Cocoa.h>
@class GameView, GameController;
enum { STATE_TITLE, STATE_PLAYING, STATE_GAME_OVER }
@interface Game : NSObject //parse error befor 'interface'

{
IBOutlet GameController *gameController;
IBOutlet GameView *gameView;
int state;
} //parse error before token '{'

- (void)setState: (int)newState; //fatal error metod definition not in class context (sorry, needed the space so that it wasn't a frown here on the forums)
- (int)state;
@end

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #2
1) missing semi-colon after the enum.
2) the second error is symptomatic of the first.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #3
ok, thanks Grin

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #4
one last problem:

/* Game */

#import <Cocoa/Cocoa.h>
@class GameView, GameController;
enum; { STATE_TITLE, STATE_PLAYING, STATE_GAME_OVER }
@interface Game : NSObject

{
IBOutlet GameController *gameController;
IBOutlet GameView *gameView;
int state;
}

- (void)setState: (int)newState; //parse error before semi-colon
- (int)state;
@end

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
nabobnick
Unregistered
 
Post: #5
When he said after enum he meant this:

enum { STATE_TITLE, STATE_PLAYING, STATE_GAME_OVER }; // At the end
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #6
oh...oops, sorry

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #7
Sorry but: [Image: ?id=410638]
And the code:
#import "GameView.h"
#import "Game.h"
#import "GameView.h"

@implementation GameView

- (id)initWithFrame: (NSRect)frameRect
{
if ((self = [super initWithFrame:frameRect]) != nil) {
// Add initialization code here
}
return self;
}

- (void)drawRect: (NSRect)rect
{
}

switch([game state])
{
case STATE_TITLE:
[self displayTitle:rect];
break;

case STATE_PLAYING:
[self displayPlaying:rect];
break;

case STATE_GAME_OVER:
[self displayGameOver:rect];
break;

glFinish();
[[self openGLContext] flushBuffer];

- (void)displayTitle: (NSRect)rect { }

- (void)displayPlaying: (NSRect)rect {
glClearColor(0,0,1.0f,0);
glClear(GL_COLOR_BUFFER_BIT);
}

- (void)displayGameOver: (NSRect)rect { }
}

@end

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Oldtimer
Posts: 832
Joined: 2002.09
Post: #8
First error: the drawing code isnt' inside a method/function. I suppose you don't want both a { and a } after the switch, only one makes sense. Second error, you need the OpenGL headers included: #import <OpenGL/gl.h> at the top of your file. I think the other two errors are caused by these two. Smile Good luck.
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #9
Fenris Wrote:I suppose you don't want both a { and a } after the switch, only one makes sense.
Thanks and which one?

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Oldtimer
Posts: 832
Joined: 2002.09
Post: #10
Sorry, the {. That starts a function that you're closing a bit of ways down. The way you have it now starts a function, and ends it. The code that follows it is dangling freely.
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #11
So, what should I edit? Maybe you could fix the code by pasting it and editing as needed? Adding the OpenGL header does this, btw. wait, wrong link...

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #12
Ok, here are the errors [Image: ?id=410653]

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Moderator
Posts: 770
Joined: 2003.04
Post: #13
Try this:
PHP Code:
#import "GameView.h"
#import "Game.h"
#import "GameView.h"
#import <OpenGL/gl.h>

@implementation GameView

- (id)initWithFrame: (NSRect)frameRect
{
    if ((
self = [super initWithFrame:frameRect]) != nil)
    {
        
// Add initialization code here
    
}
    return 
self;
}

- (
void)drawRect: (NSRect)rect
{
    switch([
game state])
    {
        case 
STATE_TITLE:
            [
self displayTitle:rect];
            break;

        case 
STATE_PLAYING:
            [
self displayPlaying:rect];
            break;

        case 
STATE_GAME_OVER:
            [
self displayGameOver:rect];
            break;
    }

    
glFinish();
    [[
self openGLContextflushBuffer];
}

- (
void)displayTitle: (NSRect)rect
{
}

- (
void)displayPlaying: (NSRect)rect
{
    
glClearColor(0,0,1.0f,0);
    
glClear(GL_COLOR_BUFFER_BIT);
}

- (
void)displayGameOver: (NSRect)rect
{
}

@
end 
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #14
It built but, the window didn't open nd it said this:
[Session started at 2005-04-29 07:30:38 -0400.]
ZeroLink: unknown symbol '_glClearColor'

Executable “FlipSquare” has exited due to signal 6 (SIGABRT).

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #15
make sure to include the OpenGL headers and frameworks.

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Post Reply