0
Why it cant read the property?
Tried making a snake game with a starting menu, but cant get the x and y position of the mouse click. https://replit.com/@FallenMoon/snakegame#script.js
2 Respuestas
+ 1
Gabriel Rossine Are you referring to the menu(evt) function?
Are you receiving errors that indicate "Cannot read property pageX of undefined on line..." or something to that effect?
If so, I'm sure the cursor position relative to the page is available when the menu(evt) function is called as a handler for the MouseEvent.
It's likely the issue you're experiencing occurs when the same menu(evt) function is called by the setInterval() function.
In this case, evt will be undefined when menu() is called by setInterval() thereby resulting in errors everytime evt.pageX and evt.pageY are called on undefined. It's like calling undefined.pageX and so on.
One option to test this theory is to add the following to the first line of the menu(evt) function to see if that specific error disappears.
function menu(evt) {
evt = evt ? evt : { pageX: 0, pageY: 0 }
...
}
Or something to that effect.
But this is only a temp code to quickly get past the errors and likely will require additional changes.
0
David Carroll Thanks. I will try it.