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

Legacy GM Cannot get object to remain visible on mouse click. [SOLVED!]

K

KitKatarine

Guest
Hello! I hope I'm posting in the right place.

I have a problem regarding getting an object to remain visible when I click the mouse.

This is currently the code I'm working with in the "STEP" event of obj_player:
Code:
///Left Mouse Button Commands (

//Check for the LMB
if mouse_check_button(mb_left)
{
    with instance_nearest(mouse_x, mouse_y, obj_tree)    //Find the nearest object to create sprite on top of
    {
       instance_create(x,y-96, obj_cut); // create instance of obj_cut
       
    }

}
Which does this (the button just appears when I click LMB, but disappears instantly).

What I want is for the button to remain up until I click it or elsewhere, and no amount of Googling has given me an answer.

How do I get the button object to stay up?

(Also, if anyone can answer as to why it doesn't work when the player, tree, and button objects are all at different depths, that would be superb.)


Thank you so much!
 

TheBroman90

Member
My guess is that you are using
Code:
mouse_check_button(mb_left)
which runs every step, instead of
Code:
mouse_check_button_pressed(mb_left)
which runs only once when the mouse is pressed.

And I think you have a code in the button which tells it to destroy itself if you press it or elsewhere.
And since your mouse event runs every step, it registers as if you click again, which makes the button disappear.
 
K

KitKatarine

Guest
My guess is that you are using
Code:
mouse_check_button(mb_left)
which runs every step, instead of
Code:
mouse_check_button_pressed(mb_left)
which runs only once when the mouse is pressed.

And I think you have a code in the button which tells it to destroy itself if you press it or elsewhere.
And since your mouse event runs every step, it registers as if you click again, which makes the button disappear.
So I changed mouse_check_button to mouse_check_button_pressed, and it's the same problem.

I have no code in my button object, so that's not it either.


EDIT:

So I changed some code around, got rid of some excess bunk. Turns out, you were right and there was some other garbage that was conflicting with my step event. Except now with THIS:

Code:
if mouse_check_button(mb_left) with instance_nearest(mouse_x, mouse_y, obj_tree)
    {
      instance_create(x,y-96, obj_cut); // create instance of obj_cut
       
    }
I get THIS. Which is sort of right, but sort of... not.

But thank you so much for your help! It's not the end I wanted, per se, but it's a start.



It also doesn't work in the "CREATE" event of my obj_player. I thought I might give that a try and see if that works but no, that's also not it.
 
Last edited by a moderator:

TheBroman90

Member
The Create event only runs once when the instance is created, then it is ignored.

Do you have any code for the button in other objects? Like
Code:
with(obj_button)
{
    // Do stuff...
}
Because nothing with this code should make it disappear.
 
K

KitKatarine

Guest
The Create event only runs once when the instance is created, then it is ignored.

Do you have any code for the button in other objects? Like
Code:
with(obj_button)
{
    // Do stuff...
}
Because nothing with this code should make it disappear.
You were right, there was something buggy in another event somewhere. I've been having issues for a week already with this game - and it's just an experimental thing!
I edited my reply to show what was happening now, but thank you so much for your input because honestly, I was so lost before now :D
 

rIKmAN

Member
So I changed mouse_check_button to mouse_check_button_pressed, and it's the same problem.

I have no code in my button object, so that's not it either.


EDIT:

So I changed some code around, got rid of some excess bunk. Turns out, you were right and there was some other garbage that was conflicting with my step event. Except now with THIS:

Code:
if mouse_check_button(mb_left) with instance_nearest(mouse_x, mouse_y, obj_tree)
    {
      instance_create(x,y-96, obj_cut); // create instance of obj_cut
      
    }
I get THIS. Which is sort of right, but sort of... not.

But thank you so much for your help! It's not the end I wanted, per se, but it's a start.



It also doesn't work in the "CREATE" event of my obj_player. I thought I might give that a try and see if that works but no, that's also not it.
That happens because every time you click you are creating a new instance of the chop/axe button.

Do you want this to be the same action for every tree? ie. Chop it?

Create a single instance of your chop button, and deactivate it.

Then when you click on a tree, activate it again and update the x/y position based on whatever tree you clicked.

Then you can see if it's clicked (do the chop on the clicked tree) or if you click elsewhere you can deactivate the button again.
 
K

KitKatarine

Guest
That happens because every time you click you are creating a new instance of the chop/axe button.

Do you want this to be the same action for every tree? ie. Chop it?

Create a single instance of your chop button, and deactivate it.

Then when you click on a tree, activate it again and update the x/y position based on whatever tree you clicked.

Then you can see if it's clicked (do the chop on the clicked tree) or if you click elsewhere you can deactivate the button again.
That is exactly what I've ended up doing! Thank you so much for your help~
 
Top