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 MikeL

I'm working on a way to create a close approximation of Ruby symbols in impact. I've got it working with a plugin such that if I put within MyGame in my main.js file:

symbols:  new ig.Symbols("JUMPING RUNNING HIDING etc."),  

I can then use:

ig.s.JUMPING 

in my entities and it will have had a number automatically asigned to it. Saves having to asign say STATE{JUMPING: 1, RUNNING: 2, etc.} and allows the symbol to be used anywhere within any class. Within the Symbols class it does:

ig.s = this;

in order to allow for the shortcut version and allow it to be accessible everywhere.

It works great within the game. The problem is that I get an error in Weltmeister. This is because the entities may be referring to say ig.s.JUMPING, but Weltmeister doesn't know what ig.s is. It will throw an Uncaught TypeError.

Is there a simple way to get Weltmeister to recognize the custom class and shortcut naming (ig.s)?

1 decade ago by dominic

Weltmeister only calls the init() and draw() methods of entities.

I guess you're checking for ig.s.JUMPING in your draw method? Maybe you could move into the update method, and switch animations there (or jump to a specific frame, or whatever you need), so that draw() draws the right thing.


You can also check if ig.global.wm is defined, to see if you're running in the editor:
if( !ig.global.wm ) {
	// Not in Editor - Do some fancy stuff here.
}

Btw: that symbols thing is really interesting. I thought about defining values for my input actions when I worked on Biolab Disaster, but then decided to just use strings, because... I'm lazy :D

Maybe you could even get rid of the initialization of your symbols with getters and setters somehow!?

1 decade ago by MikeL

Appreciate the explanation Dominic. I think that was a wise move you made going with strings for the input action. I think I'm going to drop this for now otherwise I'll never got on to the next game! (And I can help get rid of this headache...)

1 decade ago by MikeL

Ok. I lied. I couldn't drop it. But I found out a work around. I also found this out as I examined more closely:

If I put ig.s.JUMPING, for example, anywhere within the enitity (either in init, draw, or even as a member as in state: ig.s. JUMPING), I will get an

Uncaught type error: cannot read property 'Jumping' of undefined.


On the other hand if I just use ig.s. There is no problem even if 's' is not defined. So I was essentially calling ig.undefined.undefined which you apparently can't do in Javascript. But you can do ig.undefined for example.

I found a similar issue when I tried to spawn another entity from within an Entity's init function as in: ent = ig.game.spawnEntity( EntityParachute, x, y ); Here I would get an

Uncaught TypeError: Cannot call method 'spawnEntity' of null


So to counter the problem for my symbols plugin, I changed my terminology to:
ig.Entity.JUMPING
which works fine both in the game and in Weltmeister, because only JUMPING is undefined. Going to test more to be sure...

1 decade ago by Ken

LOL 2pts for sticking with it MikeL. Thanks for sharing and interesting about the can do ig.undefined but not ig.undefined.undefined.
Page 1 of 1
« first « previous next › last »