Disable custom menu option based on switch value

Hi,

I've created a custom menu for my game and one of the options on there is to view a map of the current location. However the map itself isn't available, story wise, until the player examines a certain location and finds it. Based on that I'd like to have the menu option disabled until the located is examined and a switch turned on.

I've tried to do this in some experiments but I couldn't get it right, so I was hoping someone could tell me how to achieve this.

Thanks
I assume you're using some type of Window_Command ? If so, take inspiration from the default menu, specifically this function:
Spoiler
Code:
Window_MenuCommand.prototype.addMainCommands = function() {
   var enabled = this.areMainCommandsEnabled();
   if (this.needsCommand('item')) {
      this.addCommand(TextManager.item, 'item', enabled);
   }
   if (this.needsCommand('skill')) {
      this.addCommand(TextManager.skill, 'skill', enabled);
   }
   if (this.needsCommand('equip')) {
      this.addCommand(TextManager.equip, 'equip', enabled);
   }
   if (this.needsCommand('status')) {
      this.addCommand(TextManager.status, 'status', enabled);
   }
};

Something like this:
Code:
//Switch #1 is whether the map command is added to the command window
//Switch #2 is whether the map command is enabled or not
MyWindow.prototype.addMapCommand = function() {
   if ($gameSwitches.value(1)) {
      this.addCommand("View the Map", 'map', $gameSwitches.value(2));
   }
};
Thanks very much, that worked perfectly. I had tried to get the switch value in a different way but that didn't work.

Thanks again.

Original thread: https://forums.rpgmakerweb.com/threads/disable-custom-menu-option-based-on-switch-value.93339/