-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about array scope in Game of Life #8
Comments
@daveronson hey you've probably already solved this, but I wanted to solve this problem and have it auto-seed as well. I tried moving the rows and cols into state, but I had the same failure as before when I added the this.seed() call after this.clear() in the gridSize() function. So I don't think it's a scope issue, maybe I'm wrong. But when I removed the arrayClone() call from the seed() function [the one doing the JSON stringify/parse trick] and replaced it with a newly generated gridCopy built of the this.row and this.col values, everything worked. In fact, you don't need to call this.clear() in the gridSize() at all, just call this.seed() Anyways, my repo of it auto-seeds, if you'd like to check it out: https://github.com/donkeypagoda/gol-react-tutorial |
Great video about creating the Game of Life.
I was trying to enhance the gridSize function to call this.seed and then this.playButton after this.clear but I get an out of bounds error when choosing the largest grid because the array is still 50x30 and it's trying to seed 70x50. This obviously doesn't happen in the original code when you select gridSize and then separately click the seed button.
I'm not sure if this is state vs prop vars, an array creation issue or if this is a array scope issue? Any thoughts would be appreciated.
The text was updated successfully, but these errors were encountered: