Jump to content


Photo
- - - - -

Classic Pause


  • Please log in to reply
46 replies to this topic

#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
  • 92 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
  • 51 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

  • New Member
  • 123 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

  • New Member
  • 215 posts
  • Version:GM8

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

#27 HerpDerp

HerpDerp

    GMC Member

  • New Member
  • 215 posts
  • Version:GM8

Posted 12 June 2012 - 12:50 AM

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

#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

#29 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 92 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

#31 Tarik

Tarik

    GMC Member

  • GMC Member
  • 2469 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

#33 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 92 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

#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

#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
  • 92 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

#39 NameDollars

NameDollars

    GMC Member

  • GMC Member
  • 5 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

#40 pixeltao

pixeltao

    GMC Member

  • GMC Member
  • 92 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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users