Vice City: Multiplayer

Community Projects => SLC's Squirrel Plugin => Bug Reports => Topic started by: EK.IceFlake on June 13th, 2017, 09:33 AM

Title: [Bug] The IRC module still uses the old event API
Post by: EK.IceFlake on June 13th, 2017, 09:33 AM
I was trying out IRC and found out that it still uses the old Bind event API:
Code: [Select]
base.Bind(SqIrcEvent.Connect, this, this.OnConnected);
I would've expected something like this:
Code: [Select]
base.On.Connected.Connect(this.OnConnected, this);
Title: Re: [Bug] The IRC module still uses the old event API
Post by: . on June 13th, 2017, 01:05 PM
The signals and slots event system is bound to the main plugin. However, you can easily convert it to the new implementation via script:
Code: [Select]
class MyIRC extends SqIRC.Session
{
    On = null; // DO NOT MAKE THE TABLE HERE BECAUSE IT'LL BE SHARED AMONG ALL INSTANCES OF THIS CLASS!

    function constructor()
    {
        // Our table of signals
        this.On = {
            Connected = SqSignal();
        }
        // Construct the actual IRC session instance
        base.constructor();
        // Setup event forwarding so that the signal instance receives the event and forwards it to the connected functions/slots
        // Use the signal instance as the environment and call the emit function with it
        base.Bind(SqIrcEvent.Connect, this.On.Connected, SqSignal.Emit);
        // Now use the signals as you would normally use them
        this.On.Connected.Connect(function(event, origin, params) {
            print("some guy connected");
        });
    }
}

IRC <- MyIRC();
/*
IRC.On.Connected.Connect(function(event, origin, params) {
    print("some guy connected");
});
*/

It's just a matter of receiving from one end and forwarding to another.