MZ Help with ".setHandler" and ".bind"

After watching Poryg's JavaScript guide on how to create custom Scenes and Windows, I managed to create a basic Scene that's supposed to allow you to swap between between parties. The Scene is called when selecting the "Change Scenario" command on the menu. So far, I managed to get the commands to show, allow the player to cancel out of the scene, and to scroll to different commands by using the code from the tutorials as a basis.

Unfortunately, I can't manage to allow for the player to actually select them and swap parties. I know I'm supposed to use .setHandler and .bind, but I just can't understand the tutorial for some reason. It's probably something small that I'm missing.

(Also, I can't seem to get commands to only show up if a particular switch is on, but that might be easier to fix)

Code (Without attempting to use .setHandler and .bind):

Spoiler
JavaScript:
function Scene_Tut () {
    this.initialize.apply (this, arguments);
}

Scene_Tut.prototype = Object.create(Scene_MenuBase.prototype);


Scene_Tut.prototype.initialize = function () {
    Scene_MenuBase.prototype.initialize.call(this);
}

Scene_Tut.prototype.create = function () {
    Scene_MenuBase.prototype.create.call(this);
    this._tutWindow = new Window_Tut ((Graphics.boxWidth - 600) / 2, 0);
    this._tutWindow.select(0);
    this._tutWindow.activate();
    this.addWindow(this._tutWindow);

}

function Window_Tut() {
    this.initialize.apply(this, arguments);
}

Window_Tut.prototype = Object.create(Window_Selectable.prototype);
Window_Tut.prototype.constructor = Window_Tut;

Window_Tut.prototype.initialize = function(x, y) {
    var width = this.windowWidth();
    var height = this.windowHeight();
    Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this.refresh();
    
};

Scene_Tut.prototype.update = function () {
    Scene_MenuBase.prototype.update.call(this);
    if (Input.isTriggered("cancel")) this.popScene();
}


Scene_Tut.prototype.command1 = function () {
        $gameParty.addActor(1);
        $gameParty.addActor(4);
        $gameParty.addActor(6);
        $gameParty.addActor(7);
        $gameParty.removeActor(2);
        $gameParty.removeActor(3);
        $gamePlayer.reserveTransfer(7, 6, 12, 0, 0);
}

Scene_Tut.prototype.command2 = function () {
        $gameParty.addActor(2);
        $gameParty.removeActor(1);
        $gameParty.removeActor(4);
        $gameParty.removeActor(6);
        $gameParty.removeActor(7);
        $gameParty.removeActor(3);
        $gamePlayer.reserveTransfer(9, 5, 12, 0, 0);
}

Scene_Tut.prototype.command3 = function () {
        $gameParty.addActor(3);
        $gameParty.removeActor(1);
        $gameParty.removeActor(4);
        $gameParty.removeActor(6);
        $gameParty.removeActor(7);
        $gameParty.removeActor(2);
        $gamePlayer.reserveTransfer(11, 7, 9, 0, 0);
}


Window_Tut.prototype = Object.create (Window_Command.prototype);
Window_Tut.prototype.constructor = Window_Tut;

Window_Tut.prototype.initialize = function (x, y) {
    Window_Command.prototype.initialize.call (this, x, y);
    this.opacity = 0;   
}


Window_Tut.prototype.makeCommandList = function() {
    if ($gameSwitches.value(57));
        this.addCommand ("Reid", "command1");
    if ($gameSwitches.value(58));
        this.addCommand ("Priscilla", "command2");
    if ($gameSwitches.value(59));
        this.addCommand ("Gale", "command3");
};

The Scene:

Spoiler
Screen Shot 2024-08-22 at 7.34.28 PM.png
Unfortunately, I can't manage to allow for the player to actually select them and swap parties. I know I'm supposed to use .setHandler and .bind, but I just can't understand the tutorial for some reason.
Are you doing this in conjunction with some proper JavaScript tutorials? This isn't piece-of-cake-simple stuff, so if you don't kind of get the context, it's much harder to just imitate things without understanding them (I ask only because your other problem is a pretty basic syntax error, below).

What you're talking about is how to connect the scene and its windows. If you look at any of the menus that already exist in the code, you'll see something like this:

Code:
Scene_Battle.prototype.createPartyCommandWindow = function() {
    const rect = this.partyCommandWindowRect();
    const commandWindow = new Window_PartyCommand(rect);
    commandWindow.setHandler("fight", this.commandFight.bind(this));
    commandWindow.setHandler("escape", this.commandEscape.bind(this));
    commandWindow.deselect();
    this.addWindow(commandWindow);
    this._partyCommandWindow = commandWindow;
};

That's the scene telling the window when you select the "fight" symbol it runs the scene's commandFight() method.

So the two things that work alongside that are the window creating the actual drawn list of commands that you see, and tying them to the symbols:
Code:
Window_PartyCommand.prototype.makeCommandList = function() {
    this.addCommand(TextManager.fight, "fight");
    this.addCommand(TextManager.escape, "escape", BattleManager.canEscape());
};

And then the command methods back in the scene that actually contain the code to be executed when that command/symbol is selected.

Code:
Scene_Battle.prototype.commandFight = function() {
    this.selectNextCommand();
};

(Also, I can't seem to get commands to only show up if a particular switch is on, but that might be easier to fix)
Your conditional syntax is wrong. Semicolons go at the end of a command, not after a conditional or loop or anything like that.

Code:
if (condition)
// One command is performed if the result of the condition is true
    x += 4;

So placing a semicolon at the end of the if line tells the code that's your one command that's executed if the condition is true, and the command is blank.

Code:
if (condition) /* You putting a semicolon here indicates the end of a command */ ;
Are you doing this in conjunction with some proper JavaScript tutorials? This isn't piece-of-cake-simple stuff, so if you don't kind of get the context, it's much harder to just imitate things without understanding them (I ask only because your other problem is a pretty basic syntax error, below).

No. I was frustrated and tried to brute force my way through the code because I thought it would eventually click. I think that it's best if I watch JavaScript tutorials starting from the basics and try to resolve the issue later when I have more knowledge. Thank you for solving the syntax issue.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-sethandler-and-bind.171334/