GameMaker: Studio

GameMaker: Studio

View Stats:
Morosaurus Oct 3, 2012 @ 4:07pm
Pausing?
Is there any way to pause the game without using GML and if it does have to have GML could someone make it simple and explain what each thing does?
< >
Showing 1-15 of 20 comments
terraformer299 Oct 3, 2012 @ 4:41pm 
The method I know of, and use, can only be done in GML due to some functions that are used.
:/

>Create an object, and name it objPause
>Select "Add Event", select "Key Press", and then select the button you want to pause with
>Go to the control tab and add an action of "Code Execute"
>Insert this code(lines with // before text indicates a comment explaining what the code does)

{
draw_set_color(c_red) //Sets the color that the text will be drawn as to red
draw_set_halign(fa_center) //Sets the text to draw horizontally centred
draw_text(room_width/2,room_height/2,"Game Paused") //Draw's the text in the centre of the room
screen_refresh(); //Refreshes the screen so the text is drawn
io_clear(); //Clears the keyboard's state
keyboard_wait(); //Waits for the users to take pause off
}

>Save the object and close.
>Test.

:)
Hopefully it works how you want it to.

Good luck with your game!
Morosaurus Oct 3, 2012 @ 4:53pm 
Thanks, but I found out GameMaker: Studio now has resource limitations unless you buy the standard edition and I can't make a full fledged game :/
terraformer299 Oct 3, 2012 @ 5:00pm 
Yes, the free version does have some limitations.
:/
Sorry about that.

They've put this limitation on so, as most companies do, you'll be getting somewhere, and then suddenly you can't go any further.
:|
It does get frustrating.
Jester Helquin Oct 3, 2012 @ 7:59pm 
download GM 8.1 lite there isnt a limit
MicahDS Oct 3, 2012 @ 9:25pm 
GML is really the only option I know of. I strongly suggest that you learn GML; you will be happy if you do.

The method that terraformer299 pointed out is pretty good, except it's limited to pausing absolutely everything or pausing absolutely nothing. There is no inbetween, and you may not want to pause everything all the time. For example, you might want a game that allows the player to bring up an inventory that can be controlled while everything else is paused. In most cases you'd want enemies and whatnot to be paused while you are free to equip/unequip items and such. This sort of "pausing" is also useful for RPGs and other games that use text boxes and have cutscenes and such. In those cases, you will want to freeze most objects and events except for certain character movements and dialogue.

HOW TO DO IT:
To do this method of pausing, you would need to create a variable that keeps track of the paused status (you could also have different levels of paused status, which can be very useful).
Before executing movement and most any code, you would simply have it check if the game is paused by checking the value of the pause variable, and have it exit the script if the game is paused.

The problem with this is that you need to build your game from the ground up with this in mind, or you will likely have much difficulty reprogramming a project to make use of this method, and you may not be able to use a lot of the motion drag and drops. Learning to program step-by-step movement is practically required for this method, which means much more work.

This is mildly advanced stuff, but it really pays off to push yourself to learn new, better methods.

------------------------------------------------------------------------------
Code example for a GML script:
------------------------------------------------------------------------------

// any code placed here will execute, regardless of the paused value

if pause = true{
exit;
}

// any code placed here will only execute if paused = false (if the game is not paused)

------------------------------------------------------------------------------

You may also use numbers (as opposed to just true/false) if you want to have various levels of paused status for more control. Meaning "0" is not paused at all, "1" is inventory only, and "2" is cutscene which does not allow you to even enter into your inventory (for lack of a better example).
MicahDS Oct 3, 2012 @ 9:31pm 
That said, an extremely simple way is to bring up a pop up message that says "paused, press ok when ready to resume", or something along those lines. Everything will pause until you click the okay button. It's not a very professional way to do it, but that is for sure the most simple way I know of.

