1 decade ago by Apiheld
I usually declare globals in main.js like that, before everything else:
then I use ig.global.TILESIZE in the init() method of an Entity. This usually works without a problem. I just figured now that this won't work in Weltmeister. The global is undefined in Weltmeister, which leads to an error so that the entity isn't shown at all.
The question now is: How do you declare globals such that Weltmeister also knows them? From my understanding, Weltmeister loads the entities via PHP/AJAX only and ignores the main.js file (and modules, plugins etc.)
Another solution would be to check in an entity whether the Weltmeister scope is loaded and use global variables in init() only, if the scope is NOT Weltmeister:
but how silly is that? My Entity shouldn't know anything about the Level editor.
ig.global.TILESIZE = 32; ... ig.module( 'game.main' ) ...
then I use ig.global.TILESIZE in the init() method of an Entity. This usually works without a problem. I just figured now that this won't work in Weltmeister. The global is undefined in Weltmeister, which leads to an error so that the entity isn't shown at all.
The question now is: How do you declare globals such that Weltmeister also knows them? From my understanding, Weltmeister loads the entities via PHP/AJAX only and ignores the main.js file (and modules, plugins etc.)
Another solution would be to check in an entity whether the Weltmeister scope is loaded and use global variables in init() only, if the scope is NOT Weltmeister:
if (window.wm === undefined) { this.myVar = ig.global.DIRECTION.UP; }
but how silly is that? My Entity shouldn't know anything about the Level editor.