Jump to content


Photo
- - - - -

Easy pause tutorial


  • Please log in to reply
5 replies to this topic

#1 Mauriits

Mauriits

    GMC Member

  • New Member
  • 3 posts

Posted 15 December 2010 - 06:46 PM

  • Title: Easy pause tutorial
  • Description: I'll show you how to make a script which pauses the game when you press a key (without saving files). An additional pause menu or anything else is very easy to build in.
  • GM Version: GM 7 / 8
  • Registered: No
  • File Type: .txt and .gmk
  • File Size: 28Kb
  • File Link: Pause_menu.txt, Pause_example.gmk

Follow the instructions and it should work perfectly.
This is what you have to do:

1. Create an object named obj_pausecontroller and place this piece of code in the Draw Event.

if room = rm_pause
{
draw_background(global.pausebg,0,0)
}

2. Place this script in the Step Event.

//////////////// Pause menu script ///////////////
//
// Made by Maurits van der Veen
// Simau Games © December 14, 2010
// 
// You're free to use this script, credits are appreciated =D
// 
// Need help? Please feel free to contact me: Mauriits@gmail.com.
//////////////////////////////////////////////////

room_persistent = 0 //only needed if your rooms are not presistent

if keyboard_check_pressed(ord("P"))
{// of course ord("P") can be replaced by the key you want
   if room != rm_pause
   {
   global.varprevroom = room;
   room_persistent = 1; //only needed if your rooms are not presistent
   global.pausebg = background_create_from_screen(0,0,argument0,argument1,0,0);
   room_goto(rm_pause);
   }
   else
   {
   background_delete(global.pausebg);
   global.pausebg = 0;
   room_goto(global.varprevroom);
   }
}


3. The depth of obj_pausecontroller has to be lower than all other objects (e.g. -2000000).

4. Create a new room and call it rm_pause, give it the same width and height as the views in the other rooms (if you aren't using views; use the same width and height as the other rooms).

5. Place the obj_pausecontroller in rm_pause and in every room where you want the player to be able to pause the game.

6. Replace argument0 with the width of rm_pause and argument1 with the height of rm_pause. (Line 19 of the script which has to be placed in the Step Event)

7. Everything you want, when the game is paused can be made in rm_pause.

8. It should work now, have fun with it!

If you have any questions, comments or if you need help, feel free to contact me (Mauriits@gmail.com) or post a reply.

Edited by Mauriits, 24 February 2012 - 06:26 PM.

  • 0

#2 szbeat

szbeat

    GMC Member

  • New Member
  • 18 posts

Posted 13 July 2011 - 12:16 PM

why not just show_message("pause")? the player won't be able do do anything before he click OK.
  • 0

#3 danst852004

danst852004

    GMC Member

  • New Member
  • 15 posts
  • Version:GM8

Posted 16 February 2012 - 05:55 PM

man there is alot error on it especial with assignment operator expected
  • 0

#4 DESTRUKTORRR

DESTRUKTORRR

    GMC Member

  • New Member
  • 3 posts
  • Version:GM8

Posted 20 February 2012 - 07:50 PM

The code itself seems solid enough, but I have to ask: do you know how taxing adding an extra room like this to the possibilities for every room might be on the system? Is it noticeable, or does it not make any significant difference?

I ask because I was thinking of a system that would work similarly, but would effectively stop all ai systems and player inputs (such as move keys and action keys like "attack" or "block," for example), and popping up a GUI.

Intuitively, this would be far simpler to program, but as far as efficiency goes, it can quite often be a better idea to go with the more complex version of a very similar thing.

Any information you might have would be awesome ^_^

Edited by DESTRUKTORRR, 21 February 2012 - 06:08 PM.

  • 1

#5 Mauriits

Mauriits

    GMC Member

  • New Member
  • 3 posts

Posted 24 February 2012 - 02:23 PM

The code itself seems solid enough, but I have to ask: do you know how taxing adding an extra room like this to the possibilities for every room might be on the system? Is it noticeable, or does it not make any significant difference?

I ask because I was thinking of a system that would work similarly, but would effectively stop all ai systems and player inputs (such as move keys and action keys like "attack" or "block," for example), and popping up a GUI.

Intuitively, this would be far simpler to program, but as far as efficiency goes, it can quite often be a better idea to go with the more complex version of a very similar thing.

Any information you might have would be awesome ^_^


It shouldn't give any problems for so far as I know. It relies on the 'persistent' function in game maker.
For example, you hold the left arrow to move left and then press P, it goes to the pause room, you still hold the left arrow key, then if you press P again, it doesn't detect the keyboard input from the keys you pressed before entering the game room, so you stop moving, unless you press the key again. If this is what you mean, and this is a problem for your game, then you might have to find another way to pause the game.

You might already know what the option 'presistent' does, but if you don't, this is what wikibooks.org says about persistent rooms in game maker:

Persistent rooms: By default, rooms will reset once they are left; platforms return to their original position, items will reappear, etc. A persistent room will remain in the exact way as it was left, and will only reset if the game restarts. If you need to reset a persistent room, it may be done manually via scripting. Persistent objects will not remain with the previous room; they will be transferred to the new room.


I hope this helped you :P

EDIT: Never mind, about the key input thing. It depends on how you've programmed the movement.

Edited by Mauriits, 24 February 2012 - 03:22 PM.

  • 0

#6 Pandaboy

Pandaboy

    GMC Member

  • GMC Member
  • 1164 posts
  • Version:GM:Studio

Posted 19 March 2012 - 05:15 AM

To be honest, this is far more advanced than a pausing script needs to be. There is really no need at all to change room.

All that is needed to pause the game is one object named obj_pause and a total of 6 lines of code spread out over 5 events.

Edit: Instead of posting the code here I'll simply create a topic :P

Edited by Pandaboy, 19 March 2012 - 05:55 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users