How can I access each other’s objects / variables / functions?
The call of MyClass.test() leads to an error cause “MyClass” is undefined. I’ve included the external events into the main events, but this doesn’t work. The scope seems to be separated. What is the way to go?
To elaborate, that is because each event is its own function. var defines a variable as function scoped, so as soon as the Javascript event it is in finishes executing, it goes out of scope and is deleted. The labels at the top and bottom of the Javascript event are supposed to hint at that. By attaching the variable to the global window, it isn’t a scoped variable anymore and I’ll be accessible at anytime from anywhere.
Note that window is not a guaranteed global scope. In the future, the game might run in an environment where window is not the global scope, sou you should always attach your stuff to the gdjs global object instead, as that one is always guaranteed to be defined in a GDevelop game.