1 decade ago by gxxaxx
I have a short list of vars (mostly config parameters) that I want to store and make available globally.
My first inclination was to use parameters in "main" for this purpose.
But my entities are instantiated before main. Or at least "ig.game.myparam" is undefined when the entities are being instantiated.
To handle this I have been using a post init so that certain things are accomplished during the first update cycle rather than in init.
So here's my bright (???) idea.
Create a singleton-ish class
Then I can reference parameters in this class using something like the following:
So the question is, what do you think?
Is this workable?
Or, is there something about this approach that will blow up in my face?
I would really like to have a place to put parameters that exists before my entities "init".
Thanks for any clues,
My first inclination was to use parameters in "main" for this purpose.
But my entities are instantiated before main. Or at least "ig.game.myparam" is undefined when the entities are being instantiated.
To handle this I have been using a post init so that certain things are accomplished during the first update cycle rather than in init.
So here's my bright (???) idea.
Create a singleton-ish class
ig.module( 'game.entities.special.vault' ) .requires( 'impact.impact' ) .defines(function(){ ig.MyVault = ig.Class.extend({ player: null, world: 'flat', param2: '', etc: true, init: function(theGame){ this.kill(); } }); });
Then I can reference parameters in this class using something like the following:
ig.MyVault.prototype.world = 'side';
So the question is, what do you think?
Is this workable?
Or, is there something about this approach that will blow up in my face?
I would really like to have a place to put parameters that exists before my entities "init".
Thanks for any clues,