Problems with the switch statement

Moderator
Posts: 623
Joined: 2007.09
Post: #16
Well, that got me down to only five errors, which shouldn'tt be too hard to fix. Thanks for all the help!Wink
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #17
Alright, now I'm getting a 3 parse errors in Game.h. See code.
Code:
/* Game */

#import <Cocoa/Cocoa.h>
#import "Cell.h"

#define BOARD_SIZE 8

enum { STATE_TITLE, STATE_PLAYING, STATE_GAME_OVER };

@class GameController, GameView;
Cell* board[BOARD_SIZE] [BOARD_SIZE]; // game board



@interface Game : NSObject

- (void)setState:(int)newState;
- (int)state;
- (Cell*)cellAtRow(int)row andColumn:(int)column;
- (void)resetBoard;
{
    IBOutlet GameController *gamecontroller;
    IBOutlet GameView *gameview;
    int state; // current Game state

}


@end
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #18
First, what are the errors?

Second, don't you need to include the headers that define GameController, GameView, etc?

(and everyone mistypes Smile )

It's not magic, it's Ruby.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #19
Don't include headers in headers, as a general rule. Forward declarations are perfectly sufficient in this case.
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #20
Firstly, Cell.h doesn't have anything in it so far, so I don't know why I was told to do it,(But I don't know alot of what I'm doingRolleyes). Secondly the errors were not actually in Game.h(I should have made this clear). What Happens is, I have two files, GameView.m and GameController.m. They are both getting three error messages;
"parse error before '(' token"
"parse error before '{' token"
"parse error before '}' token". The little Red circle with the "x" appears in each of them next to the line; "#import "Game.h". Since neither GameView.m or GameController.m have (, {, or }, I assumed the problem was in Game.h. So I really have no idea what's going on.Mad Perhaps I should use a different tutorial?Sad

Lincoln Green

P.S What do you mean, everyone Mistypes?
Quote this message in a reply
Member
Posts: 283
Joined: 2006.05
Post: #21
Code:
- (Cell*)cellAtRo[b]w([/b]int)row andColumn:(int)column;

Needs a colon after cellAtRow. Should help a bit.
Quote this message in a reply
⌘-R in Chief
Posts: 1,237
Joined: 2002.05
Post: #22
Code:
#import "Cell.h"

What Keith said.



Code:
#define BOARD_SIZE 8

enum { STATE_TITLE, STATE_PLAYING, STATE_GAME_OVER };

Fine...


Code:
@class GameController, GameView;

Ok...


Code:
Cell* board[BOARD_SIZE] [BOARD_SIZE]; // game board

Red alert.

You're declaring a global variable "board" here. Bad bad bad.



Code:
@interface Game : NSObject

- (void)setState:(int)newState;
- (int)state;
- (Cell*)cellAtRow(int)row andColumn:(int)column;
- (void)resetBoard;
{
    IBOutlet GameController *gamecontroller;
    IBOutlet GameView *gameview;
    int state; // current Game state

}
@end

DEFCON 1. This isn't valid at all.

A) You've completely mixed up where the braces and member variables go. Revisit Objective-C syntax 101.

B) What maximile said.




What you should have is:

Code:
#import <Cocoa/Cocoa.h>


#define BOARD_SIZE 8

enum {
    STATE_TITLE,
    STATE_PLAYING,
    STATE_GAME_OVER
};


@class GameController, GameView, Cell;
@interface Game : NSObject
{
    Cell * board[BOARD_SIZE][BOARD_SIZE];
    IBOutlet GameController * gamecontroller;
    IBOutlet GameView * gameview;
    int state;
}

- (void)setState:(int)state;
- (int)state;
- (Cell *)cellAtRow:(int)row andColumn:(int)column;
- (void)resetBoard;




What tutorial are you reading? Either you're messing up the reading part pretty thoroughly or it has some pretty shoddy code examples... Rolleyes
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #23
Ah. that got rid of the parse "(" errors. Just 4 left…
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #24
FreakSoftware Wrote:What tutorial are you reading? Either you're messing up the reading part pretty thoroughly or it has some pretty shoddy code examples... Rolleyes

http://www.cloisterroom.com/FlipSquare.pdf
Quote this message in a reply
Member
Posts: 81
Joined: 2007.05
Post: #25
How about ... adding some brackets.

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;
}
default:
break;
}
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #26
macnib Wrote:How about ... adding some brackets.

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;
}
default:
break;
}

We already solved the Switch function problem, it was actually a problem earlier in the code. But thanks anyway…
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #27
Well, It's pretty good practice, and as a bonus, you get scoped code Smile

It's not magic, it's Ruby.
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #28
Nayr Wrote:Well, It's pretty good practice, and as a bonus, you get scoped code Smile

Touché.Rolleyes
Quote this message in a reply
Post Reply