Simplifying to Configure This Script

I have this particular question about simplifying scripts. Take this script as an example:

class Window_TitleCommand < Window_Command #-------------------------------------------------------------------------- # * Create Command List #-------------------------------------------------------------------------- def make_command_list add_command(Vocab::new_game, :new_game) add_command(Vocab::continue, :continue, continue_enabled) add_command("Book", :book) add_command(Vocab::shutdown, :shutdown) endendclass Scene_Title < Scene_Base #-------------------------------------------------------------------------- # * Create Command Window #-------------------------------------------------------------------------- def create_command_window @command_window = Window_TitleCommand.new @command_window.set_handler🙂new_game, method🙂command_new_game)) @command_window.set_handler🙂continue, method🙂command_continue)) @command_window.set_handler🙂book, method🙂command_book)) @command_window.set_handler🙂shutdown, method🙂command_shutdown)) end def command_book SceneManager.call(Scene_GameBook) end endAs you can see we can call it a poor scripter's way of making a title screen command of his / her own. I want to ask, say I want the one who will use the script to add more commands, how can I simplify the script so I don't have to out the handler in the scene, the command and the method that would execute the command everytime? 

I want it to be simplified into something I can configure the command, the key symbol and the method that would execute it.

Thanks!
Example

Code:
# Add as neededCommands = {  "Test"  => :method_test,  "Test2" => :method_test2  # etc}# Don't need to touch anymoreclass Window_TitleCommand < Window_Command    def make_command_list    add_command(Vocab::new_game, :new_game)    add_command(Vocab::continue, :continue, continue_enabled)    add_command(Vocab::shutdown, :shutdown)        Commands.each do |name, method_sym|      add_command(name, method_sym)    end  endend
This is what I do in my own scripts even if it's for personal use.
Thanks a lot. I have another question...say, on this script, my main problem is the method. Say, all those titles call a certain scene, is there a way to simplify it so you do not have to make methods for each scenes? Like you indicate what scene you're calling instead of the method?

Commands = { "Test" => :method_test, "Test2" => :method_test2 # etc}this for example is well and good, but don't you have to create a command on Scene_Title? Say, I want to add different scenes on each of the added commands, is there a way to call them via SceneManager? Something like:

Name -> symbol -> command call

If this doesn't make sense, I can give you more details. I just want it to be simplified well and have full control of what's happening.

This is where the problem lies:

module TitleScreen Title_Commands = { "New Game" => :new_game, "Continue" => :continue, "Book" => :book, "Shutdown" => :shutdown, } Scene_Handler = { "New Game" => SceneManager.call(Scene_Gameover) }endclass Window_TitleCommand < Window_Command def make_command_list TitleScreen.each do |name, method_sym| add_command(name, method_sym) end endendHow can I eliminate the problem over the commands? Like if I add items on my title screen, I have to make separate commands for them, when all I have to do is to call different scenes on them....
You will need to think about how the whole handle thing is designed.


RPG Maker provides a very simple form of event handling for scenes. In other programming API's, they might call it an "onkeypress" event.


When you press OK, the window looks up whether there are any handles assigned to the OK keypress, and if so, it will execute the method assigned to those handles.


In the command window's case, when you press the OK button, it will look at the handle associated with the command that you selected and then execute the method associated to that handle 🙂continue, :new_game, etc)


This means that you shouldn't simply assign a piece of code to a symbol, because ruby will simply execute it when it sees it, which is not what you want.


Two simple things that you can do


1. Explicitly define the method, and then assign the method to execute in your configuration, or


2. Create a proc with the logic that you want to execute, and assign it to the handle.


If the only thing you're going to be doing with these methods is calling a scene, you can simply assign the scene name to call and then pass that to a method as arguments. RPG Maker has already been set up to support extra event argument.


I don't really agree with this design if you were strictly conforming to MVC, but it's a lot easier to make your windows re-usable rather than having the scene handle all input handling and then determining what to do with it depending on which window is active, etc.
I am thinking of using arrays, but there's another block of problem in my head. By explicitly defining the method and execute the config, did you mean I have to create a single command method and call different command execution for it?
# Example only. I would not structure the config like this myself
# Assign names to each handle


Commands = {


"Test" => :method_test,


"Test2" => :method_test2


# etc


}


# Assign method to call to each handle


Handles = {


:method_test => :test_method


}


class Scene_Title


def create_command_window


@command_window = Window_TitleCommand.new


@command_window.set_handler🙂new_game, method🙂command_new_game))


@command_window.set_handler🙂continue, method🙂command_continue))


@command_window.set_handler🙂book, method🙂command_book))


@command_window.set_handler🙂shutdown, method🙂command_shutdown))


# no need to touch


Handles.each do |handle, method_name|


@command_window.set_handle(handle, method(method_name))


end


end


# define what the method does. Can be changed by other scripts, etc.


# Does not affect the handle or the command name or anything else


def test_method


SceneManager.call(Scene_Test)


end


end
MAJOR EDIT: My friend is doing this script for me, however, I thank all your answers and will think of it as a lesson.

Original thread: https://forums.rpgmakerweb.com/threads/simplifying-to-configure-this-script.36576/