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:

RMXP

Note: Tthis section has been minimised by precluding the remarks and the sound commands.


case @command_window.index
when 0 # item
   $scene = Scene_Item.new
when 1 # skill
   @command_window.active = false
   @status_window.active = true
   @status_window.index = 0
when 2 # equipment
   @command_window.active = false
   @status_window.active = true
   @status_window.index = 0
when 3 # status
   @command_window.active = false
   @status_window.active = true
   @status_window.index = 0
when 4 # save
   if $game_system.save_disabled
      return
   end
   $scene = Scene_Save.new
when 5 # end game
   $scene = Scene_End.new
end

RMVX

case @command_window.index
when 0 # Item
   $scene = Scene_Item.new
when 1,2,3 # Skill, equipment, status
   start_actor_selection
when 4 # Save
   $scene = Scene_File.new(true, false, false)
when 5 # End Game
   $scene = Scene_End.new
end

At this point, you can probably figure out how things work and how to insert the command execution on your own, but let me explain further, as this can be somewhat confusing.

As you may recall from Part 1, each item in the list is assigned an incremental number to show the order in which they should be listed. The first menu item starts at 0 - not 1 as you would think because the container variable is s1 and not s0 - and is counted up from that number. So, 0 is "Item", 1 is "Skill", etc. For each menu item, a corresponding when x is required, followed by the code executing the appropriate command. RPG Maker will search through and find the index value and execute the commands under the corresponding when.

So, looking at the above code, when the first item ("Items") is selected is the index is set to 0. Under its when is:

$scene = Scene_Item.new

This is the same for both RPG Makers. However, in RMVX the code has been cleaned up and you'll notice that items 1, 2 and 3 are grouped together, since they execute the same command when selected and you'll notice when comparing the two that the "window activity" has also been truncated in RMVX in the start_actor_selection.

We're now ready to add the command to display the Extra Stats window. If you remember, we inserted the item list in between "Save" and "End Game", so the first thing to do is change when 5 to when 6. (Otherwise, when you select "Extra Stats" the End Game menu will still appear.)

So between the two when sections (right after when 4), inserting the following:

when 5 # extra stats
   $scene = Scene_ExtraStats.new

will call the Extra Stats window onscreen.

If done correctly, you should have a working menu with the addition of a window displaying the extra stats. (Note: If you use my Extra Stats script, you won't need to change the menu, as it's all ready to go.)

In Part 3 (which I'll add in a few days' time), we'll continue with some of the other functions of the command menu. Until then, happy menu creating!

1 Comments So Far:

Companion Wulf said...

thanks!

Post a Comment

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