• 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 Using mouse input for multiple actions, but they are interfering with each other. How should I fix this?

S

Squigglestixx

Guest
Apologies if this has been asked before or is really simple, I'm very much still learning.

I'm building a point-and-click adventure game, using mb_left for most actions, including inspecting items on-screen and advancing the text. The code I'm using for text boxes has a step event that checks if(mouse_check_button_pressed(mb_left)){. and this will cause the text to go from typing out one letter at a time to just showing the whole block of text (for impatient players).

However, mb_left is also what causes the textbox object to be created in the first place, when you click on a in-game item. This seems to make the textbox object see the if(mouse_check_button_pressed(mb_left)){ as soon as it's created and automatically skips the text crawl.

Is there some easy way around this? a way to disable mb_left for a short period of time?
 

Nidoking

Member
The easiest way, in my opinion, is to set some flag to false when you create something and use an alarm to set it to true when you want to process the inputs.
 

FoxyOfJungle

Kazan Games
mouse_check_button_pressed(mb_left) checks the global mouse click. For it to interfere with the local instance of the object being executed, it must be as follows:

You create the variable "opened" in the create event, and then set it to false when destroys the textbox, to prevent it to open twice.

GML:
if not (opened)
{
    if mouse_check_button_pressed(mb_left)
    {
        if point_in_rectangle(mouse_x,mouse_y,bbox_left,bbox_top,bbox_right,bbox_bottom)
        {
            show_message("clicked me");
            opened = true;
        }
    }
}
 
Last edited:
S

Squigglestixx

Guest
mouse_check_button_pressed(mb_left) checks the global mouse click. For it to interfere with the local instance of the object being executed, it must be as follows:

You create the variable "opened" in the create event, and then set it to false when destroys the textbox

GML:
if mouse_check_button_pressed(mb_left)
{
    if not (opened)
    {
        if point_in_rectangle(mouse_x,mouse_y,bbox_left,bbox_top,bbox_right,bbox_bottom)
        {
            show_message("clicked me");
            opened = true;
        }
    }
}
will this method require that the textbox itself be clicked in order to advance? i'd like to avoid that if possible.
 

FoxyOfJungle

Kazan Games
will this method require that the textbox itself be clicked in order to advance? i'd like to avoid that if possible.
You can do it the way you want, for example, instead of using the mouse click, use:
keyboard_check_pressed() and point_distance() or distance_to_object.

Would be like this:

GML:
if not (opened)
{
    if keyboard_check_pressed(vk_enter)
    {
        var inst = instance_nearest(x,y,obj_textbox)
        if (inst != noone)
        {
            if (distance_to_object(inst) < 30)
            {
                show_message("opened");
                opened = true;
            }
        }
    }
}
 
S

Squigglestixx

Guest
The easiest way, in my opinion, is to set some flag to false when you create something and use an alarm to set it to true when you want to process the inputs.
this worked perfectly! all i had to do was set a text_wait variable to true, with an alarm in the create event to count down 30 frames before setting it to false. this should also prevent accidental double-clicks from skipping the text crawl. thanks!
 
S

Squigglestixx

Guest
You can do it the way you want, for example, instead of using the mouse click, use:
keyboard_check_pressed() and point_distance() or distance_to_object.

Would be like this:

GML:
if not (opened)
{
    if keyboard_check_pressed(vk_enter)
    {
        var inst = instance_nearest(x,y,obj_textbox)
        if (inst != noone)
        {
            if (distance_to_object(inst) < 30)
            {
                show_message("opened");
                opened = true;
            }
        }
    }
}
thanks for your help!!
 
Top