Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

GM8: Problem with mouse moved object!

Hi! I am working on a game in GAME MAKER 8 PRO. I tried to make an object moved with the mouse. I have an event which says

LEFT MOUSE BUTTON PRESSED: Move Free (direction 90 / UPWARDS)

This makes the OBJECT move UP only when pressing LEFT MOUSE on the object only(not globally!)

I then have another event saying this: LEFT MOUSE RELEASED : MOVE FREE (Direction: 270, down)

I have LEFT MOUSE BUTTON making the object move UP
Then when releasing LEFT MOUSE BUTTON, I have the OBJECT fall downwards again. Only when NOT pressing LEFT with the cursor over the object.

HERES A RECORD OF MY PROBLEM:

http://www.youtube.com/watch?v=5hZWipgy_5k

As you can see the OBJECT STILL moves any direction! I have to tap it or press it to make it go down again! Now that was NOT my idea, my idea was to make the OBJECT fall automatically when NO button is pressed (not globally) over the object! Please help, WHY does it continue moving? Am I using the wrong events?

NOTE: I want THE BOX to drop when mouse buttons IS NOT PRESSED OVER THE OBJECT, but it DOES NOT. I want it to move to LEFT when pressing LEFT MOUSE BUTTON (working) and UP when pressing RIGHT MOUSE BUTTON (working), and stop moving + DROP when NO BUTTON TOUCHED. At all. Right now nothing's working, but before I had to hover the mouse arrow over the object to make it drop again, simply not just releasing left/right arrow button (that I want). I have made a similar game in GM7 but GM8 doesn't seem to work in the same way.

COMMANDOS IN GM7:

OBJECT BOX: Left Mouse > Move 180 (LEFT)
Right Mouse > Move 90 (UP)
No Mouse Button > STOP MOVING + Move 270 (DOWN)


The difference is that it worked in GM7 WHEN I RELEASED any button, but in GM8, i need to steer curson OUT OF the object (BOX) and returning it over the BOX. Why is it like this? The release commandos doesn't work either! Thanks in advice:)

/9robin3
 
RadethDart":pjcpx4uq said:
I feel pretty bad that no one helped you, so hopefully I can still help you. I will check back frequently. If you want to get my attention faster, email me if you don't see a response.

radethdart@gmail.com

thank you! I am not using any code but simple commands. I made the command : Mouse - no button > STOP MOVING. But is that whats causing the problem?
 
Can you PM me your file and I can take a look at it for you. From what you are describing, I don't see why it wouldn't work. It might be the way you are declaring it. Would you be 100% against using GML for the code if I could make it work using GML? I could also try making it work using the D&D if you would prefer.
 
RadethDart":2krsc0ho said:
Can you PM me your file and I can take a look at it for you. From what you are describing, I don't see why it wouldn't work. It might be the way you are declaring it. Would you be 100% against using GML for the code if I could make it work using GML? I could also try making it work using the D&D if you would prefer.

I do know nothing about coding NOTHING. but if it craves the use of codes, can youhelp me with that too? I will prepare the file for tomorrow then I'll post it to you! hank you a lot^^
 
No problem! If you have skype, maybe we could communicate through that so I can help you learn the language a bit. It is really easy if you have any learning experience of game languages. The GML is just like the drag and drop environment; I really like coding in GML. :)
 
RadethDart":1q7kwbr9 said:
No problem! If you have skype, maybe we could communicate through that so I can help you learn the language a bit. It is really easy if you have any learning experience of game languages. The GML is just like the drag and drop environment; I really like coding in GML. :)

nice, yeah I have skype :D I would be pleased!:) just add robinandblom

EDIT: Here is the GAME FILE:
http://www.megaupload.com/?d=W2UK5C98

NOTE: I want THE BOX to drop when mouse buttons IS NOT PRESSED OVER THE OBJECT, but it DOES NOT. I want it to move to LEFT when pressing LEFT MOUSE BUTTON (working) and UP when pressing RIGHT MOUSE BUTTON (working), and stop moving + DROP when NO BUTTON TOUCHED. At all. Right now nothing's working, but before I had to hover the mouse arrow over the object to make it drop again, simply not just releasing left/right arrow button (that I want). I have made a similar game in GM7 but GM8 doesn't seem to work in the same way.

COMMANDOS IN GM7:

OBJECT BOX: Left Mouse > Move 180 (LEFT)
Right Mouse > Move 90 (UP)
No Mouse Button > STOP MOVING + Move 270 (DOWN)


The difference is that it worked in GM7 WHEN I RELEASED any button, but in GM8, i need to steer curson OUT OF the object (BOX) and returning it over the BOX. Why is it like this? The release commandos doesn't work either! Thanks in advice:)

/9robin3
 
