Ask coding questions

← Back to all posts
cannot read width of undefined
EduardFaus

https://replit.com/@EduardFaus/flappybirdAi#Javascript/script.js

I have been working on implementing an ai to flappy bird. I decided to try to create a sort of algorithm like neat from scratch in my code. For some reason everytime i reach the second generation and the birds get replaced with the new generation I get an error.

The console tells me " TypeError: Cannot read property 'width' of undefined ".

When opening it with chrome web tools it seems that this error is referring to when I try drawing my players.

What I don't understand is how are they undefined. In code I tried making it so it would console.log when my birds are undefined and it never runs. I even tried adding if statements to my code so it would only run if it was still defined (now removed). However I couldn't get it to work.

I researched the error and got here (https://stackoverflow.com/questions/53226663/typeerror-cannot-read-property-width-of-undefined) the thing is I don't see anywhere in the code where I redefined a variable.

Does anyone understand why I am getting this error?

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
DynamicSquid
EduardFaus
Comments
hotnewtop
Coder100


u never defined this.birdImg so make sure to do that.

EduardFaus

@Coder100 thank you so much :D

Coder100