Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Apiheld

I usually declare globals in main.js like that, before everything else:

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.

1 decade ago by FelipeBudinich

This is a very interesting shortcoming that is created by the tight coupling between weltmeister and how we define entities.

It is silly, but keep in mind that entities are already aware of the level editor:
http://impactjs.com/documentation/class-reference/entity#wmscalable

(Personally, I do not use weltmeister anymore because I would need to modify it too much in order to make it work on my project)
Page 1 of 1
« first « previous next › last »