You are going to be so mad at yourself when you realize what you have to do to fix this. :P

Change your "Mouse Released" events to "Global Mouse Left Released" and "Global Mouse Right Released."

That should solve your problem in GMK8. :) It worked for me, so if you have any more questions, let me know.
 
RadethDart":oqrngcuo said:
You are going to be so mad at yourself when you realize what you have to do to fix this. :P

Change your "Mouse Released" events to "Global Mouse Left Released" and "Global Mouse Right Released."

That should solve your problem in GMK8. :) It worked for me, so if you have any more questions, let me know.

ohh my:O so have you tried that? Haha how ackward of me xD I'll test that at once:)

EDIT: It doesn't really work, the object keeps moving in any direction if you hold the cursor still (even if box have moved away from cursor) it's just when you release it it drops. I want the box to drop when cursor's not pressed ON the object. Is that possible please?:P
 
After a little bit of time coding, I fixed your problem!

Place this in the step event of your object and then delete the mouse commands. You should only have the Create Event, Step Event, and Outside Room Event.

C:
<div class="c" id="{CB}" style="font-family: monospace;"><ol>//------------------------------------------------------

//

// Mouse Over and Move Objects on Click

// Location: step event

// Objective: Check if mouse is over object

//            Check which button is being pressed

//            Do what you need to do with that object

// Script Version: 1.0

// Author: RadethDart

//

//------------------------------------------------------

 

// Set the x and y variables of the box (object)

x = box1.<span style="color: #202020;">x // x position of the box -------edit this line for the x position of object

y = box1.<span style="color: #202020;">y // y position of the box -------edit this line for the y position of object

 

// Check if the mouse is positioned over the object

<span style="color: #b1b100;">if (mouse_x <= x + real(sprite_width) and mouse_y <= y + real(sprite_height))

{

 // if the left mouse button is being pressed while on the box

 <span style="color: #b1b100;">if (mouse_check_button_pressed(mb_left))

 {

  // then set the motion to go left (180 degrees = left)

  motion_set(<span style="color: #cc66cc;">180, <span style="color: #cc66cc;">3);

 }

 

 // if the right mouse button is being pressed while on the box

 <span style="color: #b1b100;">if (mouse_check_button_pressed(mb_right))

 {

  // then set the motion of the box up (90 degrees = up)

  motion_set(<span style="color: #cc66cc;">90, <span style="color: #cc66cc;">3);

 }

 // if the mouse is not over the object, then force to move down (270 degrees = down)

} <span style="color: #b1b100;">else {

  direction = <span style="color: #cc66cc;">270;

  speed = <span style="color: #cc66cc;">2;

}

 

//------------------------------------------------------

//

// Below is used to catch any exceptions the object

// might allow by the mouse not being on the object

//

//------------------------------------------------------

 

// Check if the mouse is not positioned over the object

<span style="color: #b1b100;">if ((!mouse_x <= x + real(sprite_width)) and (!mouse_y <= y + real(sprite_height)))

{

 // if the left mouse button is released while not over the object

 <span style="color: #b1b100;">if (mouse_check_button_released(mb_left))

 {

  // make sure the box drops

  direction = <span style="color: #cc66cc;">270;

  speed = <span style="color: #cc66cc;">2;

 }

 // if the right mouse button is released while not over the object

 <span style="color: #b1b100;">if (mouse_check_button_released(mb_right))

 {

  // make sure the box drops

  direction = <span style="color: #cc66cc;">270;

  speed = <span style="color: #cc66cc;">2;

 }

}
 
Thanks man:) it works. Well better anyway. But still it moves when cursor's outside of the BOX, not all the time, but a few seconds after the mouse has left the object. But maybe I'll have to go with this, still it works fine:)

EDIT: I need to do the same with a mirrored object. It moves instead of UP and LEFT, RIGHT and LEFT.
 
Hey, my computer at home went down yesterday, and I have been busy with some personal things, so I am going to try and fix my computer tonight and get that code written for you. Sorry about the delay.
 
RadethDart":20m5duq8 said:
Hey, my computer at home went down yesterday, and I have been busy with some personal things, so I am going to try and fix my computer tonight and get that code written for you. Sorry about the delay.

