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

9 years ago by Oliver

Hello people!
I made a little plugin (my first one, im new with impactjs), and its body looks like this:

ig.module(
    'plugins.dibujaceldas'
)
.requires(
    'impact.game'
)
.defines(function(){

ig.Dibujaceldas = ig.Class.extend({

    staticInstantiate: function(i)  {
	return !ig.Dibujaceldas.instance ? null : ig.Dibujaceldas.instance;
    },

    init: function()    {
	ig.Dibujaceldas.instance = this;
    },
    Dibujarceldas: function (posicionx, posiciony, pasosadar) {
    },
    
});

});

so.... whenever y try to use this plugin in my player entity doing something like this:

init: function( x, y, settings ) {
        this.parent(x, y, settings);
        this.celdasdibujadas = new ig.Dibujaceldas();
        this.queceldaspinto = this.celdasdibujadas.Dibujarceldas(ig.game.zeldax, ig.game.zelday, this.pasos);
},

and try to edit the layers with weltmeister i get this error:

Uncaught TypeError: undefined is not a function


I dont know why i get this error, my fast and easy solution by now is commenting this line:

this.celdasdibujadas = new ig.Dibujaceldas();

And (while the game gets a error) weltmeister works like a charm. But i want to use this plugin in dozens of entities so commenting the line in every single entity wont be aviable option anymore... could you please help me get a solution for this problem?

Thanks! (and sorry for the horrible english)

9 years ago by Joncom

You're trying to use your plugin in your player entity:
new ig.Dibujaceldas();

Did you require it first though?
ig.module(
    'game.entities.player'
)
.requires(
    'impact.entity',
    'plugins.dibujaceldas'
)

If you don't require it, it won't get loaded, and therefor will be "undefined".

9 years ago by Oliver

Hello Joncom
Yes, sadly i do require it first, and i dont get any errors when i play the game. The problem is only when i try to edit it with weltmeister. Any other ideas?

Thanks!

9 years ago by Datamosh

If you do not require the function dibujaceldas in weltmeister, you can detect the context before use:

if (!ig.global.wm) {
	this.celdasdibujadas = new ig.Dibujaceldas();
	this.queceldaspinto = this.celdasdibujadas.Dibujarceldas(ig.game.zeldax, ig.game.zelday, this.pasos);
}

9 years ago by drhayes

Does that mean "draw cells"?

If you change it from ig.Dibujaceldas.instance to ig.algo in your class does it work?

It's not super related, but instead of:

return !ig.Dibujaceldas.instance ? null : ig.Dibujaceldas.instance;

you can say:

return ig.Dibujaceldas.instance;

Same thing.

9 years ago by FelipeBudinich

@drhayes Could you please explain why:

return !ig.Dibujaceldas.instance ? null : ig.Dibujaceldas.instance;

is the same as:

return ig.Dibujaceldas.instance;

?

9 years ago by drhayes

Sure!

When you say !ig.Dibujaceldas.instance ? null : ig.Dibujacelda.instance; you're saying "if I don't have an object return null, else return the object", right? If you don't have an object, you either have null or undefined. Those values will have the same effect.

9 years ago by Oliver

Perfect! thank you for your help!!!

9 years ago by stahlmanDesign

As @Datamosh said, entities that are to be laid out in Weltmeister might not be able to reference another entity because you're in the level editor, not the game. In such entities, check to see if you are in Weltmeister and if you are, skip over the offending code:

if (!ig.global.wm) {
 // not in WM, safe to reference other entity etc.
}
Page 1 of 1
« first « previous next › last »