15 October 2010

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.


Main Processing

This is the part that sets up the menu and processes the user's actions when the menu items are selected. These are defined in a method (main in RMXP and create_command_window in RMVX).

Each menu item is stored in a container variable, by default set to s followed by an incremental number, which sets the order in which the menu items appear in the list. To exemplify, the basic structure of the command list would be:

s1 = "Items"
s2 = "Skills"
s3 = "Equipment"
s4 = "Status"
s5 = "Save"
s6 = "End Game"

These can be set (to the right of the equals sign) as a string, i.e. text enclosed in quotes. If you don't include the quotes, RPG Maker will throw up an "uninitialized constant" error.

They can also be set to a fixed number (fixnum) or other variable, which in turn must be converted into a string using .to_string after the number. Otherwise, a "cannot convert Fixnum into String" error will occur.

The following will display 123 (converted to a string) as the first menu item:

s1 = 123.to_s

You can also assign system words, as defined in the Database (under System in RMXP and Terms in RMVX), called "words" (RMXP) or "terms" (RMVX) in the script. RMVX by default contains a separate module, Vocab, where all terms can be redefined.

RMXP

def main
   s1 = $data_system.words.item
   s2 = $data_system.words.skill
   s3 = $data_system.words.equip
   s4 = "Status"
   s5 = "Save"
   s6 = "End Game"
end

RMVX

def create_command_window
   s1 = Vocab::item
   s2 = Vocab::skill
   s3 = Vocab::equip
   s4 = Vocab::status
   s5 = Vocab::save
   s6 = Vocab::game_end
end

Immediately following the container variables is the command to call a new Command Window, containing all of the menu items defined in this list (s1 through s6).

@command_window = Window_Command.new(width, [commands])

This line will display a new Command Window: width is the actual width of the Command Window (by default set to 160) and the commands are all of the container variables separated by commas (i.e. s1 through s6).

RMVX has an additional option for multiple columns, placed right after [commands].

RMXP

@command_window = Window_Command.new(160,
   [s1, s2, s3, s4, s5, s6])

RMVX

@command_window = Window_Command.new(160,
   [s1, s2, s3, s4, s5, s6], 2)

Note: This includes the extra column option, in this case set to 2. While it's not mandatory, bear in mind that the text will be crunched to fit the window width, which should be changed also accordingly.


So to add an item to the list, create another s variable, then add it to the commands list, thus:

s1 = "Items"
s2 = "Skills"
s3 = "Equipment"
s4 = "Status"
s5 = "Save"
s6 = "Extra Stats"
s7 = "End Game"
@command_window = Window_Command.new(160,
   [s1, s2, s3, s4, s5, s6, s7])

You can add items to the list or remove them depending on your game's needs, but you'll need to change the commands accordingly. The next step is to add a routine to tell RPG Maker what to do when our added "Extra Stats" is clicked. This will be detailed in Part 2.

0 Comments So Far:

Post a Comment

Related Posts with Thumbnails
Template Design "Perfect World" by SkinCorner