views:

35

answers:

1

I'm getting a little confused how to set up a class that's two steps below the top-most one.

For instance, say I have a game called BoardGame. One of whose parameters in numberOfSquares.

The classes are setup like this:

BoardGameSetupViewController > BoardGamePlayViewController > GameEngine

BoardGameSetupViewController creates an instance of BoardGamePlayViewController after the number of squares has been chosen. BoardGamePlayViewController has the GameEngine class as a @property which has been @synthesised.

So how would I set up that GameEngine directly from BoardGameSetupViewController? To set up the numberOfSquares for instance?

So in BoardGameSetupViewController, I want to set the properties of the engine, but they don't seem to get passed on.

BoardGamePlayViewController *boardGamePlayViewController = [[BoardGamePlayViewController alloc] initWithNibName:@"BoardGameView" bundle:nil];

// this line doesn't work
boardGamePlayViewController.gameEngine.numberOfSquares = 12;
+2  A: 

You first need to create an instance of GameAEngine beofre you do the assignment boardGamePlayViewController.gameEngine.numberOfSquares = 12; So,

GameEngine *gameEngine = [[GameEngine alloc] init];
boardGamePlayViewController.gameEngine = gameEngine;
boardGamePlayViewController.gameEngine.numberOfSquares = 12;

should work.

ennuikiller