Problems with the switch statement
Well, that got me down to only five errors, which shouldn'tt be too hard to fix. Thanks for all the help!

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
First, what are the errors?
Second, don't you need to include the headers that define GameController, GameView, etc?
(and everyone mistypes
)
Second, don't you need to include the headers that define GameController, GameView, etc?
(and everyone mistypes

It's not magic, it's Ruby.
Don't include headers in headers, as a general rule. Forward declarations are perfectly sufficient in this case.
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 doing
). 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.
Perhaps I should use a different tutorial?
Lincoln Green
P.S What do you mean, everyone Mistypes?

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


Lincoln Green
P.S What do you mean, everyone Mistypes?
Code:
- (Cell*)cellAtRo[b]w([/b]int)row andColumn:(int)column;
Needs a colon after cellAtRow. Should help a bit.
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...

Ah. that got rid of the parse "(" errors. Just 4 left…
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...
http://www.cloisterroom.com/FlipSquare.pdf
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;
}
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;
}
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…
Well, It's pretty good practice, and as a bonus, you get scoped code

It's not magic, it's Ruby.
Nayr Wrote:Well, It's pretty good practice, and as a bonus, you get scoped code
Touché.
