GMS2.3 - How to pause a Player when the textbox is up?

Still relatively new coder here... I have been trying to find out a way to get my player to essentially pause (can't move around using the keyboard function BUT can still play the idle animation) while the textbox is up running dialog, but so far my attempts have been unsuccessful. Below is my script code in the Step section of my obj_textbox. Can anyone assist?

I was originally using

if message_draw==true
{ speed=0 }

But it wasn't working anywhere.

Code:
/// @desc Type text
scr_input();
var action_hold = keyboard_check(vk_space);

// Check if we need more characters
if (characters < message_length) {
    characters += message_speed+action_hold;

    // Copy string to the current character
    message_draw = string_copy(message[message_current], 0, characters);
} else { // Once we have finished adding the characters
    if (actionKey) {
        //Check if there are more messages
        if (message_current < message_end) { //Start the next message
        message_current += 1;
        message_length = string_length(message[message_current]);
        characters = 0;
        message_draw = "";
    } else {
    // destroy the object
    instance_destroy();
        }
    }
}


///
///
///

if(keyboard_check_pressed(ord("E"))){
    if(counter < str_len){ counter = str_len; }
    else if(page < array_length_1d(text) - 1){
        page++;
        event_perform(ev_other, ev_user1);
    } else { instance_destroy(obj_textbox);}
}


// Where to put the code if I want the player to not be able to move when a text box is open?
 

Yal

🐧 *penguin noises*
GMC Elder
You should abort all processing, not just movement speed. In every event that's relevant (Step, Key Press / Release / Held, etc) you'd add something like
GML:
if(global.paused){
  exit;
}
as the first line.

Ideally use a global variable for whether pausing is on or off, so you only need to change it in one place if you add more reasons to pause (e.g. a pause button).


If you use alarms, you additionally need to add code in the Step Event that, if the game is paused, adds 1 to every alarm.
If you use the built-in movement system, you additionally need to add -hspeed to x, -vspeed to y, -gravity to vspeed, and so on.
Basically, in the step event, when the game is paused you need to undo any automatic processes that you simply cannot nullify by aborting an event. (This should happen before you exit the event's processing, of course, or it won't happen)
 

woods

Member
id put the global paused variable in some controller object
and

Code:
       if(global.paused){
exit;
}
would go in every object you want paused(like the player and enemies and such)
 

kburkhart84

Firehammer Games
You could also use the deactivation system. Make a separate player object that ONLY shows the idle animation. When you load up a text box, deactivate the player, and create this other object in the same x/y position.. When you are done with the text box, remove the other object, and re-activate the player. This let's you not have to add any code to the player itself to handle it.

The above assumes that the player is the only thing that needs stopped...if you have enemies or something like that, you will either need to do them the same way, or handle it in a different manner. I personally think it would be neat if ALL the enemies went into some idle animation, like tapping their foot waiting or something.
 
id put the global paused variable in some controller object
and

Code:
       if(global.paused){
exit;
}
would go in every object you want paused(like the player and enemies and such)
Thank you for your help, and Yal too. I don't quite understand it right now, but I'm sure it will click when I can figure out how to set up the global var (and where exactly) to get it to work! I know it seems like super simple stuff, but my brain isn't wired for coding (I have an artist's mind, lol) so it just takes some tries to get things to snap when it comes to programming.
 
M

MeanLikeCharlieSheen

Guest
I would try looking into finite state machines there is a good write up i found at Finite State Machines definitely worth a read and definitely worth it in the long run, if you have any trouble feel free to message me I'm relatively new at this but more then happy to help with what i can 👍
 

MaxLos

Member
I would try looking into finite state machines there is a good write up i found at Finite State Machines definitely worth a read and definitely worth it in the long run, if you have any trouble feel free to message me I'm relatively new at this but more then happy to help with what i can 👍
Was gonna say this as well. If all he wants to do 'pause' the player so they can't move around while talking, using a state machine to set him to a "talking" state or something similar where the only actions that can be done is advance the text will be simplest way
 
Thank you for your help, and Yal too. I don't quite understand it right now, but I'm sure it will click when I can figure out how to set up the global var (and where exactly) to get it to work! I know it seems like super simple stuff, but my brain isn't wired for coding (I have an artist's mind, lol) so it just takes some tries to get things to snap when it comes to programming.
Try something like this somewhere in your player step event. It worked for me

name of speed for character (mine is called: walkspeed)

Code:
if instance_exists("Message object here")
{
   (name of speed for character) = 0
}
else
{
    (name of speed for character) = (Insert desired number)
}
 
Last edited:
Try something like this somewhere in your player step event. It worked for me

name of speed for character (mine is called: walkspeed)

Code:
if instance_exists("Message object here")
{
   (name of speed for character) = 0
}
else
{
    (name of speed for character) = (Insert desired number)
}
THANK YOU! That worked (for the most part)! Any advice on how to make it so the keyboard keys, when pressed, won't be able to move you around in a frozen circle when obj_texbox is up? Player can't move around, but can spin ^^;
 

woods

Member
the same way you stop the speed of the player..
in the player step event where you declare your player movement for example

i would go something like this..
obj_player step event
Code:
if instance_exists("Message object here")
{
   key_left = noone;
   key_right = noone;
}
else
{
    key_left = keyboard_check(ord("A"));
    key_right = keyboard_check(ord("D"));
}
 

Tyg

Member
id put the global paused variable in some controller object
and

Code:
       if(global.paused){
exit;
}
would go in every object you want paused(like the player and enemies and such)
Woods has given the easiest way and the way i use also, a global var paused..or i make that a state
definately easier if you have a controller object of all input, turn on or off controls or input
instead of chasing each objects input
 
Last edited:
Top