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

Windows Mouse_button_check

Chaser

Member
Sorry to post about what is probably something i've done but i going out of my mind here

Mouse_check_button_pressed(mb_left)
This function will return true if the mouse button being checked has been pressed or false if it has not. This function will only be triggered once for any mouse button when it is first pressed and to trigger it again the button will need to have been released and pressed again. Note that it will be considered triggered for the duration of the step, and for all instances that have any mouse events or that use this same function.

So, i want an object to be created when i press the left mouse button, but only if a variable is true. In order to set the variable to true i need to left mouse button press on an object.

in the object it has this:
create event
global.active = false

mouse left press event
if global.active = false
{
global.active = true;
}
if global.active = false
{
global.active = true;
}

Now on my other object (which is the mouse cursor)
Step Event
x = mouse_x;
y = mouse_y;

Left pressed event

if global.active = 1
{
if !instance_exists(obj_marker_1)
{
instance_create_depth(mouse_x,mouse_y,-10,obj_marker_1);
}
}
else
{
//do nothing
}

Now this seems pretty straight forward to me. Once the global.active is set to true my NEXT left press should create the instance i want. But what is happening is as soon as left click on the object(and turn global.active from false to true) it immediately creates the instance. At the time the first left pressed is actioned the variable is false so it shouldn't do that should it?? It says this function will only trigger once.

What is happening here that i'm not getting my head round? It's driving me bonkers. Seems like this function is triggering every step, not just once? Could someone put me out of my misery :)
 
H

Homunculus

Guest
The description of the mouse_check_button_pressed entry in the manual already has your answer: the event is triggered for the duration of the whole step. Since both objects (the one that sets global.active and the cursor) have the mouse pressed event, they are both going to execute it at the first press. Now, in that step, if the event of the cursor object executes after the other one, global.active will be true, and your instance will be created. There's not direct way to set which event of the same kind triggers first for two instances in the same step.

The term "once" in this case means "for one step only", not for a single instance.
 

Chaser

Member
Yeah, i see that now, i was just thinking the time the button is pressed, not for the time of the 'steps' its triggered. I'l have to find another way. appreciate your answer. Thanks
 
Top