Disable custom menu option based on switch value

Discussion in 'Javascript/Plugin Support' started by Jimminybob, Mar 29, 2018.

  1. Jimminybob

    Jimminybob Villager Member

    Messages:
    24
    Likes Received:
    7
    First Language:
    English
    Primarily Uses:
    RMMV
    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
     
    #1
  2. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,505
    Likes Received:
    953
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    I assume you're using some type of Window_Command ? If so, take inspiration from the default menu, specifically this function:
    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));
       }
    };
    
     
    #2
  3. Jimminybob

    Jimminybob Villager Member

    Messages:
    24
    Likes Received:
    7
    First Language:
    English
    Primarily Uses:
    RMMV
    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.
     
    #3

Share This Page