How to make Menu

Started by Draco, Mon 28/11/2011 17:55:51

Previous topic - Next topic

Draco

As you can see, my biggest problem is making menu. Can you tell me any code to make menu? I need 4 things:
1.Start a new game
2.Load game
3.Show intro text (I planned this like another room, but if you have better idea just tell me)
4.Exit
So, could you tell me?

NickyNyce

#1
Start game is easy, just keep in mind that where your character starts from is where your game starts from. If you have a start menu, you could start your character in that room but put his starting coordinates to -20, -20 ...this will put your character off the screen. You can make a hotspot for the new game, load and quit buttons that I'm assuming you are going to draw, otherwise make a GUI to do this. When the player chooses new game, call character.changeroom to the desired location.

When you want to stop the game, or quit...you could call...
QuitGame(0);
or QuitGame(1);

If you use QuitGame(0); it will quit automatically...if you use QuitGame(1); it will ask you, are you sure you want to quit?

This is if you are using the default template

When you load your game... if your using the default template ...use gRestoreGame.visible=true;

As for the text...you could still have your character say what you wish because he will be off screen, but the words will appear on the screen if you use character.SayAt

Hope this helps

Ghost

#2
To make things even easier, put your game menu into a room and set it's "Show Player Character" setting to false- that way you never see the main character.

Then create a GUI; call it gMainMenu.

On that GUI, you place four buttons. Name them btnNewGame, bnLoadGame, btnIntro, btnExit. There is no need to call them exactly that, it's just a habit I've developed.

Create event handlers for all four buttons (you know how to do that, right?)

* For "New Game", all you need to do is to move the player to the room where the game starts, so:
        player.ChangeRoom(RoomNumber);
   will do.
* For "Load Game", this depends if you are using the default template or have written your own load GUI. What you want to do is make that load GUI visible.
* For "Intro Text", just as you said, a separate room is a good idea- just move the player there AND make sure you also have the "Show Player Character" set to false. Then, just as Nick said, you can simply make the character "speak" the intro.
* For "Quit", yes, call QuitGame.

Now to make sure that the menu disappears when the player leaves the room, create a room event for "Player leaves Room". Enter the following line:
  gMainMenu.Visible = false;

Please note that this is from the top of my head, and maybe capitalisation is a bit wrong. But it should get you started.

Dhelayan

Thanks for explaining it in such detail! Really helped me a lot, as i'm just starting out with AGS :D
Now i got one problem tho. When i add the "gRestoreGame.Visible=true" event to the LoadGame button, it doesn't show up in the Menu screen, but it shows up immediatly when my char changes from the Main menu to the first room of the game..

Ghost

It could be that the main menu GUI remains visible OVER your restore game GUI (The fact that the restore game GUI is visible in the next room, when there is no Main Menu, suggests this).

Try to either make a smaller main menu, move it to a place where it will not overlap with the restore GUI, or, best, make it invisible before you make the restore GUI visible.

Dhelayan

Okay, so right now, the script looks like this:

function btnLoadGame_OnClick(GUIControl *control, MouseButton button)
{
gMainMenu.Visible=false;
gRestoreGame.Visible=true;
}

Of course, this way, the Main Menu does not appear again when i click on Cancel in the LoadGame GUI, and it's not really centered

Ghost

#6
Quote from: Dhelayan on Tue 29/11/2011 19:07:36
Okay, so right now, the script looks like this:

function btnLoadGame_OnClick(GUIControl *control, MouseButton button)
{
gMainMenu.Visible=false;
gRestoreGame.Visible=true;
}

Of course, this way, the Main Menu does not appear again when i click on Cancel in the LoadGame GUI, and it's not really centered

GUI.Centre() - centers a GUI on screen

In the restore GUIs event handler, just add

if (player.Room == ROOMNUMBER)
 gMainMenu.Visible = true;

This makes the main menu visible again when cancelling, but only in room ROOMNUMBER (you don't want to make it come up elsewhere ;) )

Both functions are very basic, and you will probably use them often. The manual has all functions you can apply to a GUI listen, too- it's a good read because GUIs really are an elementary part of almost any game.

---
edit: I think this is the first time I beat khris!

Khris

1.
Code: ags
function btnLoadGame_OnClick(GUIControl *control, MouseButton button)
{
  gMainMenu.Visible=false;

  gRestoreGame.Centre();         // the very first GUI command in the manual's list...
  gRestoreGame.Visible=true;
}


2.
In the cancel button's function, turn gMainMenu.Visible back to true. If you can't find it, open the restore GUI and double-click the Cancel button.

3.
Try to put at least some minimal effort into solving stuff like this on your own.

Draco

There are two buttons which doesn't work:
1.Start
2.Intro text
When I click on them I just get to the menu again.And If I use the load button and cancel it I'm on the page with intro text. I used This code:

function Button1_OnClick(GUIControl *control, MouseButton button)
{
player.ChangeRoom(2);
}

function Button2_OnClick(GUIControl *control, MouseButton button)
{
  gMainMenu.Visible=false;

  gRestoreGame.Centre();         
  gRestoreGame.Visible=true;
}

function Button3_OnClick(GUIControl *control, MouseButton button)
{
player.ChangeRoom(3);
}

function Button4_OnClick(GUIControl *control, MouseButton button)
{
QuitGame(1);
}


Rooms are:
1.room with menu
2.Starting place
3.Intro text


SMF spam blocked by CleanTalk