+ 1
Cannot read property of "x"
It kept saying that the property of x is undefined, but this event would occur temporarily. When the bullet collides with the ufo. How could i fix that? for(var i = 0; i < numberOfFruits; i++){ const bulletsShooting = bullets.filter(element => element.isShooting === true) for(var bulletShooting of bulletsShooting){ if(Collide(bulletShooting, fruits[i])){ fruits.splice(fruits.indexOf(fruits[i]), 1) numberOfFruits -= 1 player.score += 10 } } } https://code.sololearn.com/W5Y5Nkm3A7jB/?ref=app
1 Answer
+ 2
If the error isn't persistent, then I think the problem is when you're updating the number of fruits,
`i < numberOfFruits` is slower so collision function tends to collide with an undefined fruit, so it'll be better to loop backward
for (I = numberOfFruits; I > -1; I--)
Also, do expect the unexpected console error message when writing games, so always add this to stop all console errors when you're ready to publish your code
onerror = () => {};
console.log = () => {};
console.error = () => {};