Do away with the declaration of readgrid, and the assignment of generation to it. First of all, generation is not declared in the scope of next(), and secondly I doubt you would need readgrid because you already have access to cells.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.

Ian E Jones

Greenhorn

Posts: 4

posted 7 years ago

Those are the errors. I declared size on line 7, is there something else I should be doing at the end with that variable?

Stephan van Hulst

Saloon Keeper

Posts: 8975

168

posted 7 years ago

1

Neither size nor generation are declared within the scope of the next method. They are local to the main method, and the Life constructor.

I already told you what to do about the generation symbol. Replace size in your next method with cells.length, and cells[row].length.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.

Stephan van Hulst

Saloon Keeper

Posts: 8975

168

posted 7 years ago

1

Also, I notice you assign new columns to the cells array in your next method. Don't do this. First construct the array newGrid with the same dimensions as cells, then read all the data you want from cells, and apply the results to newGrid. Finally when you are done, assign newGrid to cells. This will assure that you don't change the old situation before you are done reading from it.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.

Ian E Jones

Greenhorn

Posts: 4

posted 7 years ago

That's actually what I was trying to do, I was just coming up with errors trying to write it any different way, what should I be doing here?

Stephan van Hulst

Saloon Keeper

Posts: 8975

168

posted 7 years ago

If I may make a suggestion, start like this, it should make the next method easier to implement, and the Life class easier to use by another class in general:
Make sure the next() method does not change the state of the current object.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.