+ 1
Why is this element null?
In this code, I'm trying to make a moveable "player" object, and while trying to start working on the basic functions, the player keeps becoming null. I don't know how to make this stop persisting. https://code.sololearn.com/W6kn1U4hQbSc/?ref=app
2 Answers
+ 1
Check line 29:
window.onload= getPos();
This line CALL getPos when the script run (and the code in is tab on SL run BEFORE the processing of html) and assign the result (in this case no result) to window.onload and is not what you want. The correct use is this:
window.onload= getPos;
Note the lacks of parentheses than assign a reference to getPos to window.onload callback (opposed to call the function)
0
I also tried using a while loop to keep running until the player variable is recognized, but that just crashed the app đ