• 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. :( The problems are in italics and this is the Game.h file, can anyone help me?

    /* Game */

    #import
    @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


  • I did that one...


  • 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 at the top of your file. I think the other two errors are caused by these two. :) Good luck.


  • The window doesn't open and I get this warning, /Users/matthew/FlipSquare/GameView.m:35: warning: `GameView' may not respond to `-openGLContext'


  • through IB, how would I do that programmatically?


  • Which ones?


  • I suppose you don't want both a { and a } after the switch, only one makes sense.
    Thanks and which one?


  • 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).


  • Sorry but: http://www.imagehosting.us/imagehosting/showimg.jpg/?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


  • 1) missing semi-colon after the enum.
    2) the second error is symptomatic of the first.


  • When he said after enum he meant this:

    enum { STATE_TITLE, STATE_PLAYING, STATE_GAME_OVER }; // At the end


  • one last problem:

    /* Game */

    #import
    @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


  • oh...oops, sorry


  • make sure to include the OpenGL headers and frameworks.


  • Is GameView a subclass of NSOpenGLView? If not, you can set that through either IB or programmatically. How did you create the GameView class?


  • Well for started add the openGL framework then include openGL/opengl.h (i think thats the name)


  • Ok, here are the errors http://www.imagehosting.us/imagehosting/showimg.jpg/?id=410653


  • 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.


  • ok, thanks :D


  • 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...


  • Try this:
    #import "GameView.h"
    #import "Game.h"
    #import "GameView.h"
    #import

    @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







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Problems with Obj-C , Please add it free.