gniziemazity / self-driving-car

MIT License
665 stars 332 forks source link

Uncaught TypeError: Cannot read properties of undefined. #1

Closed kid-gorgeous closed 2 years ago

kid-gorgeous commented 2 years ago

Hello, I've noticed there was an error while following along. This was found at 57:46 of the video. Not sure what to do to fix this. Maybe it's my browser?

error

robert-wallis commented 2 years ago

maybe the draw method for loop on line 32 should use this.rays.length instead of this.rayCount, also it's looking for an x and y property but on line 27 it pushes an array instead of an object with x and y properties

kid-gorgeous commented 2 years ago

I don't think it changed very much. The first index of the array holds a object that carries the x, and y value, but it's not accessing it from what I can tell. The length of the for loop is based off of the amount of rays requested, so I don't think changing rayCount will help either. Thank you for the input though. Im still working towards a solution. 😅

nickhandberg commented 2 years ago

Check if you have a duplicate car.draw(ctx) in the main.js file outside of the animate function and remove it.

kid-gorgeous commented 2 years ago

It does seem like a declaration error, but it threw me off. Im not a frequent javascript..

But just want to make a note to the creator: thank you for making this; "3. Artificial Sensor" worked fine after cloning and compilation. It's really cool application you made. I think it's a fantastic way to use, and especially learn javascript. This is extraordinary work.

Jackferson commented 2 years ago

As @noko12312 says, this problem is caused by a duplicated call of car.draw method, this ran before the car.update function was called, which meant that the sensor draw was called before any sensors were created.

Just make sure there is no draw outside the animate function on the main.js

kid-gorgeous commented 2 years ago

As I said @Jackferson, nothing was duplicated. Thank you for your concerns.