MV Enable/Disable menu command based on a switch

I'd like to disable these 2 commands (taken from SRPG) if a certain switch is on.

Window_MenuCommand.prototype.addTurnEndCommand = function() {
this.addCommand(_textSrpgTurnEnd, 'turnEnd', true);
};

Window_MenuCommand.prototype.addAutoBattleCommand = function() {
this.addCommand(_textSrpgAutoBattle, 'autoBattle', true);
};

What kind of code would I need to implement it?
Code:
Window_MenuCommand.prototype.addTurnEndCommand = function() {
    if ($gameSwitches.value(XY))
        this.addCommand(_textSrpgTurnEnd, 'turnEnd', true);
};

Window_MenuCommand.prototype.addAutoBattleCommand = function() {
    if ($gameSwitches.value(XY))
        this.addCommand(_textSrpgAutoBattle, 'autoBattle', true);
};

Paste it in as a new Plugin below SRD's Plugin. Replace XY with your switch Id. Tell me if it works for you 🙂
Thank you for your help.
Unfortunately I get an error message.

error.png


EDIT: I don't know if this is what you were trying to do, but I would like the two commands to be greyed out, not totally removed.
Oh, to grey them out, use this:


Code:
Window_MenuCommand.prototype.addTurnEndCommand = function() {
    const enabled = $gameSwitches.value(XY);
    this.addCommand(_textSrpgTurnEnd, 'turnEnd', enabled);
};

Window_MenuCommand.prototype.addAutoBattleCommand = function() {
    const enabled = $gameSwitches.value(XY);
    this.addCommand(_textSrpgAutoBattle, 'autoBattle', enabled);
};

Okay, the error message says, that "_textSrpgTurnEnd" is not available. I don't know how to access this variable, so I can only recommend you to add this code snippet directly into the SRPG Plugin at the bottom; If this still does not work, you may think about overriding the code parts of SRPG with my Code snippet.
I'm still getting that "_textSrpgTurnEnd" is not defined (similar error).

EDIT:
this works (inserted directly in the code, not at the bottom)

Window_MenuCommand.prototype.addTurnEndCommand = function() {
const enabled = $gameSwitches.value(X);
this.addCommand(_textSrpgTurnEnd, 'turnEnd', enabled);
};


However it does the opposite... it's disabled if the switch X is OFF not ON... what should I change to make it do the opposite?
However it does the opposite... it's disabled if the switch X is OFF not ON... what should I change to make it do the opposite?
Oh, that's weird 0.o
Anyway, when you want the opposite behaviour, add a ! right before $gameSwitches.value(...), this will invert the variable "enabled".

Code:
const enabled = !$gameSwitches.value(X);
Thank you, this did it.

Original thread: https://forums.rpgmakerweb.com/threads/enable-disable-menu-command-based-on-a-switch.132395/