+ 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

22nd May 2019, 12:53 AM
Archie
Archie - avatar
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)
22nd May 2019, 5:57 AM
KrOW
KrOW - avatar
0
I also tried using a while loop to keep running until the player variable is recognized, but that just crashed the app 😅
22nd May 2019, 12:57 AM
Archie
Archie - avatar