Gw Temp

Menu

Tutorial - 'Basic Menu System' by Typer85

An item about RPGMaker 2000 posted on

Blurb

Creating a very basic but expandable menu system in Game maker!

Body

Table of Contents:
I. Introduction
II. What You Need
III. Tutorial Part I
IV. Tutorial Part II
-----
I.
This tutorial is written to help new Game Maker (GM) users make a very basic Menu System. Might not be the very best, but will help new users.

Before I start, I would like to thank GZ_Soft from the GM Forum for helping get a hands on start with GM. It is because of him that this tutorial exists.
-----
II.
Before you go ahead and read the rest of this, you must make sure you have the following. This tutorial completley ignores the basics, such as Adding Sprites and Adding Objects.
a. Game Maker
b. Understanding of Game Maker Lanaguage (GML)
c. A game already underway with Objects and Sprites.
-----
III.
a.
Start up GM and load up your game. Go to your Main Character Object and double click on it.

At this point, you should have also created a new room called 'Menu_Room', or the code will not work.

b.
Create a new Create event and add Execute a Piece of Code for its action. Once in the code editor, add the following code:

//Start Code
global.return_player=false;
//End Code

What this does is set the variable to false or off. Read on to find out why.

c.
Create a new Room End event and add Execute a Piece of Code for its action. Once in the code editor, add the following code:

//Start Code
global.return_x=x;
global.return_y=y;
//End Code

This is a very simple code that stores the player's current X and Y coordinates on the current room once the room ends. The X position is stored in 'global.return_x' and the Y position is stored in global.return_y'.

d.
Create a new Room Start event and add Execute a Piece of Code for its action. Once in the code editor, add the following code:

//Start Code
if (global.return_player=true)
{
x=global.return_x;
y=global.return_y;
global.return_player=false;
}
//End Code

What this does is very simple. Once the room starts up, it picks up the X and Y coordinates from the variables that we defined before, and returns the player to his postion before going the Menu Screen.

e.
Create a new Press M Key event and add Execute a Piece of Code for its action. Once in the code editor, add the following code:

//Start Code
global.current_room=room;
global.return_player=true;
room_goto(Menu_Room);
//End Code

This does several things. When the user presses M, the current room that he is in is saved in the variable 'global.current_room'. It also saves his current X and Y coordinate (see the above section), and advances him to the room with the Menu on it.

Now your probably wondering, what the hell is going on and what is the point for all this. This is just the start of the Menu System. So far all we did was define what will happen when the user goes to the actual Menu, which is: Save current Room, Save Current Position, Advance to Menu.
----
IV.
Now to the actual Menu. You do not need to have any fancy backgrounds or anything for this Tutroial. You could do all that later, as soon as you have a basic understanding on how to do this.

a.
Go the room you created before named 'Menu_Room'. Go to Settings --> Creation Code and put the following code in:

//Start Code
global.menu=true;
//End Code

What this does is let the program know that once this map is created, the variable 'global.menu' is turned on. You really do not need this variable right now for our example, but later on you might, such as for pausing the game if the menu is open, etc...

b.
Create a new Object and call it 'obj_exit_menu'. Add a Press M Button event and add Execute a Piece of Code for its action. Add the following code:

//Start Code
global.menu=false;
room_goto(global.current_room);
//End Code

This does 2 important things. First it turns off the variable 'global.menu' when exiting the Menu. Remember the variable 'global.current_room' we defined above. Well it comes in handy here. When the user exits the Menu, he goes to whatever room he was in before thanks to this variable.

Thanks to all the variables we defined above as well, the player will be returned to the same exact X and Y coordinate he was in on that room.
-----
This is basically it. You now have the option to add nice pictures and backgrounds to the menu. Even create a custom cursor and so forth.

This is a very simple Tutorial and I know its very primitive. Look forward to my Second Part where I explain the use of Strings and such to create an even more advanced Menu.

Thanks for Reading,