javascriptgame-developmentincisor

Trouble triggering an Incisor app event with more than one argument


I'm having trouble triggering an Incisor app event with more than one argument.

The console output:

spinResult Defined

spinResult Callback Added

5

undefined **(I expect this to read "7777")**

TestAppEvent: CODE VALIDATION FAILED: 'string=' expects the parameter 'string' to be type 'string', but type 'undefined' was provided

How do I get multiple arguments to be available in my callback function?

class ProjectMain
{
    init()
    {
        this.text = new TextAssembly();
        this.text.string = "Build It Once.";

        // Define the event here
        nc.defineAppEvent("spinResult");
        console.log("spinResult Defined");

        // Add the callback for the "spinResult" event
        nc.appEvents.spinResult.addCallback(this, "spinResultCallback");
        console.log("spinResult Callback Added");

        // Trigger the event with multiple arguments
        nc.appEvents.spinResult.trigger(5, "7777");
    }


    /**
    * spinResultCallback
    */
    spinResultCallback(resultData, message)
    {
        console.log(resultData);
        console.log(message); // this should read "7777"
        
        this.text.string = message;

    }
}

Solution

  • The issue you're facing is due to your trigger call, spinResult.trigger(). The trigger function only takes one argument. If you want to supply multiple parameters to the callback, you can send them in an array.

    For example: Here's what the trigger line should look like to rectify this issue:

    nc.appEvents.spinResult.trigger( [5, "7777"] ); // pass in the args as an array