How to get the return value from an event?

Hello there,

I am doing a get() and a set() function to comunicate two scripts.
Set works perfectly, the problem is with the get().
Here you can see my code:

//script_1
    this.stateButton.button.on('click', function (event) {
        var response = this.app.fire('script2:getPlayer');
        console.log(response);
    }, this);

//script_2
    app.on('script2:getPlayer', function () {
        return this.getPlayer();
    }, this);

    Script2.prototype.getPlayer = function () {
        return "Here is your player";
    };

Is there any way to achive this?

As far as I understand, the event doesn’t return any value.

Solved it this way:

//script_1
    this.stateButton.button.on('click', function (event) {
        var response;
        this.app.fire('script2:getPlayer', function(input) { response = input; });
        console.log(response);
    }, this);

//script_2
    app.on('script2:getPlayer', function (callback) {
        callback(this.getPlayer());
    }, this);

    Script2.prototype.getPlayer = function () {
        return "Here is your player";
    };
1 Like