Best of luck to you!
Morosaurus Oct 4, 2012 @ 1:11pm 
Oh yeah I knew of that way, but like you said it's just pretty unproffesional
Fable Oct 4, 2012 @ 2:03pm 
FrozenFire's first method is the way I'd go. It takes more effort, since you have to add it to every object that updates in regular intervals to make sure nothing is updating while the others aren't, but it's a worthy method that works really well.

EDIT: It also allows exacting control over the pause, and unlike terraformer's method, allows a working pause screen, since input doesn't resume the game.

EDIT2: You might be able to do it in D&D, just "Check if variable pause is set to true", "Start a block of code" (or whatever it's called), "Exit event", "End code block", rest of code.

Don't quote me on that. I don't use D&D, really.
Last edited by Fable; Oct 4, 2012 @ 2:09pm
Fish! Oct 4, 2012 @ 8:33pm 
problem with terraformer299 code is that in GameMaker:Studio the screen_redraw(); and keyboard_wait(); functions are now considered obsolete and refuses to compile.
Fish! Oct 5, 2012 @ 11:34pm 
Found a way... I think. Still need to put more testing in this idea. But make your rooms persistant, create a room for a pause screen/menu and then create a object for pause control.

Create event for button to signal pause.
Check current room, if not Pause room
record current room
Change to pause room
Else
Change to "previous" room. Can be trick as it's not actually the previous room drag and drop option.
Fable Oct 5, 2012 @ 11:51pm 
It would be so much easier (and more reliable) to just add FrozenFire's code to the top of every object's Step event.
Last edited by Fable; Oct 5, 2012 @ 11:51pm
Fish! Oct 6, 2012 @ 7:19am 
Yeah, at the moment I'm just hacking around, but I see one thing up with FrozenFire's method (not that it's wrong, it does actually work. I tried it :-) But based off the tutorials, it doesn't go into any detail about parent objects. So when you create an enemy and add an event handle for pause that works. But then you create another enemy and have to add another event. So I forgot to re-program one enemy and it blew me up while on pause X-D Also with the parent thing, works until you want one enemy to do something a little different and over-write the event.
Also not to say mine is any more right, but mine contains at least some of the basic logic for handling a title screen, that you can escape to, and then resume from. Or at least I think so :-)
Fish! Oct 6, 2012 @ 7:51am 
Also not to be any more of a smart ass, the original question was how to without script.
Still probably would look at doing FrozenFires suggestion myself at some point as I do kinda want to do one of those pause menus that appear over the game. Which is fun if you want to try the drag and drop approach. Hit P, save screen shot, load screenshot as background, change the pause room background to screen shot, go to pause room. Handle all the pausing stuff in there as well.

FrozenFire's. Parent class the objects, with pause build in and then use a controller to detect pause and display pause sprite over the top. Bleh, why do I get a sinking feeling my project is duff and I'm going to have scrap and start again. Ah the fun of learning new programming.
Last edited by Fish!; Oct 6, 2012 @ 7:53am
Fable Oct 6, 2012 @ 8:09am 
Parents are for code that stays the same across objects. So in your case, you'd probably make the pause part of a parent object called "obj_pause", then you'd parent enemies to "obj_enemy" and put a small amount of basic enemy code there, and then make each of your enemy objects based on what they are.

If you want to KEEP the parent's code AND add new code, you have to add "event_inherited()" at the top of the Step event for the object you set to have that parent.
Last edited by Fable; Oct 6, 2012 @ 8:10am
Fish! Oct 6, 2012 @ 10:39am 
Thanks. That is useful to know. I'm still hacking around at the moment, need to start thinking of writing up a game plan, then working all this stuff out correctly. Such as the passing of parameters on object/instance creation so that I can easily group enemy and get them to behave in formation but also die in formation.

The tutorials don't really go into that much detail parent objects or at least so far that I've got.

I got so far through the tutorials and though hmm with this one I could add so much more. Is there a detailed scripting tutorial?
< >
Showing 1-15 of 20 comments
Per page: 1530 50

Date Posted: Oct 3, 2012 @ 4:07pm
Posts: 20