Game Development Reference
In-Depth Information
The comment box above the method is pretty good about explaining what parameter goes where. For most
options, you'll only be using the first two parameters. The command name is defined in the Vocab module (the
specific terms list starts on line 113). The symbol used in the
add_command
method is the handle defined within
set_handler
. The Continue option also uses the third parameter, which determines whether or not you can select it
from the menu. (When the player has no save files for the game, Continue will be grayed out.)
.push
is a method from
Ruby's Array class. As the method name implies,
.push
sends an object to the end of an array (the array, in this case,
being
@list
). Going back to
Window_GameoverCommand
, we can see the format of an
add_command
object that accepts
two parameters.
add_command(Vocab::shutdown, :shutdown)
■
to summarize the menu logic:
add_command
adds options to menus while
set_handler
gives those options
their functionality. as proven already, you need both to create a new menu option.
Note
The Title screen option is called in the form
to_title
. So, you would write the following in
make_command_list
to
add that command to
Window_GameoverCommand
.
add_command(Vocab::to_title, :to_title)
Place that one in between the two existent
add_command
expressions. Then, you would add the following line to
create_command_window
in
Scene_Gameover
, so that the option actually does something when the player interacts
with it. I placed it between the Continue and Exit Game commands.
@command_window.set_handler(:to_title, method(:command_to_title))
Last, you need to add the
command_to_title
method itself, or the game will return an error telling you that the
method is undefined.
■
i named the method
command_to_title
, to keep with the naming conventions used for this command in
rMVxa. as it turns out, there
is
a preexisting method of the same name. More on that below.
Note
As said in the note above, there's a preexisting method called
command_to_title
. In fact, running a search for
the method will return only four results, two of them being the instances of the term we added for this exercise. The
second result (line 48 of
Scene_End
) contains what we're looking for. Here's the method:
def command_to_title
close_command_window
fadeout_all
SceneManager.goto(Scene_Title)
end
Copy-paste that method to the
Scene_Gameover
class you have tweaked, and we're done! Play-test your game and
cause a game over. If you have done everything correctly, the screen should look like Figure
14-5
.