1

I have been attempting to follow on how to make John Conway's 'Game of Life' through 'Make Games With Us'. I was able to follow for most of the tutorial until I reached in the step method of MainScene.m (here is the link to the site):

- (void)step
{
    [_grid evolveStep]
    _generationLabel.string = [NSString stringWithFormat:@"%d", _grid.generation];
    _populationLabel.string = [NSString stringWithFormat:@"%d", _grid.totalAlive];
}

The errors are of the same type; they're showing up at _grid.generation and _grid.totalAlive. The error is the following:

Property 'generation' not found on object of type 'Grid *'
Property 'totalAlive' not found on object of type 'Grid *'

I have looked at this link on how to fix the very same issue, yet I saved and published everything correctly in SpriteBuilder; the user apparently solved it, but I cannot find out how.

Update: Missing Property Declaration (Grid.m):

#import "Grid.h"
#import "Creature.h"

// variables that cannot be changed
static const int GRID_ROWS = 8;
static const int GRID_COLUMNS = 10;

@implementation Grid {
    NSMutableArray *_gridArray;
    float _cellWidth;
    float _cellHeight;
    int _generation; // This one
    int _totalAlive; // This one
}

/*Rest of the methods go here*/

@end

Thank you in advance!

virenabhyankar
  • 251
  • 1
  • 2
  • 9

2 Answers2

2

This unfortunately was a mistake in our tutorial.

Indeed you need to add two properties to Grid.h:

@property (nonatomic, assign) int totalAlive;
@property (nonatomic, assign) int generation;

Instead of adding instance variables to Grid.m.

The tutorial has now been updated: https://www.makegameswith.us/tutorials/game-of-life-spritebuilder/game-of-life-code/

You can also find the entire code for the solution on GitHub: https://github.com/MakeGamesWithUs/GameOfLife.spritebuilder

Sorry for the inconvenience!

Ben-G
  • 4,996
  • 27
  • 33
  • Thanks. I had figured out that I needed to replace the iVars with properties. I am currently working on finishing the game. – virenabhyankar May 27 '14 at 22:52
0

The error message is telling you that there is no property named generation for the class Grid. Perhaps you are getting confused with accessing properties directly with a leading "_" vs "self.".

Insure that such a property exists. Update the question to show th declarations of the missing properties.

Just use the property setters and getters instead of directly accessing them. Declare all ivars as properties. That creates consistence and reduces errors.

zaph
  • 111,848
  • 21
  • 189
  • 228
  • Thank you. I decided afterwards to change the instance variables into properties and the code worked just fine. However, I would still like to solve how to "work" the code with iVars because it seemed to work for the authors of the tutorial. – virenabhyankar May 27 '14 at 16:28
  • @KodInc Where is the tutorial? – zaph May 27 '14 at 16:33
  • I have provided the link in the original post (it is the first link). – virenabhyankar May 27 '14 at 16:35
  • Property statements by default create instance variables with a leading underscore. The current wisdom is to use properties. Among other reasons is KVC and the later ability to change the setter/getter behavior without having to change the code that uses them. – zaph May 27 '14 at 16:36
  • OK, got the link. I would advise against using tutorials found on their site. Good tutorial sites include [Ray Wenderlich Tuturials](http://www.raywenderlich.com) and [IOS SDK | Mobiletuts+](http://code.tutsplus.com/categories/ios-sdk). Also consider the great site [NSScreencast](http://nsscreencast.com)($9 per month, well worth it) – zaph May 27 '14 at 16:41
  • Thank you for your help! I have also gone through those sites' tutorials and have succeeded in building some applets. – virenabhyankar May 27 '14 at 16:42
  • @KodInc I would definitely not advise against using our tutorials! While this was an unfortunate mistake that happened while updating the tutorials we have received great feedback by hundreds of users for all of our tutorials so far. – Ben-G May 27 '14 at 20:18
  • @Ben-G I have looked at your code on GitHub and it just is not current with best practices. An example is the `Creature` class and the handling of `isAlive`, use of `self.isAlive` in `init`, use of `FALSE` in stead of `NO`, `isAlive` in place of `alive` and `getter=isAlive` in the property declaration. See Apple's document [Programming with Objective-C](https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html) – zaph May 27 '14 at 20:47
  • @Zaph I agree that the tutorial should be updated to use `YES`/`NO` instead of `TRUE`/`FALSE`. Besides that most of the best practices are not applied intentionally. In our first tutorials we focus on giving people a quick start - building a game without having to learn all language details and best practices upfront. – Ben-G May 27 '14 at 21:55
  • @Ben-G Just a side note, I found some inconsistencies with the Github source and the code on the tutorial. This isn't really **that** important; however, it is hard for someone who is checking up on both to see. – virenabhyankar May 27 '14 at 23:40