Pass values through events

I am basically trying to get a value of script into another one. Currently, events without values look like this for me.

Script 1

Swapper.prototype.initialize = function() {

    this.app.on("get:select", this.onGetSelect, this);
    
};

Swapper.prototype.onGetSelect = function(dt) {
    alert("event found");
};

Script 2

this.app.fire("get:select");

However, if I want to alert a value from script 2 in script 1, how would I do it?

Hi @XKRS-GT,

You can pass arguments in your fire call like this:

this.app.fire("get:select", true, 12, 'start');

Now on your on event handler callback, the arguments will be automatically made available:

Swapper.prototype.onGetSelect = function(switch, amount, state) {
    console.log(switch, amount, state);
    // prints true, 12, "start"
};
2 Likes

I think this should work. Really helped.

1 Like