15 October 2010

Customizing Menus - Part 2: Inside The Menu

In Part 1, we dealt with the basic menu structure and how the the commands are displayed and called. Part 2 expands on that and details how to execute the routines when the menu item is selected.

Scroll down to case @command_window.index (line 123 in RMXP and line 88 in RMVX). This is where the execution methods are defined, telling RPG Maker that when a menu item (the menu index if you recall) is selected, call the appropriate command.

This is processed in the definition update_command in RMXP and update_command_selection in RMVX. And this is where we need to change the code so that it does what it's supposed to do when the menu item is selected. The default structure is as follows:

Customizing Menus: Part 1 - Menu Structure

In this multi-part tutorial, I'll demonstrate how to customize the default menu (Scene_Menu) in both RMXP and RMVX. Scripting the menu is more frustrating than difficult because it doesn’t allow you to simply append new commands to the existing menu and only the menu items manually added into the menu script will appear. So we have to manually add them to form our basic menu. (That said, for the non-scripters, SojaBird's excellent New Menu Items script makes it easier to collate existing menu items and add new ones.)

For the purpose of this tutorial, however, we'll be modifying the existing Scene_Menu to add an Extra Stats window. First thing's first, let's explore how the menu structure is set up.

The basic structure for the menu in each RPG Maker is the same, but RMVX also has the additional option of multi-columns in the menu, which we'll cover later.


Initialize The Menu Index

The first section sets the command cursor's initial position.

def initialize(menu_index = 0)
   @menu_index = menu_index
end

By default, it's set to 0, the first item on the menu list. The number increases by one for every menu item below the first command, which means that every time the cursor is moved down to the next command it increases by one. Conversely, if the cursor is moved up one command the index decreases by one. So, if you were to set the menu_index to 4, when you open the status menu the cursor would default to "Save" every time you open it.
Related Posts with Thumbnails
Template Design "Perfect World" by SkinCorner