Adding Command To Menu and making it do something.

Discussion in 'Learning Javascript' started by ApocalympseGaming1992, Mar 25, 2018.

  1. ApocalympseGaming1992

    ApocalympseGaming1992 Warper Member

    Messages:
    3
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMMV
    I goto select my new command for bestiary, but it won't do anything except freeze game even though i have common event set
    to do something. Heres the code:


     
    #1
  2. Gamefall Team

    Gamefall Team Nebula Games Leader Veteran

    Messages:
    339
    Likes Received:
    424
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Well, your code shoud be polished a little:

    Code:
    (function(){
    // I suggest to insert all your methods inside the scope.
    
    var parameters = PluginManager.parameters('AG1992_D_D_Menu') //Set the object parameters inside a variable. This way is easier to use for all the parameters you want.
    var cmd = String(parameters['commandName']); //Call your parameters
    var transparent = 0;
    
    // No need of recalling the making of the command list, because you didn't make any edit to it.
    
    //When you want to edit and old method, remember to ALIAS it. In js when you write a method with //the same name of the old one, it will be REPLACED. So, making an alias preserves all the contents //of the other methods and assure compatibility with other possible plugins.
    
    var oldWindowMenuCommandAddMainCommands = Window_MenuCommand.prototype.addMainCommands
    Window_MenuCommand.prototype.addMainCommands = function() {
    oldWindowMenuCommandAddMainCommands.call(this)
    this.addCommand(cmd, 'bestiary');
    };
    
    //Same Here
    
    var oldCreateCommandWindow = Scene_Menu.prototype.createCommandWindow
    Scene_Menu.prototype.createCommandWindow = function() {
    oldCreateCommandWindow.call(this) //Calls the alias;
    this._commandWindow.setHandler('bestiary', this.commandBestiary.bind(this));
    };
    
    // I'm not really sure about this approach, but if you want to load a common event that is processed on map, we can try to do this
    Scene_Menu.prototype.commandBestiary = function(){
    $gameTemp.reserveCommonEvent(1);
    this.popScene() //Returns the map and processses the common event.
    };
    })();
    Remember that is really important to alias methods which have importants information.
     
    #2
    Aloe Guvner likes this.

Share This Page