Adding New Commands to the Menu

Discussion in 'Learning Javascript' started by StrawberryWeisscream, May 6, 2016.

    Tags:
  1. StrawberryWeisscream

    StrawberryWeisscream Villager Member

    Messages:
    5
    Likes Received:
    1
    First Language:
    English
    How does one go about adding a new command to the menu?


    I've created a window that works in its own scene. Now I simply want to add a command to the menu screen that opens that scene. I have gotten this far on my own (by commenting out the command that adds the "Formation" option): 

     After that, I don't know what to do. I have a blank spot on the menu where the text for the option should be, but I have no idea how to add it. I can manage to trace it all the way back to the TextManager (though I have no clue what to do there) and I can't tell where it's pulling the .is[Instert Whatever Here]Enabled() from.
     
    #1
  2. Gatene

    Gatene Intermediate Scripter Member

    Messages:
    11
    Likes Received:
    1
    Location:
    South Carolina
    First Language:
    English
    Hey StrawberryWeisscream,


    I do not have a lot of time right this moment, but since you've already made the scene and a window to go with it, it shouldn't take too much more work.


    in the rpg_scenes.js file, find the function named


    Scene_Menu.prototype.createCommandWindow




    You are going to add a line similar to the ones that you see there:


    this._commandWindow.setHandler('YourMenuItemName',   this.YourFunctionThatCallsTheScene.bind(this));




    where YourMenuItemName will actually be the symbol(nickname) for the MenuItem you are creating. For example mine reads


    this._commandWindow.setHandler('gg', this.commandPersonal.bind(this));




    gg is the symbol (nickname) for my menu Item named "Give Gold" (You'll give meaning to the symbol in a few moments).


    YourFunctionThatCallsTheScene will be a memorable function name to the function that will start your new scene...like mine would be...


    this._commandWinhdow.setHandler('gg', this.commandPersonal.bind(this));


    find a spot below the createCommandWindow function, and create your new function that will call your Scene. Like this...


    Scene_Menu.prototype.yourFunctionThatCallsTheScene = function() {
        SceneManager.push(Your_Scene);
    };


    there are no quotes surrounding Your_Scene...you will get an error...


    So far, you've only told the game to start a scene when an option that doesn't exist in the menu is selected, clicked, or touched. To actually add the command to the menu, you will go to the rpg_windows.js file and search for the function named:


    Window_MenuCommand.prototype.addMainCommands


    Once you're there, you will see  something like this:


    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);
    }
    };


    Notice the this.addCommand function calls harbor the names of some of the menu items you currently see on your menu screen. Now, depending on where you want your new menu item, you will add a line like this:


    this.addCommand('yourMenuItem', 'yourMenuItemSymbol', enabled);


    I will explain after this example of what mine looks like:


    this.addCommand('Give Gold', 'gg', this.isFormationEnabled());


    'Give Gold'  is what I want displayed on the screen


    'gg'   is the symbol(nickname) of my menu item.


    this.isFormationEnabled() is a function called to see if Formation is Enabled, then this will be enabled too. My menu item allows me to give the gold of one character to another,     so I have to make sure there are at least two characters in my party... isFormationEnabled() is an easy way of doing that; but if you don't have any requirements of when


        the player can select your menu item, then simply leave it as enabled


    Now, since I want my Give Gold menu item between Item and Skill, I will place my addCommand() function between the two if statements there...


    Window_MenuCommand.prototype.addMainCommands = function() {
    var enabled = this.areMainCommandsEnabled();
    if (this.needsCommand('item')) {
    this.addCommand(TextManager.item, 'item', enabled);
    }

    this.addCommand('Give Gold', 'gg', this.isFormationEnabled());

    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);
    }
    };


    See how I did that? I didn't want to check to see if the menu needs the command, so I didn't need my own if statement and I just added the addCommand function with the parameters I already explained to you.


    Try this out, and if it doesn't work, let me know. I am out of time, I will check the post as I can throughout the day tomorrow at work...if I can't, it will be around 6pm EST before I get the chance.


    Gatene
     
    Last edited by a moderator: May 6, 2016
    #2
    WickedWolfy likes this.
  3. StrawberryWeisscream

    StrawberryWeisscream Villager Member

    Messages:
    5
    Likes Received:
    1
    First Language:
    English
    Hey, Gatene. This worked perfectly, thank you so much! The only thing that I noticed is the sound that plays when you select that option is doubled. It sounds like it plays twice within milliseconds of each other.


    - Thanks again!
     
    #3
  4. Gatene

    Gatene Intermediate Scripter Member

    Messages:
    11
    Likes Received:
    1
    Location:
    South Carolina
    First Language:
    English
    Hey,


      That's very odd. It shouldn't at all, because there are no sound commands in either of the places I had you edit code. It didn't for me. Well, you can always make another post, maybe someone out there has run across the same problem. or maybe, it is conflicting with a plug in you are running? Well, I hope you can get that taken care of.


    Gatene
     
    #4

Share This Page