GameMaker: Studio

GameMaker: Studio

View Stats:
I can't get a mouse action to take place ONLY on a certain object.
Ok, so i am in the midst of making an educational app for my programming class and i am currently working on the visual appearance. So, for one object i am trying to make it so when it is clicked it moves off the screen. However, i having a slight problem. I set this following code in the objects Left Pressed event:
______________________________________
pressed = true;
if(pressed = true){
movespeed+=grav;//add gravity to initial jump speed
y+=movespeed;//adds movespeed to object's y coordinate.
}
_______________________________________

**In the Create Event, pressed = false, movespeed = 10, grav = 1.5;

The problem is that i have to click the object so it moves one frame at a time. I also tried not using the Left Pressed and putting it all in the Step event like the following:
__________________________________________________
if(mouse_check_button_pressed(mb_left)){
pressed = true;
}
if(pressed = true){
movespeed+=grav;
y+=movespeed;
}
__________________________________________________

For visual purposes, this works fine. However the problem is that if i click anywhere on the screen it makes the object do its action and not when the object specifically is being pressed.

If someone could show me the error of my ways i would be very grateful. I have also tried using Left Button function instead of the Left Pressed, the only difference being that i need to hold the mouse over the object for each frame or else it doesn't move.
< >
Showing 1-3 of 3 comments
Blind Nov 21, 2014 @ 12:40pm 
Use the event Mouse, Enter and Mouse, Exit to store the local ID of the button you are trying to press and only perform operations on the object whose ID is stored.
Sera Nov 21, 2014 @ 1:47pm 
Set pressed to true in the mouse click event, but run the movement logic in the step event; pressed = true doesn't reset between events, so as long as the object was clicked and the variable was set, the step event should realize it and take apprpriate action.

The reason it's only moving one step at a time in the first setup is because it's only running that movement check on the frame the object has been clicked. That's what the input checks generally do; they're one-off reactions to whatever said input is, so to set them off again, you need to keep hitting that input. The Step event, meanwhile, runs every frame regardless.
ThePhantom4567 Nov 22, 2014 @ 2:01pm 
@Zaron X,
Thank you very much. this worked. I spent 2 days trying to figure out this problem. I guess it just takes another set of eyes to see the solution.
< >
Showing 1-3 of 3 comments
Per page: 1530 50

Date Posted: Nov 21, 2014 @ 10:03am
Posts: 3