Oh I am sorry that your computer broke:( ok well I just need the same thing but mirrored, to the UP, RIGHT box thanks^^
 
I made the collision detection 100% better, and made this for both directions. It is really easy and interchangeable for what you are wanting to do. All it takes is copy/paste of my code into the step even of the object you want to move around.

The variables that you want to change are the ones at the top with the x, and the y.
C:
<div class="c" id="{CB}" style="font-family: monospace;"><ol>x = OBJECT.<span style="color: #202020;">x // the object's x that you want to track

y = OBJECT.<span style="color: #202020;">y // the object's y that you want to track

Box Move Left/Up
C:
<div class="c" id="{CB}" style="font-family: monospace;"><ol>//------------------------------------------------------

//

// Mouse Over and Move Objects on Click

// Location: step event

// Objective: Check if mouse is over object

//            Check which button is being pressed

//            Do what you need to do with that object

// Script Version: 2.0

// Author: RadethDart

//

//------------------------------------------------------

 

// Set the x and y variables of the box (object)

x = box1.<span style="color: #202020;">x // x position of the box

y = box1.<span style="color: #202020;">y // y position of the box

 

// Check if the mouse is positioned over the object

<span style="color: #b1b100;">if (position_meeting(mouse_x, mouse_y, self))

{

 // if the left mouse button is being pressed while on the box

 <span style="color: #b1b100;">if (mouse_check_button_pressed(mb_left))

 {

  // then set the motion to go left (180 degrees = left)

  motion_set(<span style="color: #cc66cc;">180, <span style="color: #cc66cc;">3);

 }

 

 // if the right mouse button is being pressed while on the box

 <span style="color: #b1b100;">if (mouse_check_button_pressed(mb_right))

 {

  // then set the motion of the box up (90 degrees = up)

  motion_set(<span style="color: #cc66cc;">90, <span style="color: #cc66cc;">3);

 }

 // if the mouse is not over the object, then force to move down (270 degrees = down)

} <span style="color: #b1b100;">else {

  direction = <span style="color: #cc66cc;">270;

  speed = <span style="color: #cc66cc;">2;

}

 

//------------------------------------------------------

//

// Below is used to catch any exceptions the object

// might allow by the mouse not being on the object

//

//------------------------------------------------------

 

// Check if the mouse is not positioned over the object

<span style="color: #b1b100;">if (!position_meeting(mouse_x, mouse_y, self))

{

 // if the left mouse button is released while not over the object

 <span style="color: #b1b100;">if (mouse_check_button_released(mb_left))

 {

  // make sure the box drops

  direction = <span style="color: #cc66cc;">270;

  speed = <span style="color: #cc66cc;">2;

 }

 // if the right mouse button is released while not over the object

 <span style="color: #b1b100;">if (mouse_check_button_released(mb_right))

 {

  // make sure the box drops

  direction = <span style="color: #cc66cc;">270;

  speed = <span style="color: #cc66cc;">2;

 }

}

Box Move Right/Up
C:
<div class="c" id="{CB}" style="font-family: monospace;"><ol>//------------------------------------------------------

//

// Mouse Over and Move Objects on Click

// Location: step event

// Objective: Check if mouse is over object

//            Check which button is being pressed

//            Do what you need to do with that object

// Script Version: 2.0

// Author: RadethDart

//

//------------------------------------------------------

 

// Set the x and y variables of the box (object)

x = box2.<span style="color: #202020;">x // x position of the box

y = box2.<span style="color: #202020;">y // y position of the box

 

// Check if the mouse is positioned over the object

<span style="color: #b1b100;">if (position_meeting(mouse_x, mouse_y, self))

{

 // if the left mouse button is being pressed while on the box

 <span style="color: #b1b100;">if (mouse_check_button_pressed(mb_left))

 {

  // then set the motion to go left (0 degrees = right)

  motion_set(<span style="color: #cc66cc;">0, <span style="color: #cc66cc;">3);

 }

 

 // if the right mouse button is being pressed while on the box

 <span style="color: #b1b100;">if (mouse_check_button_pressed(mb_right))

 {

  // then set the motion of the box up (90 degrees = up)

  motion_set(<span style="color: #cc66cc;">90, <span style="color: #cc66cc;">3);

 }

 // if the mouse is not over the object, then force to move down (270 degrees = down)

} <span style="color: #b1b100;">else {

  direction = <span style="color: #cc66cc;">270;

  speed = <span style="color: #cc66cc;">2;

}

 

//------------------------------------------------------

//

// Below is used to catch any exceptions the object

// might allow by the mouse not being on the object

//

//------------------------------------------------------

 

// Check if the mouse is not positioned over the object

<span style="color: #b1b100;">if (!position_meeting(mouse_x, mouse_y, self))

{

 // if the left mouse button is released while not over the object

 <span style="color: #b1b100;">if (mouse_check_button_released(mb_left))

 {

  // make sure the box drops

  direction = <span style="color: #cc66cc;">270;

  speed = <span style="color: #cc66cc;">2;

 }

 // if the right mouse button is released while not over the object

 <span style="color: #b1b100;">if (mouse_check_button_released(mb_right))

 {

  // make sure the box drops

  direction = <span style="color: #cc66cc;">270;

  speed = <span style="color: #cc66cc;">2;

 }

}
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top