GMS 2 Pause Player Input

Discussion in 'Programming' started by Zagaroo, Aug 2, 2017.

Tags:
  1. Zagaroo

    Zagaroo Member

    Joined:
    Jul 24, 2017
    Posts:
    47
    How would I go about disabling the players input for a certain amount of time?
     
  2. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    755
    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.
     
  3. Zagaroo

    Zagaroo Member

    Joined:
    Jul 24, 2017
    Posts:
    47
  4. Turkish Coffee

    Turkish Coffee Member

    Joined:
    Nov 25, 2016
    Posts:
    512
    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
     
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,647
    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.
     
  6. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    755
    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
    [​IMG]
     
  7. Turkish Coffee

    Turkish Coffee Member

    Joined:
    Nov 25, 2016
    Posts:
    512
    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.
    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.
     
  8. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,647
    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.
     
  9. PixelPluto

    PixelPluto Member

    Joined:
    Sep 1, 2018
    Posts:
    5
    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: Dec 5, 2018
  10. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,647
    Is it because you did not reset counter?
     
  11. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    661
    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.
     
  12. PixelPluto

    PixelPluto Member

    Joined:
    Sep 1, 2018
    Posts:
    5
    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 :) .
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice