CodingTrain / CodingTrain/Toy-Neural-Network-JS

Cannot read property 'top' of null

Open
#142 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
437
Forks
242
PR merge metrics
No merged PRs in 30d

Description

When i was following along the video i got the following error:

> Uncaught TypeError: Cannot read property 'top' of null Bird.js:44

the same error as in the video but when he fixed it and i wrote the same as him i still got the error. does somebody knows how to fix this issue?

This is the code:`

let closest = null;
let closestD = Infinity;
for (let i = 0; i < pipes.length; i++) {
let d = pipes[i].x - this.x;
if(d < closestD && d > 0) {
closest = pipes[i];
closestD = d;
}
}

let inputs = [];
inputs[0] = this.y / height;
inputs[1] = closest.top / height;
inputs[2] = closest.bottom / height;
inputs[3] = closest.x / width;
let output = this.brain.predict(inputs);
if(output[0] > 0.5) {
this.up();
}
`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at Bird.js:44 and trace the pipes loop before the inputs are assembled. Reproduce the tutorial state where no pipe is selected, then verify the prediction path can run without the null-property error. Done means the reported TypeError no longer occurs during the game.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
game-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.