Hi!
I have Root(Game) script wich do calculations for another entities. How can i pass value from root to another entity script.
I tried use passing in root atribute an another entity, and call it’s srtipts with parameters. But there is not correct function context.
For example:
Game.attributes.add('anotherEntity', { type: 'entity' });
Game.prototype.setToAnotherEntity = function() {
const val = this.anotherEntity.script.setterFunc(this.someParams)
console.log(val) // undefined
};
AnotherEntity.prototype.initialize= function() {
this.inicializedVariable = "someValue";
this.setTo = "initValue"
};
AnotherEntity.prototype.setterFunc= function(someParams) {
this.setTo = someParams;
return this.inicializedVariable;
};
AnotherEntity.prototype.update= function() {
console.log(this.setTo) // "initValue"
};
I tried bind context but it doesn’t work. Maybe I working with scripts not for the best way. Can you expaine how can i subscribe to changes in root from another entities? And important thing is i have to clone AnotherEntity
, and pass this.someParams
to current clone