I am developing a game engine here:
http://synodins.com/apps/tank_fight
But now, for some reason, it doesn’t run anymore.
I cannot initiate the Raphael module, when i run the site with mozilla web debugger, i get “Raphael is not defined”.
But that doesn’t make any sense because it’s very clearly defined in the raphael.js module.
Also, occationally the game runs fine, like, every 20th time i try.
And there’s no clear pattern to what makes it work.
I print out Hello world 1 before trying to initiate raphael, and hello world 2 after trying.
Can anybody see what the problem is?
The block of
load_scriptcalls loads the scripts asynchronously. This is why there appears to be no clear pattern.There is no guarantee that raphael.js is loaded (and therefore, that
Raphaelis defined) by the time that the line:is called.
You should wait until the whole document is ready before attempting to use variables defined in external scripts. Under normal circumstances, this is the
onloadevent of the document. Various libraries like jquery also offer their own “ready” event, that you could tie to if you use them.Is there any reason why you load the scripts in the way you do, rather than simply using markup, as below?