• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

pause menu

mX273

Member
Hi guys!

I would like to make a simple pause menu with changing form a persistant room to the pause-room.
I also made the obj_inputDevice and the obj_player persistant, to have control in the pause room.
Strangely the step event of the obj_inputDevice is not executed anymore, althougt the debugger
shows instances of the player and the inputDevice in the pause room.

thats my code:
GML:
/// obj_player
// ---------------------

// get the latest state of the inputDevice (gamepad) assuming that the step-event of this device is periodically executed
btn_pause    = scr_inputDevice_checkButton(e_inputDeviceButton.start, e_inputDeviceButtonState.posEdge)
    
    if (btn_pause)  // this variable stays always true, when changed to pause room (step-event of inputDevice isn't executed anymore)
    {
        btn_pause = false
        if (room != rm_pause)
        {
            // CASE A: Go to pause room
            global.pause           = true
            room_persistent        = true
            global.roomBeforePause = room
            room_goto(rm_pause)   
            exit
        }
        else
        {
            // CASE B: Go back from pause room
            global.pause           = false
            room_goto(global.roomBeforePause)   
            global.roomBeforePause = noone
            room_persistent        = false
            exit
        }
    }
When i press pause in the game, game maker executes Case A, then Case B, then Case A and so on...

any ideas?
 

Nidoking

Member
If the input instance isn't processing input, then it's probably not resetting the state of the button. Maybe something in the input processor is pausing based on the pause state?
 

samspade

Member
It's only a guess, but you have a room_goto in there. I believe the room switches at the end of the event, so if this event is running before the step event of input device runs it will change rooms before it can.

I think what is happening is this:

- pause button pressed and handled in the input object
- the player object checks if it is pushed, and if so, changes to the pause room
- then it checks again (before input runs) and changes back
- then it checks again (before input runs) and changes to the pause room
- repeat

If that is the case, and my guesses about the rest of your code are right, switching all input handling to the begin step event might solve the issue. This way, you can be sure that the input is handled before it is checked. This is a good practice in general if you're going to have an input manager, handle the input in the begin step and don't allow any instance to check it before the step event.

Also, your player instance probably shouldn't be checking and handling the pause state and room switching, but that is more of a code structure thing than a likely to be the problem thing.
 

mX273

Member
why do you think that the step "- then it checks again (before input runs) and changes back "
is called twice? The step event of each instance should be called once per Frame no matter which order...
so actually, the inputDevice should be updatet each frame.

"Also, your player instance probably shouldn't be checking and handling the pause state and room switching, but that is more of a code structure thing than a likely to be the problem thing. "
Yes, thats true... i moved it to the obj_gameController

Thank you!
 

Nidoking

Member
why do you think that the step "- then it checks again (before input runs) and changes back "
is called twice? The step event of each instance should be called once per Frame no matter which order...
so actually, the inputDevice should be updatet each frame.
Because room_goto changes rooms at the end of the event - and there's an exit right after each one, which immediately ends the event. When the new room starts, it's a new step, or "frame" if you like.
 

TailBit

Member
I had that problem, my controller object sending me to titlescreen, and my titlescreen object exiting the game on the same press .. Had to emulate a key release or have my step event exit on first step using a variable.
if flag { flag=false; exit; }
 

mX273

Member
Because room_goto changes rooms at the end of the event - and there's an exit right after each one, which immediately ends the event. When the new room starts, it's a new step, or "frame" if you like.
That means the order of execution of the step events (of each instance) is reset at room change?

Execution of step-events:

1. step-event of obj_A
2. step-event of obj_B
3. step-event of obj_inputDevice
4. step-event of obj_player
---> room change here --- restart at 1??
(5. step-event of obj_C not executed because of room change ... restart at 1)
(6. step-event of obj_D not executed because of room change ... restart at 1)


is that correct?
 

Nidoking

Member
That's essentially correct, with the added complication that you can't rely on those steps to happen in the same order every time. Also, after the room change, the same instances won't necessarily exist (unless absolutely every instance in your game is persistent) - the instances from the old room will be destroyed, and the instances for the new room will be created and run their room start events before the first step. The persistent instances will also run their Room End and Room Start events, so that can be a good place to reset things that will need to change during room transitions.
 
Top