GameMaker Pause Player Input

Z

Zagaroo

Guest
How would I go about disabling the players input for a certain amount of time?
 
have a variable that keeps track of whether the player can control the game or not. Set it to true.
Above the code that checks the player's input, see if that variable is true before running the code.
When you want to remove control, set the variable to false, and use an alarm to set it back to true after X amount of time.
 
have a variable that keeps track of whether the player can control the game or not. Set it to true.
Above the code that checks the player's input, see if that variable is true before running the code.
When you want to remove control, set the variable to false, and use an alarm to set it back to true after X amount of time.
thats probably the most basic fix for the pausing but if you have lots of codes, it would be a boring and hard work to put the code into every code file. I was thinking that for a while
 

TheouAegis

Member
if you have lots of codes, it would be a boring and hard work to put the code into every code file. I was thinking that for a while
Then it's your fault for not planning things out better ahead of time.

You could also just move everyone's codes to User Events and have a central controller object tell them to run their proper User Events, but that'd be just as much work or more.

If you did come up with an alternative, I'd be interested to hear it.
 
it would be a boring and hard work to put the code into every code file.
You shouldn't be checking input in very many places. In fact, you should check all input right at the beginning of your player's step event. Check all possible buttons and store them in variables. Then use those variables to actually move the character and what not.

Here's an example from one of my projects
 
Then it's your fault for not planning things out better ahead of time.

You could also just move everyone's codes to User Events and have a central controller object tell them to run their proper User Events, but that'd be just as much work or more.

If you did come up with an alternative, I'd be interested to hear it.
That seemed a bit offensive with your usage of words. Could be much more kind I think. Besides that, I didn't think of an alternative and I will do the same -pause variable- I remember a guy saying "de-activating- the objects. What about that? I mean, I haven't tried de-activating an object never.
You shouldn't be checking input in very many places. In fact, you should check all input right at the beginning of your player's step event. Check all possible buttons and store them in variables. Then use those variables to actually move the character and what not.

Here's an example from one of my projects
Okay but I was actually thinking about AI stuff like makes the enemies move for example. I need to type the pause in each of the UNIQUE coded enemies.
 

TheouAegis

Member
De-activating makes them invisible too. So then if you want them still visible, you take a screenshot and show that after you deactivate everything. But then you can't have things, say, be animated doing that. So don't deactivate those! But then they're back to being active and you're back to square one.

That's what the single-controller principle takes care of, but like using a global variable check, it requires significant forethought.
 
P

PixelPluto

Guest
Hi there, I hope it's okay if I re-open this topic, because I tried the method Pixelated_Pope explained here, and though I managed to make Gamemaker ignore mouse input, I didn't manage to enable it again with a timer.

I'm currently working on a HTML5 interactive story, and the player has to click one object on the screen to continue the story, in this case making text appear and starting some small animations. It is during those small animations that I would like player input to be ignored.

My code looks like this:

Create event:
counter = 0;
var_mouse = true;

Left mouse button released event:
if (var_mouse = true) {
counter += 1;
}

Step event:
if (counter = 1) {
text[1]
}
if (counter = 2) {
text[2]
start animation
}
if (counter = 3) {
text[3]
var_mouse = false;
alarm[0] = room_speed * 10
}

Alarm 0 event:
var_mouse = true;

I switched from DnD to GML only recently, so I probably missed some detail here. I also tried to find a work-around on this, but without success.

Thanks for your help in advance.
 
Last edited by a moderator:
Follow your code logically in your head. To begin with counter is 0 and var_mouse is true. When you click, you increase counter by 1 ONLY IF var_mouse is true. In the step event, the value of counter determines what text is going to show and also sets the alarm and var_mouse to false if it is 3. So you click a few times, the counter goes up: counter = 1, you show some text, counter = 2, you show some more text and do an animation, counter = 3, you set var_mouse to false and alarm[0] to 10 seconds. But what's this? In the next step event, counter still equals 3, so you're setting var_mouse to false and alarm[0] to 10 seconds again, and again, and again, every step. Ok, so as long as counter = 3, var_mouse will always be false, meaning you can't click to change the value of the counter and alarm[0] is being set to 10 seconds literally every step of the game. You've just made the mouse input useless and also made it so alarm[0] will never trigger.

What @TheouAegis suggested should fix it, depending on how your game is set up. Once you set alarm[0], you need to stop counter from equaling 3, otherwise you'll just be setting alarm[0] every step. There's multiple ways to solve this problem, but resetting counter to 0 is probably the quickest and easiest.
 
P

PixelPluto

Guest
Thank you for your reply :) !

I forgot to mention that my counter should be able to go to 4 to continue the game and to show text[4], so I tried the resetting, and it just started to show text[1] again.

But you gave me an idea on how to solve my problem, so I'll try out that idea :) .
 
P

PixelPluto

Guest
For those who encounter the same problem and are interested in my solution:

I set up a second trigger (in my case var_mouse_2 = false) and a second counter (counter_2). If f. e. counter = 4, the first trigger var_mouse is set to "false", but I also start an alarm. When the alarm goes off, the second trigger var_mouse_2 is set to "true", and only if var_mouse_2 = true, then counter_2 is able/allowed to count.

I hope this helps :) .
 
Top