• 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!

GameMaker Clearing inputs? / Unwanted button presses exiting pause menu

hogwater

Member
Game is a 2d platformer.

OK, I have a pause feature that brings up a pause menu. My "confirm" button in the pause menu is the same as my "jump" button during gameplay. When I press "confirm" to exit the pause menu, my character instantly jumps upon exiting the menu (if he's in a char state with jumping allowed).

I believe that I need to clear my inputs somehow when closing the pause menu, but I've been unsuccessful so far, and I'm not really sure where or how to do this. Here's how the pause function works, as well as inputs:

Step event of my player char initiates the pause:
Code:
//pause that game my man
if (pause) && (!global.paused) && (can_pause)
{
global.paused = true;
var view_x = camera_get_view_x(obj_camera.camera);
var view_y = camera_get_view_y(obj_camera.camera);
var view_width = camera_get_view_width(obj_camera.camera);
var view_height = camera_get_view_height(obj_camera.camera);
instance_create_layer(view_x + ((view_width/5)*3),view_y + (view_height/4),"top_layer",obj_pause_menu);
audio_play_sound(snd_pause,0,0);
can_pause = false;
}

This creates a pause menu object. In its Create event:
Code:
//actual pausing 
instance_deactivate_all(true);
instance_activate_object(obj_input);
instance_activate_object(obj_game_control);
instance_activate_object(obj_audio_control);
instance_activate_object(obj_display_control);
instance_activate_object(obj_debug_drawer);

This is what the "unpause" menu selection does:
Code:
//RESUME (unpause) option
if (menu_index == 5) && (confirm)
{
can_do = true;
instance_activate_all();
global.paused = false;
    if (instance_exists(obj_harry))
    {
        with (obj_harry)
        {
        can_pause = true;
        }
    }
audio_play_sound(snd_unpause,0,0);
instance_destroy();   
}

Finally, this is how I collect the inputs from my "input manager object" in the step event of my player char:

Code:
//get player input
left = obj_input.left_held;
right = obj_input.right_held;
down = obj_input.down_held;
up = obj_input.up_held;
run = obj_input.x_button_held;
jump = obj_input.a_button;
attack = obj_input.y_button;
attack_held = obj_input.y_button_held;
attack_release = obj_input.y_button_release;
attack2 = obj_input.b_button;
attack2_held = obj_input.b_button_held;
attack2_release = obj_input.b_button_release;
pause = obj_input.start_button;
pause_release = obj_input.start_button_release;

Ideas?
 
Two suggestions:

1) Don't exit the menu on the same frame that the button is pressed, but at least on the next.
2) Have another control variable for player inputs that is set to 0 when entering a menu, and set to 1 upon releasing any input.
 

hogwater

Member
Two suggestions:

1) Don't exit the menu on the same frame that the button is pressed, but at least on the next.
2) Have another control variable for player inputs that is set to 0 when entering a menu, and set to 1 upon releasing any input.
You sir, are a champion. Your first idea worked wonderfully, thanks!

Also, thinking about this thing for a while made me realize that I should really move the pause activation to either my input object or a controller object.
 
Last edited:

TheouAegis

Member
Is your pause using a continuous hold check (e.g., mouse_check_button(mb_left) or keyboard_check(vk_enter)) or is it using a press check? If it's using a press check, you could just set pause to 0.
 

hogwater

Member
It's a press check. Where would I put that? Just in the code block that exits the menu?

I tried variations on that but I may have been putting that code in the wrong place or something.
 

TheouAegis

Member
If I was understanding your issue, when you check if pause is true, set pause to 0 as the result. A pressed-check will only exist for one step. So if you're setting pause to 0 after you checked that it's 1, it will be 0 for all other references to pause until the next time the key is pressed again, thus making pause true for only one single block of code in any given step.
 
Top