Adding a Pause Function

Learn how to make certain types of games and use gameEditor.

Adding a Pause Function

Postby Zivouhr » Sun Feb 12, 2017 8:29 pm

Pause Mode / Adding a Pause Function / Pausing the Game, Unpausing / Suspend / Unsuspend
This is for any regular sized game that can be exported to PC, Mac and Linux.

pausingyourgame.ged
(4.49 KiB) Downloaded 120 times

Here is a Demo of how Pausing in your game works, select the View Actor to see PAUSE GAME example coding as listed below:

One solution to pause the game and resume it when you're ready by unpausing it, is to have:

1. View/keydown event/script editor: //the reason it's in view is because View is Always present.
2. For the key to enter in the box prompt, enter the letter:
p
//p for pause
Set it for any key pressed, and repeat off. Then go into the script editor.

3. In the script editor, type the following:

PauseGameOn(); //just like that, no need to enter the "game.ged" in the parentheses.


/////////
2. Next, create another key down event within your view, but this one will unpause the game:

View/keydown event/script editor: //the reason it's in view is because View is Always present.
2. For the key to enter in the box prompt, enter any numbers or letters of keys that are used in your game, whether up, down, left, right arrows, w,a,s,d, z,x.... And so on.

w a s d space
//Don't list p here, since the keydown event of p pauses the game when the gamer presses p on the keyboard.
Set it for any key pressed, and repeat off. Then go into the script editor.

3. In the script editor, type the following:

PauseGameOff(); //just like that, no need to enter the "game.ged" in the parentheses.

I'm about to test it myself.
Okay, it works as planned. 8) Just got it working in City of Rott: Streets of Rott.

As a beginner when I first starting learning Game Editor and the C language, I couldn't figure this out because I thought I had to use the same letter to unpause it, so then it was a series of keydown In Order of Buttons Pressed, which went on into infinity because there would be p, pp, ppp, pppp, ppppp, etc, since the player would press the p key countless times to pause and unpause the game. :mrgreen:

UPDATE: Feb 2017: Well, after trying out this code in my game which uses timers, I noticed the timers continue to count down even when in pause mode. I have hundreds of timed events going on. I'd have to manually enter EventDisabled commands and then EventEnabled commands to stop and restart the timers.
I wonder what Suspend mode is about.

Moderator's note: Originally posted in "Any way to unsuspend game?", but moved here because the question was resolved long ago, and this post would probably be more useful in the tutorials section.
Last edited by MrJolteon on Tue Feb 14, 2017 12:04 pm, edited 1 time in total.
Reason: Moved to a separate thread.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Adding a Pause Function

Postby ITomi » Wed Mar 01, 2017 8:35 am

Hello Zivouhr!

I've cribbed this idea from your code and completed with a variable to treat it with one button ("p"). So, add a variable to the actor in the Create event:
Code: Select all
gameisrunning=1;

and in the Key Up event of this actor:
Code: Select all
if (gameisrunning==1)
{
    PauseGameOn();
    gameisrunning=0;
}
else
{
    PauseGameOff();
    gameisrunning=1;
};

That's all! Simple and super! :)
User avatar
ITomi
 
Posts: 48
Joined: Sun Aug 21, 2016 1:56 pm
Location: Hungary
Score: 5 Give a positive score


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest