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 Joncom

I have an entity that looks something like:
EntityBullet = ig.Entity.extend({
    checkAgainst: ig.Entity.TYPE.A,
    team: ig.ENUMS.TEAM.GOOD,
    init: function(x, y, settings) {
        this.parent();
    }
    // etc...
});

I've defined my ENUM at the very top of main.js like so:
ig.ENUMS = {
    TEAM: { GOOD: 1, BAD: 2, NEUTRAL: 0 }
};

The problem is that Weltmeister complains because it has not run main.js:
Uncaught TypeError: Cannot read property 'TEAM' of undefined -- Line 8 bullet.js

So the question is, where is a good place to store ENUMS so that they are accessible to entities in Weltmeister?

1 decade ago by dominic

Just create a new file lib/game/enums.js with the module name game.enums and require that module in each of the entities that use the enums.

All modules that are required by an entity module will also be loaded by Weltmeister.

Btw.: Impact&039;s built-in <1> property for Entities (and the corresponding <2>) is intended to be used as something like your #.team property.

1 decade ago by Joncom

Thank you dominic.

Using .team instead of .type because I didn&039;t see an easy way to add a third value to #ig.Entity.type, such as C - two types is just not enough. And also, "good/bad/neutral" makes for easier to read code.

1 decade ago by SlinkyDinky

Don't mind me, I'm just posting in order to find this thread again.

1 decade ago by Joncom

@SlinkyDinky: Bookmarks sure are handy, aren't they? ;)

1 decade ago by SlinkyDinky

Gotta say, I'm not a fan of bookmarks, never have been. Not sure why, though. Seems a little restrictive to me.

1 decade ago by Joncom

I realize this is completely off-topic now, but SlinkyDinky, you have not provided an email in your forum profile, so I have no other way of continuing this conversation. I'm curious how "posting" in a thread is a useful means of finding useful threads. Do you periodically look over all threads you've posted in?
Page 1 of 1
« first « previous next › last »