• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't figure out error

 
Ranch Hand
Posts: 83
Android Python Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the code



I get the error Cannot read property 0 of undefined. What does this mean and how can I fix it?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the purpose of line 12? Appending a string to an array? Does that make sense?

I'd advise breaking this down into multiple functions that each perform one duty.
 
Rocky Rocha
Ranch Hand
Posts: 83
Android Python Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tmpArr is an array. I'm making an x*x array.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Appending a string to an array? Does that make sense?

 
Rocky Rocha
Ranch Hand
Posts: 83
Android Python Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so I figured out my original problem. But now I have an even bigger problem.

First of all, I am trying to make a javascript implementation of Conway's Game of Life(CGoL). Now, for CGoL to work, you have to update all of the squares once, and only once without letting an update of an adjacent square impact it. Basically, I have to update all of the squares at the same time. How do I do that?

Here's my updated code:
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rocky Rocha wrote:Basically, I have to update all of the squares at the same time. How do I do that?



You stash the updated values somewhere else, and then when you've calculated all of them, you copy them back to where the original values are.

Or alternatively: you copy all of the original values somewhere else, and then use the somewhere-else values to compute the new original values.
 
Rocky Rocha
Ranch Hand
Posts: 83
Android Python Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks that works, but now I have another problem. How would I push an empty array into an array? Specifically, how do I push [] into simView.grid?
 
Rocky Rocha
Ranch Hand
Posts: 83
Android Python Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So right now my issue is that I cannot read the value of the 2D array. Here is my code.



What does this error mean, and how can I fix it?
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic