Jump to content


Photo
- - - - -

Classic Pause


  • Please log in to reply
46 replies to this topic

#1 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 10 October 2008 - 07:01 PM

  • Title: Classic Pause
  • Description: A method to pause the game.
  • GM Version: 7
  • Registered: no
  • File Type: .gmk
  • File Size: 48k
  • File Link: Classic Pause
Additional Info
What I'm showing here is a way to pause the game by "manually" deactivating the instances so that they don't disappear (like in old Konami NES games). This method is highly customizable, but every step must be followed carefully. This method is different than those showed here :YoYoGame Wiki

First of all, you must create a variable named 'pausable' for ALL your objects.
ALL OBJECTS: CREATE EVENT
pausable = 1; //0 = Can't be paused. 1 = Can be paused.

Then you put all the code for pausing the game in the begin step event of a controller object.
CONTROLLER OBJECT: CREATE EVENT
{
	pausable = 0; //This object can't be paused.
	globalvar background_music,pause; //Sets a global variable for the background music and the pause state.
        pause = 0;
	

/*This will set and play the background music. You can also put this in the room creation code
if you want a different music to play for each level*/
	background_music = sound0;
	sound_volume(background_music,1);
	sound_loop(background_music);
}

CONTROLLER OBJECT: BEGIN STEP EVENT
{
// Pause Game
	if ( !pause )
	{
		if ( keyboard_check_pressed(vk_enter) ) //Pauses the game when the player press Enter.
		{
			pause=1; //The game is paused.
			sound_volume(background_music,0.85); //Reduces the volume of the background music (optional).
			sound_play(snd_pause); //Plays a sound when the game is paused (optional).
			instance_create(view_xview+view_wview/2,view_yview+view_hview/2,obj_pause); //Creates an object to display a pause sprite when the game is paused (optional).
			with ( all ) //Saves the state of all "pausable" instances and put all their local variable to 0.
			{
				if ( pausable )
				{
					prev_image_speed=image_speed;
					prev_vspeed=vspeed;
					prev_hspeed=hspeed;
					prev_gravity=gravity;
					prev_path_speed=path_speed;
					prev_timeline_speed=timeline_speed;
					image_speed=0;
					vspeed=0;
					hspeed=0;
					gravity=0;
					path_speed=0;
					timeline_speed=0;
				}
			}
		}
	}
	else if ( keyboard_check_pressed(vk_enter) ) //Resume the game when the player press Enter.
	{
		pause=0; //The game resumes.
		sound_volume(background_music,1); //Music volume is back to normal.
		with (obj_pause) instance_destroy(); //Destroys the pause object.
		with ( all ) //Restore the state of all instances.
		{
			if ( pausable )
			{
				image_speed=prev_image_speed;
				vspeed=prev_vspeed;
				hspeed=prev_hspeed;
				gravity=prev_gravity;
				path_speed=prev_path_speed;
				timeline_speed=prev_timeline_speed;
			}
		}
	}
	if ( pause )
	{
		with ( all ) //Maintains all the alarms of "pausable" objects to the same value while the game is paused.
		{
			if ( pausable )
			{
				if (alarm[0]>0) alarm[0]+=1;
				if (alarm[1]>0) alarm[1]+=1;
				if (alarm[2]>0) alarm[2]+=1;
				if (alarm[3]>0) alarm[3]+=1;
				if (alarm[4]>0) alarm[4]+=1;
				if (alarm[5]>0) alarm[5]+=1;
				if (alarm[6]>0) alarm[6]+=1;
				if (alarm[7]>0) alarm[7]+=1;
				if (alarm[8]>0) alarm[8]+=1;
				if (alarm[9]>0) alarm[9]+=1;
				if (alarm[10]>0) alarm[10]+=1;
				if (alarm[11]>0) alarm[11]+=1;
			}
		}
	}
}
Finally, you must put a little piece of code in certain events of all the "pausable" objects in order to tell them to stop performing certain events while the game is paused.
ALL OBJECTS: STEP EVENTS, KEYBOARD/MOUSE EVENTS, COLLISION EVENTS
if ( pause ) exit; //Put this before any other code.

That's about it! I hope it helps.

Edited by pixeltao, 27 October 2012 - 09:01 PM.

  • 1

#2 Titanium

Titanium

    the perfectionist

  • GMC Member
  • 1166 posts

Posted 12 October 2008 - 05:59 PM

Just looking at the last part I believe that this isn't very helpful.

if(pause)exit;

What if the character's in the air? Won't he just fall if the gravity's already set.
Won't the animations still continue?

My favorite pausing method is:

show_message("The Game is Paused: Press Enter to Continue or click O.K")

Just criticizing.
  • 0
ljrk.png
Please Play My Games.

#3 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 13 October 2008 - 05:44 AM

Just looking at the last part I believe that this isn't very helpful.

if(pause)exit;

What if the character's in the air? Won't he just fall if the gravity's already set.
Won't the animations still continue?

My favorite pausing method is:

show_message("The Game is Paused: Press Enter to Continue or click O.K")

Just criticizing.


The character won't fall while the game is paused because all the values of the built-in variables (like speed, gravity, etc.) of all instances are saved into new variables then they are set to zero when the player pauses the game. When the player resumes the game, all these values for all instances are restored. Please, read carefully and try it before criticizing.

The show_message method indeed work, but it's not very customizable and it doesn't work with a gamepad/joystick.
  • 0

#4 Chronic

Chronic

    Administrator

  • Global Moderators
  • 2729 posts
  • Version:GM:Studio

Posted 16 October 2008 - 12:09 PM

I'd like to know your opinion on why to use this method over deactivating instances.

Also, why would you alter the alarms? The whole point in pausing is to essentially freeze time... which would include any timers. But anyway, alarms count down, not up, and use -1 to show they are off.

I do however like the idea of making the background music volume reduce :)
  • 0

My recent tutorials: [Auto-Tiling] [Text Based Menu] [Sprite Based Menu] [View more at my site]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
R.I.P Mom (1951-2008)


#5 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 16 October 2008 - 06:08 PM

I decided to use this method (instead of the background_create + instance deactivation method, which is another method I like) because I'm actually making a game in 720p (1280x720) and I had two little problems/details bothering me.

The first one was that the creation of the pause background caused a lag when I paused the game. Obviously, it doesn't matter if you just freeze the game, but it's perceptible if you have a pause menu (and it can be really bad on older hardware).

The second little issue was when I played the game at a lower resolution. Since the background is created from the screen (much like a print screen) the quality of the picture changed when I paused the game, it became a little blurry. I know, I'm very picky...

This method is not necessarily the easiest choice for everyone. It needs a little more work than some other methods to integrate. But it's very clean, it's fast, it works with gamepads and it's highly customizable (and less risky and complicated than a while loop). You can even use this system to stop the action on screen during in-game dialogues, for example.

For the alarms, the idea is exactly as you said:

The whole point in pausing is to essentially freeze time... which would include any timers.

It happens only when the game is paused. They are altered simply because you don't want them to continue counting down while the game is paused, but you want to keep their current state. The idea is pretty simple, since an alarm subtract 1 every frame, you just add 1 to the alarms of pausable objects every frame, while the game is paused. So, if the value of an alarm was, for example, 8 when you paused the game, this value will still be 8 when you resume the game.

Thanks!
  • 0

#6 amberyoukai

amberyoukai

    GMC Member

  • New Member
  • 300 posts

Posted 18 October 2008 - 03:25 AM

Im with Titanium
show_message("The Game is Paused: Press Enter to Continue or click O.K")

but I give 3 choices tohe player:
Help
Resume
Exit

//Pause system by Kougan
if keyboard_check(ord("P")){
sound_stop_all()
  switch (show_message_ext("Your game is paused.","Continue","Help","Menu",)) //Check all cases as possibilities for the question. (0 = if the player press escape)
  {
	case 1:
	 {
	  
	sound_loop(sound28)}
	break; //Never forget this command with a switch-loop!
	case 0:
	{
	
	}
	
	break; //Never forget this command with a switch-loop!
	case 2:
	{
	show_info() 
		}
	break; //Never forget this command with a switch-loop!
	case 3:
	{
	 room_goto(menu)	}
	break; //Never forget this command with a switch-loop!
	case 0:
	{
 
	}
	break; //Never forget this command with a switch-loop!
  }
}

  • 0
<a href="http://gmc.yoyogames...owtopic=425413" target="_blank"><img src="http://i234.photobuc.../RedGuysig.jpg" border="0" class="linked-sig-image" /></a>
<b><!--coloro:#FF0000--><span style="color:#FF0000"><!--/coloro-->LINK NOT WORKING/Great game feauring cuztomizable character!(too busy)<!--colorc--></span><!--/colorc--></b>
See topic if you want to help(click the image)

#7 hensi

hensi

    GMC Member

  • New Member
  • 2 posts

Posted 15 September 2009 - 09:38 PM

Thanks!
  • 0

#8 Tahnok

Tahnok

    Friendly Madman

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

Posted 15 September 2009 - 11:29 PM

Clearly the two people who are posting the show_message solution don't understand the effect this is supposed to give and in what context it would be used.

Anyway, it's an interesting idea. I tend to go with the background creation method you mentioned, but I can see why you wouldn't want to use surfaces if your game isn't already reliant on them (why break a game with the pause on a PC that can't do surfaces). Still though, this method seems a little over complicated. Just thinking about the issue (without any game to test it on) it seems like it would be easier to simply deactivate all the interactive instances (anything that's moving) and put in temporary stand-in graphics for those objects. You could do it either by creating a dummy instance for every object you deactivate that simply draws the sprite, or you could add all the images that need to be drawn into a data structure that you can then loop through and draw. They should both be pretty fast I would think, depending on the number of instances on screen that need to be frozen. I couldn't imagine it being any slower than your current method anyway.

Also, depending on the game, you could simplify things by making a single "pausable" parent object. That way you aren't cycling through every instance trying to figure out which ones to pause and such; you can simply call with(parentPauseable) or something like that and have the code execute for all the instances that should change.

Edited by Tahnok, 15 September 2009 - 11:30 PM.

  • 0

gmc_signature.png


#9 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 18 September 2009 - 02:29 AM

Clearly the two people who are posting the show_message solution don't understand the effect this is supposed to give and in what context it would be used.

Anyway, it's an interesting idea. I tend to go with the background creation method you mentioned, but I can see why you wouldn't want to use surfaces if your game isn't already reliant on them (why break a game with the pause on a PC that can't do surfaces). Still though, this method seems a little over complicated. Just thinking about the issue (without any game to test it on) it seems like it would be easier to simply deactivate all the interactive instances (anything that's moving) and put in temporary stand-in graphics for those objects. You could do it either by creating a dummy instance for every object you deactivate that simply draws the sprite, or you could add all the images that need to be drawn into a data structure that you can then loop through and draw. They should both be pretty fast I would think, depending on the number of instances on screen that need to be frozen. I couldn't imagine it being any slower than your current method anyway.

Also, depending on the game, you could simplify things by making a single "pausable" parent object. That way you aren't cycling through every instance trying to figure out which ones to pause and such; you can simply call with(parentPauseable) or something like that and have the code execute for all the instances that should change.


You have a good point. I use this pause method in 2 games I'm developing right now and I indeed use parenting to keep track of the pause variables. For example, I know that all the enemies needs to be paused, so the code related to pausing the enemies only needs to be inserted in an "o_enemy_parent" object. Also, I know that since this method needs a few lines of code for every objects, it can take time to implement it correctly in a game that is near completion. However, it works very well if you plan it right from the beginning.

Concerning the pausing method you're mentioning (using dummy objects to draw sprites), I think I've seen a tutorial about it on this forum. However, to me, it seemed more complicated to implement than the method I've explained here. The idea seemed clever though.

Edited by pixeltao, 18 September 2009 - 02:31 AM.

  • 0

#10 ninja_sheep

ninja_sheep

    GMC Member

  • GMC Member
  • 138 posts

Posted 21 June 2010 - 10:45 AM

I really like this method because my pause menu is far more complicated than just a couple of buttons - there are inventories, things to upgrade etc. This method should work great for me (especially as I don't know how to do surfaces and stuff)
  • 0

#11 gmx0

gmx0

    The Messenger

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

Posted 21 June 2010 - 02:03 PM

Tip: click inside this box to load the editor
^^ Go Away!
How bout this?
in the Key press event
sleep(500);
io_clear();
keyboard_wait();
  • 0

#12 B Factory LLC

B Factory LLC

    We're awesome!!

  • New Member
  • 511 posts

Posted 21 June 2010 - 02:47 PM

One quick thing.

Instead of making the pausable variable for all objects, why not make a parent that sets pauseable to false. Make every object inherit that instance and if it CAN be paused, just overwrite that and set pausable to true.

Those of you who are fellow Java programmers will get what I'm saying.
  • 0

If you are neutral in situations of injustice, you have chosen the side of the oppressor. If an elephant has its foot on the tail of a mouse and you say that you are neutral, the mouse will not

appreciate your neutrality.

Posted Image

Anti-Wikileaks Bill introduced in US Congress! (When the giant is mad, it hits hard...)

"So this is how liberty dies. With thunderous applause." - Padme

"The ruling class has the schools and press under its thumb. This enables it to sway the emotions of the masses." - Albert Einstein

Please check out my blog: My link


#13 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 23 June 2010 - 06:02 PM

One quick thing.

Instead of making the pausable variable for all objects, why not make a parent that sets pauseable to false. Make every object inherit that instance and if it CAN be paused, just overwrite that and set pausable to true.

Those of you who are fellow Java programmers will get what I'm saying.


This is a good idea. Tahnok also mentioned it in his post above. I did not explain it in this tutorial, but I actually use it. I'll try to update this page eventually, if I can find some spare time.

Edited by pixeltao, 27 June 2010 - 05:13 PM.

  • 0

#14 ExpHP

ExpHP

    GMC Member

  • New Member
  • 32 posts

Posted 13 August 2010 - 03:54 AM

I was just now trying to implement my own pause screen, and, ironically enough, what brought me here was that I was trying to find out how to pause an alarm for that very purpose (my game uses a LOT of alarms). Incrementing the alarms every step is ingenious, and the rest of what you do here is pretty clever, too. I might just use this entire system over the pause method I was writing. It's simpler and more functional.

Before I use this, I am a bit concerned about borderline cases with alarms, though. What I mean is, let's say the game is paused when an object's alarm is at 0. To me, it looks like with the current code, the alarm will get to run right after the game is paused, resulting in an object possibly moving and changing state during the pause screen.

Maybe you should change the >0 in those lines to >=0 like so?:
if (alarm[0]>=0) alarm[0]+=1;

Or maybe alarm events in pauseable objects should require this at the beginning?:
if ( pause ) { alarm[0]=1; exit; } //Replace 0 with the alarm's number.

Or maybe I'm wrong, and you can tell me why it does work properly the way it is. :wacko:

Edited by ExpHP, 13 August 2010 - 04:02 AM.

  • 0
I am a Posted Image in the GM Quiz!... crud. The test saw right through me.

I have a lot of experience in many other languages and platforms, though. I'm just new to GM.

#15 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 13 August 2010 - 05:05 AM

I was just now trying to implement my own pause screen, and, ironically enough, what brought me here was that I was trying to find out how to pause an alarm for that very purpose (my game uses a LOT of alarms). Incrementing the alarms every step is ingenious, and the rest of what you do here is pretty clever, too. I might just use this entire system over the pause method I was writing. It's simpler and more functional.

Before I use this, I am a bit concerned about borderline cases with alarms, though. What I mean is, let's say the game is paused when an object's alarm is at 0. To me, it looks like with the current code, the alarm will get to run right after the game is paused, resulting in an object possibly moving and changing state during the pause screen.

Maybe you should change the >0 in those lines to >=0 like so?:

if (alarm[0]>=0) alarm[0]+=1;

Or maybe alarm events in pauseable objects should require this at the beginning?:
if ( pause ) { alarm[0]=1; exit; } //Replace 0 with the alarm's number.

Or maybe I'm wrong, and you can tell me why it does work properly the way it is. :wacko:


I'm not sure to understand how this borderline case can exist. When an alarm reaches 0 it generates its event and it switches off. So, if you pause the game at that time you should not re-increment it, otherwise you'll re-activate the alarm thus generating the event again (so you'll end up generating the alarm event twice once the game resumes).

So this line
if (alarm[0]>=0) alarm[0]+=1;
will potentially create a bug. In fact, it will create the exact bug you're describing.

And this line
if ( pause ) { alarm[0]=1; exit; } //Replace 0 with the alarm's number.
will also create a bug because it will always set your alarm to a value of 1 each time you pause the game (thus messing up the timing of your alarms).

I've been using this code for pausing for a while now and it still works pretty well. So, I'm confident that if you use it as explained in the first post, you shouldn't encounter any problems. Unless I completely misunderstood the issue you were talking about!
  • 0

#16 ExpHP

ExpHP

    GMC Member

  • New Member
  • 32 posts

Posted 13 August 2010 - 05:17 AM

When an alarm reaches 0 it generates its event and it switches off.

I don't know when alarms tick during the step and when their event is called. If the event really is called immediately after the timer ticks as you say (nothing else occurs in between), then your code is perfectly fine and I retract my previous statements.

So this line

if (alarm[0]>=0) alarm[0]+=1;
will potentially create a bug. In fact, it will create the exact bug you're describing.

Fair enough. I can see that happening.

And this line

if ( pause ) { alarm[0]=1; exit; } //Replace 0 with the alarm's number.
will also create a bug because it will always set your alarm to a value of 1 each time you pause the game (thus messing up the timing of your alarms).

Not quite. It's in the alarm event. It only runs when the alarm is 0.

I guess I should just take your word for it and just start implementing the system. You know more about this than me, and nobody else has complained about any issues of the sort I'm worried about yet, so chances are it's solid.

Edited by ExpHP, 13 August 2010 - 05:20 AM.

  • 0
I am a Posted Image in the GM Quiz!... crud. The test saw right through me.

I have a lot of experience in many other languages and platforms, though. I'm just new to GM.

#17 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 13 August 2010 - 05:58 AM


And this line

if ( pause ) { alarm[0]=1; exit; } //Replace 0 with the alarm's number.
will also create a bug because it will always set your alarm to a value of 1 each time you pause the game (thus messing up the timing of your alarms).

Not quite. It's in the alarm event. It only runs when the alarm is 0.


Sorry, I misread... You're right. It's unnecessary though.

I guess I should just take your word for it and just start implementing the system. You know more about this than me, and nobody else has complained about any issues of the sort I'm worried about yet, so chances are it's solid.


Well, I never had any issue with this, so I guess the alarms work as I thought they would :P (it's also how the alarms are described in the GM documentation anyways). But if you want to verify if it works (or not) as intended, you could probably test it easily enough. Anyways, I hope you'll like this system. :)
  • 0

#18 ExpHP

ExpHP

    GMC Member

  • New Member
  • 32 posts

Posted 13 August 2010 - 04:02 PM

Just finished implementing it and it works great! I'm going to see if I can use obj_pause to make a nice menu, too. I'm very glad I implemented this when I didn't already have a lot of objects, because otherwise it would've taken me a lot more time than it did.

My only grief about implementing it is that, when you forget to give an object the pausable variable, GM's error message does little to help you figure out which one is missing the variable.

Edited by ExpHP, 13 August 2010 - 04:04 PM.

  • 0
I am a Posted Image in the GM Quiz!... crud. The test saw right through me.

I have a lot of experience in many other languages and platforms, though. I'm just new to GM.

#19 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 16908 posts
  • Version:GM:Studio

Posted 10 August 2011 - 12:23 AM

Std Msg: Please fix the download link.
  • 0

#20 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 10 August 2011 - 05:41 PM

Std Msg: Please fix the download link.


Fixed.
  • 0

#21 Morpheas

Morpheas

    GMC Member

  • New Member
  • 66 posts
  • Version:GM8

Posted 03 March 2012 - 12:54 PM

mmm.newbie here.
i putted the controller in 1st room changed the values of the code.
in the create of controller i putted the 2nd code box.
in a begin step event the third code.
and in the objects of the room i putted in the create event set variable pausable 1
now the error i get....
ERROR in
action number 1
of Begin Step Event
for object musicontroler:

Error in code at line 13:
if ( pausable )
^
at position 39: Unknown variable pausable

why it doesnt see the variable pausable=1?
any idea?

Edited by Morpheas, 03 March 2012 - 12:58 PM.

  • 0

#22 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 03 March 2012 - 08:11 PM

mmm.newbie here.
i putted the controller in 1st room changed the values of the code.
in the create of controller i putted the 2nd code box.
in a begin step event the third code.
and in the objects of the room i putted in the create event set variable pausable 1
now the error i get....
ERROR in
action number 1
of Begin Step Event
for object musicontroler:

Error in code at line 13:
if ( pausable )
^
at position 39: Unknown variable pausable

why it doesnt see the variable pausable=1?
any idea?


From what I understand, the error seems to happen when your controller object checks the value of the "pausable" variable for all objects. So, the problem must be that the "pausable" variable is missing (or is misspelled) in the Create event of one of your objects. Did you double-check your objects to make sure that it's initialized properly in all of them?

A good way to avoid forgetting to include a variable shared by many objects is to use parenting: make a parent Pausable object that initializes the "pausable" variable in its Create event and then make all other objects derive from it. That way, you don't need to initialize it all your objects. Then, if the derived object has or needs a Create event, call event_inherited() to also execute the code from the parent Create event (otherwise it'd override the parent Create event).
  • 0

#23 Morpheas

Morpheas

    GMC Member

  • New Member
  • 66 posts
  • Version:GM8

Posted 04 March 2012 - 09:34 AM

i solved it thx
  • 0

#24 Bloodleh

Bloodleh

    GMC Member

  • GMC Member
  • 52 posts

Posted 04 March 2012 - 07:13 PM

Great idea, although I prefer more a simply freezing everything by while(1). Also creating a surface of everything (or something?) and then deactivating everything with the built-in function is more efficient.
  • 0

#25 ZeplashStudios

ZeplashStudios

    GMC Member

  • GMC Member
  • 126 posts

Posted 23 April 2012 - 11:50 AM

what bout this? works perfectly fine for me: still basic, but I'm sure with a screen refresh and so on you can animate a sprite:
if keyboard_check_pressed(ord("P"))
{
keyboard_clear(ord("P"))
pause = 1
while (pause = 1)
{
screen_refresh()
draw_set_color(c_black)
draw_text(room_width/2,room_height/2,"PAUSED")
if keyboard_check_pressed(ord("P"))
{
paused = 0;
exit;
}
sleep(30)
}
keyboard_clear(ord("P"));
}

  • 0

#26 HerpDerp

HerpDerp

    GMC Member

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

Posted 12 June 2012 - 12:16 AM

'Sup pixeltao,

This idea is awesome, I've been looking for a way to pause my games WHILE being able to control the game by making menu's and animations etc. Just came across this. The GM7 file still works 100% in the current GM8.1, so I've copied the code and did everything step by step. The only thing I just can't seem to find is:

Where the hell did you define your "pause" variable?!?! I don't see it anywhere in the example either, although it works flawlessly
and as you can guess, I get an error saying this variable wasn't defined in my own game. As expected...

If you can get back on me, I'll finally be able to experience the almighty power of full-control in-game pausing MUHAHA... Right, a bit over the top..

But please help! :smile:
  • 0

I may not know everything, but I'm glad to help whenever I can!

 

:GM106: If I helped you, feel free to click the shiny green vote-up arrow to the right! :GM106:

 

:thanks:


#27 HerpDerp

HerpDerp

    GMC Member

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

Posted 12 June 2012 - 12:50 AM

Nevermind, found it! works 100% in my game now, can't thank you enough ;)
  • 0

I may not know everything, but I'm glad to help whenever I can!

 

:GM106: If I helped you, feel free to click the shiny green vote-up arrow to the right! :GM106:

 

:thanks:


#28 DariusSlayer

DariusSlayer

    GMC Member

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

Posted 24 October 2012 - 03:24 PM

I came across this error when I tried out that code:


___________________________________________
FATAL ERROR in
action number 1
of Step Event1
for object Gameplay_UI:

############################################################################################
VMError!! Occurred - Push :: Execution Error - Variable Get pause
at gml_Object_Gameplay_UI_Step_1 (line -1) - <unknown source line>
############################################################################################
Self Variables :
100007( pausable ) = 0.000000


I placed the variable within every object that was in game and followed yours steps precisely.
  • 0
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.

#29 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 24 October 2012 - 06:07 PM

I came across this error when I tried out that code:


___________________________________________
FATAL ERROR in
action number 1
of Step Event1
for object Gameplay_UI:

############################################################################################
VMError!! Occurred - Push :: Execution Error - Variable Get pause
at gml_Object_Gameplay_UI_Step_1 (line -1) - <unknown source line>
############################################################################################
Self Variables :
100007( pausable ) = 0.000000


I placed the variable within every object that was in game and followed yours steps precisely.


It's a bit hard to tell without more info on your code, but I suspect that this error happens because of how the new versions of Game Maker treats undefined variables vs. how old versions treated them.

So, to solve this, make sure that the "pausable" variable is set to 0 or 1 in the Create event of your Gameplay_UI object (depending on if you want this object to be paused). The "pausable" absolutely needs to be initialized to a value before you try to check it in your Step event (or in any other event).
  • 0

#30 DariusSlayer

DariusSlayer

    GMC Member

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

Posted 24 October 2012 - 07:01 PM

Yea, I got those covered... I'm working with Studio right now, so there ought to be some differences.

I think I'll create a Pause Controller instead of putting the function with the Gameplay_UI controller (which draws lives, score, and HP).
  • 0
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.

#31 Tarik

Tarik

    GMC Member

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

Posted 24 October 2012 - 11:42 PM

A few comments from a few years back pointed out some of the difficulties in using this system. For example, using timers and various variables that aren't covered. (for example, I usually use a custom movement system that doesn't necessarily use gravity, speed etc, and creating unique holder variables for all the variables in the tens of datastructures I use isn't very practical.

Some also pointed out the option to use surfaces, or creating a sprite from the screen. But others pointed out surfaces don't work for everyone (I have to say though, this was mostly an issue in 2008 when a lot of people were still using old cards), and that not everyone can create screen-sized textures. (again, an old card issue, cards can normally always create a texture the size of the screen/resolution.)

If you still don't want to create new textures or surfaces, if you use pre-studio GM, I think all you'd need to do on pauze is to set automatic drawing off, change room to a pauze room, and then call screen refresh in the room and draw ontop any pauze message you'd like. On any keyboard input you'd switch automatic drawing back on and change the room back. Should be a few lines of code, all it requires is a persistent room. If you don't want that, just call room restart when you need to, and set it to persistent anyway.
  • 0

#32 DariusSlayer

DariusSlayer

    GMC Member

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

Posted 26 October 2012 - 06:53 PM

Yea, now all I get is this for a warning:

___________________________________________
FATAL ERROR in
action number 1
of Step Event1
for object Gameplay_UI:

############################################################################################
VMError!! Occurred - Push :: Execution Error - Variable Get pause
at gml_Object_Gameplay_UI_Step_1 (line -1) - <unknown source line>
############################################################################################


So, I did something right, I guess, that got rid of the other line of code causing an issue... I'm looking it over again and again but I really don't see how this error can come up :/
  • 0
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.

#33 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 26 October 2012 - 07:01 PM

Yea, now all I get is this for a warning:

___________________________________________
FATAL ERROR in
action number 1
of Step Event1
for object Gameplay_UI:

############################################################################################
VMError!! Occurred - Push :: Execution Error - Variable Get pause
at gml_Object_Gameplay_UI_Step_1 (line -1) - <unknown source line>
############################################################################################


So, I did something right, I guess, that got rid of the other line of code causing an issue... I'm looking it over again and again but I really don't see how this error can come up :/


Do you know if it's possible to open a GM Studio file with Game Maker 8.1? If that's the case, you could send me your project. It'd be easier to help you figure this out.
  • 0

#34 DariusSlayer

DariusSlayer

    GMC Member

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

Posted 26 October 2012 - 07:03 PM

Don't know if that's possible, but yea, I can try. PM me your emaill address, or if you want, we can text over Skype.
  • 0
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.

#35 DariusSlayer

DariusSlayer

    GMC Member

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

Posted 26 October 2012 - 07:05 PM

As of now, I have an inventory box that appears when the game should pause.
  • 0
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.

#36 rjj95

rjj95

    GMC Member

  • GMC Member
  • 196 posts
  • Version:Unknown

Posted 26 October 2012 - 08:13 PM

{
draw_set_font(font_pause);
draw_set_color(c_red);
draw_set_halign(fa_center);
draw_text(room_width/2,100, 'Game Paused. Press any key to continue');
screen_refresh();
keyboard_wait();
io_clear();
}
problem solved.
  • 0

#37 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 27 October 2012 - 09:12 PM

@DariusSlayer: After some investigation, I believe that this error is caused by the fact that GM Studio doesn't set a default value to uninitialized variables. In this case, the pause variable is declared but never initialized to a value. To fix this, you have to add:
pause = 0;
In the Create event of the Controller after the pause global variable is declared. I edited the first post to include this modification.

@rjj95: Not really. Please read the first post before posting comments.
  • 0

#38 DariusSlayer

DariusSlayer

    GMC Member

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

Posted 06 November 2012 - 02:57 PM

WHen this code is in the Step Event (as it should be), "if ( pause ) exit;", all objects that can fire can not and my player can not move. When I remove this code, every one of those object function normally, but I can't pause... I've been starring at the main code for a while now and still can't figure it out. The function of the pause works. It really does and I'm glad that it does, but baffled as to why it's impeding the other functions.
  • 0
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.

#39 NameDollars

NameDollars

    GMC Member

  • GMC Member
  • 8 posts
  • Version:GM8

Posted 28 December 2012 - 11:51 PM

When I put it in my object's Step event and try running my game to see it work, I get this message:

___________________________________________
COMPILATION ERROR in Script: pause
Error in code at line 6:
                           pause=1;
                                ^
at position 31: Variable name expected.
How can I fix this?
  • 0
NameDollars

#40 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 29 December 2012 - 01:41 AM

When I put it in my object's Step event and try running my game to see it work, I get this message:

___________________________________________
COMPILATION ERROR in Script: pause
Error in code at line 6:
                           pause=1;
                                ^
at position 31: Variable name expected.
How can I fix this?


Did you follow exact the implementation explained in the 1st post? Because, if you put the pause code into a script, or make some changes to it, it might not work as intended.
  • 0

#41 NameDollars

NameDollars

    GMC Member

  • GMC Member
  • 8 posts
  • Version:GM8

Posted 29 December 2012 - 05:15 AM


When I put it in my object's Step event and try running my game to see it work, I get this message:

___________________________________________
COMPILATION ERROR in Script: pause
Error in code at line 6:
                           pause=1;
                                ^
at position 31: Variable name expected.
How can I fix this?


Did you follow exact the implementation explained in the 1st post? Because, if you put the pause code into a script, or make some changes to it, it might not work as intended.


I followed the instructions exactly, and only removed optional stuff I did not want. I did not add nor remove anything not optional and it is the only thing in its script.

EDIT: When I run your downloadable example with the changes I made, it runs normally. When I run my game after a copy/paste to make sure they are exactly the same, it has the same error come up.

Edited by NameDollars, 29 December 2012 - 08:27 AM.

  • 0
NameDollars

#42 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 30 December 2012 - 10:41 PM



When I put it in my object's Step event and try running my game to see it work, I get this message:

___________________________________________
COMPILATION ERROR in Script: pause
Error in code at line 6:
                           pause=1;
                                ^
at position 31: Variable name expected.
How can I fix this?


Did you follow exact the implementation explained in the 1st post? Because, if you put the pause code into a script, or make some changes to it, it might not work as intended.


I followed the instructions exactly, and only removed optional stuff I did not want. I did not add nor remove anything not optional and it is the only thing in its script.

EDIT: When I run your downloadable example with the changes I made, it runs normally. When I run my game after a copy/paste to make sure they are exactly the same, it has the same error come up.


I can't easily tell you what's wrong in your implementation without having more details. Did you make sure that all of your objects have the pause variable initialized in their respective create event?

EDIT: Is it possible that you have an object named "pause" like the pause variable? This can create a conflict in your GM project. If that's the case, simply rename your pause object (or the variable).

Edited by pixeltao, 30 December 2012 - 10:45 PM.

  • 0

#43 NameDollars

NameDollars

    GMC Member

  • GMC Member
  • 8 posts
  • Version:GM8

Posted 31 December 2012 - 08:53 AM




When I put it in my object's Step event and try running my game to see it work, I get this message:

___________________________________________
COMPILATION ERROR in Script: pause
Error in code at line 6:
                           pause=1;
                                ^
at position 31: Variable name expected.
How can I fix this?


Did you follow exact the implementation explained in the 1st post? Because, if you put the pause code into a script, or make some changes to it, it might not work as intended.


I followed the instructions exactly, and only removed optional stuff I did not want. I did not add nor remove anything not optional and it is the only thing in its script.

EDIT: When I run your downloadable example with the changes I made, it runs normally. When I run my game after a copy/paste to make sure they are exactly the same, it has the same error come up.


I can't easily tell you what's wrong in your implementation without having more details. Did you make sure that all of your objects have the pause variable initialized in their respective create event?

EDIT: Is it possible that you have an object named "pause" like the pause variable? This can create a conflict in your GM project. If that's the case, simply rename your pause object (or the variable).


Thanks.

Hopefully unrelated, but may be, so still posting it here: Now my experience and HP bars aren't drawing when unpaused, but are when paused (using different objects for each) and the opponent HP still draws above them when unpaused. The codes are nearly exactly the same, but with changes for where they are drawn (EXP under the current/max, HP under current when paused, EXP 0,0, HP directly right of it when not). Again, not sure if related, but may be, so posting here to be safe.

EDIT: Never mind. Just a mistake in the coding by a guy too lazy to proof read.

Edited by NameDollars, 31 December 2012 - 10:25 AM.

  • 0
NameDollars

#44 Alphanumerai

Alphanumerai

    GMC Member

  • GMC Member
  • 16 posts
  • Version:GM8.1

Posted 16 March 2013 - 03:34 PM

Just wanted to say I'm using your pause system in my NES/SMS inspired project.
It originally appealed to me as it doesn't blank the screen of obscure it with a horrible dialogue box, so you can have your own menus.
I'm also going to use it for screen transitions, pausing everything and moving the view and player, while altering their recorded variables. To give the same affect as when you cross the screen in games like Mega Man.
Just have to add something to determine whether it was paused by the player or the game, to allow control or not ^_^

Best pause system I've found.
  • 0

#45 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 97 posts

Posted 17 March 2013 - 12:53 AM

Just wanted to say I'm using your pause system in my NES/SMS inspired project.
It originally appealed to me as it doesn't blank the screen of obscure it with a horrible dialogue box, so you can have your own menus.
I'm also going to use it for screen transitions, pausing everything and moving the view and player, while altering their recorded variables. To give the same affect as when you cross the screen in games like Mega Man.
Just have to add something to determine whether it was paused by the player or the game, to allow control or not ^_^

Best pause system I've found.


Awesome, glad you like it ^_^ I'm a fan of NES/SMS style games. I'd be curious to try it when it's ready.
  • 0

#46 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 16908 posts
  • Version:GM:Studio

Posted 18 March 2013 - 08:42 PM

Please dont name the function the same as a variable. I think that is the problem here.

 

COMPILATION ERROR in Script: pause

 

pause=1;


  • 0

#47 Ruub

Ruub

    Finn The Human

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

Posted 22 March 2013 - 09:34 AM

hey pixeltoa,

 

I figured, isn't it easier to have one control that puts in all the variables instead of having to put it in every create event?

 

//Roomstart event because persistent ;D
with (all)
{
if object_index=obj_controller
or object_index=obj_smoothbackground
or object_index=obj_megafox
or object_index=obj_cursor
{pause_able=0; exit;}

pause_able=1;
}

Edited by Ruub, 22 March 2013 - 09:36 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users