[SOLVED] Call a function on event declare with argument

Hi guys!!

Would it be possible to call a function passing an argument internally when declaring an event listener?

Something like this:

this.app.on('setModeGame:VR', this._setModeGame, 'VR', this);

NameScript.prototype._setModeGame = function(value, scope) {
 console.log(value); // this returns undefined... I want to get 'VR' string.
};

In this case value returns undefined… The only way that has worked is passing the argument on the fire event but I would like to be able to pass the value internally.

Thanks!!!

Hi @chewuaka,

If I understand correctly, you can do this:

this.app.on('setModeGame:VR', function(){
   // you can pass any local variable or script property
   this._setModeGame(this.entity, scope);
}, this);

Correct! This works too but it seems a little ugly… but I’m afraid it’s the only way?

Well, you can make it prettier by using an arrow function:

this.app.on('setModeGame:VR', () => this._setModeGame(this.entity, scope));
2 Likes

Yeaaah!!!

@Leonidas always saving the world!!! :heart_eyes: Thanks!!!

1 Like