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:



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
bump! HELP!!!!
anyone?
please anyone. there must be a solution-.-
Let me see the code you are using. Are you using GML or the D&D?
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.

[email hidden]
RadethDart wrote:
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.

[email hidden]


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 wrote:
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 wrote:
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 wrote:
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
Ah, I will check that out when I get home from work tonight. :) That's what I thought you were wanting. I am going to have to use GML for it, but I will comment heavily for you. :)
RadethDart wrote:
Ah, I will check that out when I get home from work tonight. :) That's what I thought you were wanting. I am going to have to use GML for it, but I will comment heavily for you. :)



thanks:)
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.

  1. //------------------------------------------------------
  2. //
  3. // Mouse Over and Move Objects on Click
  4. // Location: step event
  5. // Objective: Check if mouse is over object
  6. //            Check which button is being pressed
  7. //            Do what you need to do with that object
  8. // Script Version: 1.0
  9. // Author: RadethDart
  10. //
  11. //------------------------------------------------------
  12.  
  13. // Set the x and y variables of the box (object)
  14. x = box1.x // x position of the box -------edit this line for the x position of object
  15. y = box1.y // y position of the box -------edit this line for the y position of object
  16.  
  17. // Check if the mouse is positioned over the object
  18. if (mouse_x <= x + real(sprite_width) and mouse_y <= y + real(sprite_height))
  19. {
  20.  // if the left mouse button is being pressed while on the box
  21.  if (mouse_check_button_pressed(mb_left))
  22.  {
  23.   // then set the motion to go left (180 degrees = left)
  24.   motion_set(180, 3);
  25.  }
  26.  
  27.  // if the right mouse button is being pressed while on the box
  28.  if (mouse_check_button_pressed(mb_right))
  29.  {
  30.   // then set the motion of the box up (90 degrees = up)
  31.   motion_set(90, 3);
  32.  }
  33.  // if the mouse is not over the object, then force to move down (270 degrees = down)
  34. } else {
  35.   direction = 270;
  36.   speed = 2;
  37. }
  38.  
  39. //------------------------------------------------------
  40. //
  41. // Below is used to catch any exceptions the object
  42. // might allow by the mouse not being on the object
  43. //
  44. //------------------------------------------------------
  45.  
  46. // Check if the mouse is not positioned over the object
  47. if ((!mouse_x <= x + real(sprite_width)) and (!mouse_y <= y + real(sprite_height)))
  48. {
  49.  // if the left mouse button is released while not over the object
  50.  if (mouse_check_button_released(mb_left))
  51.  {
  52.   // make sure the box drops
  53.   direction = 270;
  54.   speed = 2;
  55.  }
  56.  // if the right mouse button is released while not over the object
  57.  if (mouse_check_button_released(mb_right))
  58.  {
  59.   // make sure the box drops
  60.   direction = 270;
  61.   speed = 2;
  62.  }
  63. }
Expand to see the code.
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 wrote:
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.
  1. x = OBJECT.x // the object's x that you want to track
  2. y = OBJECT.y // the object's y that you want to track
Expand to see the code.


Box Move Left/Up
  1. //------------------------------------------------------
  2. //
  3. // Mouse Over and Move Objects on Click
  4. // Location: step event
  5. // Objective: Check if mouse is over object
  6. //            Check which button is being pressed
  7. //            Do what you need to do with that object
  8. // Script Version: 2.0
  9. // Author: RadethDart
  10. //
  11. //------------------------------------------------------
  12.  
  13. // Set the x and y variables of the box (object)
  14. x = box1.x // x position of the box
  15. y = box1.y // y position of the box
  16.  
  17. // Check if the mouse is positioned over the object
  18. if (position_meeting(mouse_x, mouse_y, self))
  19. {
  20.  // if the left mouse button is being pressed while on the box
  21.  if (mouse_check_button_pressed(mb_left))
  22.  {
  23.   // then set the motion to go left (180 degrees = left)
  24.   motion_set(180, 3);
  25.  }
  26.  
  27.  // if the right mouse button is being pressed while on the box
  28.  if (mouse_check_button_pressed(mb_right))
  29.  {
  30.   // then set the motion of the box up (90 degrees = up)
  31.   motion_set(90, 3);
  32.  }
  33.  // if the mouse is not over the object, then force to move down (270 degrees = down)
  34. } else {
  35.   direction = 270;
  36.   speed = 2;
  37. }
  38.  
  39. //------------------------------------------------------
  40. //
  41. // Below is used to catch any exceptions the object
  42. // might allow by the mouse not being on the object
  43. //
  44. //------------------------------------------------------
  45.  
  46. // Check if the mouse is not positioned over the object
  47. if (!position_meeting(mouse_x, mouse_y, self))
  48. {
  49.  // if the left mouse button is released while not over the object
  50.  if (mouse_check_button_released(mb_left))
  51.  {
  52.   // make sure the box drops
  53.   direction = 270;
  54.   speed = 2;
  55.  }
  56.  // if the right mouse button is released while not over the object
  57.  if (mouse_check_button_released(mb_right))
  58.  {
  59.   // make sure the box drops
  60.   direction = 270;
  61.   speed = 2;
  62.  }
  63. }
Expand to see the code.


Box Move Right/Up
  1. //------------------------------------------------------
  2. //
  3. // Mouse Over and Move Objects on Click
  4. // Location: step event
  5. // Objective: Check if mouse is over object
  6. //            Check which button is being pressed
  7. //            Do what you need to do with that object
  8. // Script Version: 2.0
  9. // Author: RadethDart
  10. //
  11. //------------------------------------------------------
  12.  
  13. // Set the x and y variables of the box (object)
  14. x = box2.x // x position of the box
  15. y = box2.y // y position of the box
  16.  
  17. // Check if the mouse is positioned over the object
  18. if (position_meeting(mouse_x, mouse_y, self))
  19. {
  20.  // if the left mouse button is being pressed while on the box
  21.  if (mouse_check_button_pressed(mb_left))
  22.  {
  23.   // then set the motion to go left (0 degrees = right)
  24.   motion_set(0, 3);
  25.  }
  26.  
  27.  // if the right mouse button is being pressed while on the box
  28.  if (mouse_check_button_pressed(mb_right))
  29.  {
  30.   // then set the motion of the box up (90 degrees = up)
  31.   motion_set(90, 3);
  32.  }
  33.  // if the mouse is not over the object, then force to move down (270 degrees = down)
  34. } else {
  35.   direction = 270;
  36.   speed = 2;
  37. }
  38.  
  39. //------------------------------------------------------
  40. //
  41. // Below is used to catch any exceptions the object
  42. // might allow by the mouse not being on the object
  43. //
  44. //------------------------------------------------------
  45.  
  46. // Check if the mouse is not positioned over the object
  47. if (!position_meeting(mouse_x, mouse_y, self))
  48. {
  49.  // if the left mouse button is released while not over the object
  50.  if (mouse_check_button_released(mb_left))
  51.  {
  52.   // make sure the box drops
  53.   direction = 270;
  54.   speed = 2;
  55.  }
  56.  // if the right mouse button is released while not over the object
  57.  if (mouse_check_button_released(mb_right))
  58.  {
  59.   // make sure the box drops
  60.   direction = 270;
  61.   speed = 2;
  62.  }
  63. }
Expand to see the code.
Thanks a lot:D it works fine:) thanks!
If you need help with anything else, just make another post. I will try to make sure and check back at least once a day. :D
RadethDart wrote:
If you need help with anything else, just make another post. I will try to make sure and check back at least once a day. :D


thanks its alright^^

But I can post a demo of the game. You'll se what I've done. It my very own strategy game.
Sure! Send me a link! I would love to see it. :D
RadethDart wrote:
Sure! Send me a link! I would love to see it. :D


Nice to hear^^ I am uploading now:)

EDIT: Here it is: http://sandbox.yoyogames.com/games/1931 ... -it-2-demo


PS. If your looking for Press It 1, then I think I have it somewhere. I'll find it^^ It doens't work o W vista or 7 though.
Hmm, I can't believe how awesome that game is going to be! Great idea! I am really happy to see that my coding helped you out. :P I noticed that you changed up the code just a little bit to help accommodate what you were trying to achieve. Excellent choice on the music. :3
Thank u very much^^ are you online at skype often?:)
I get on occasionally. I am never at my computer for long periods of time now that I work on a computer all day at work. :P I have to give my eyes a rest sometimes, lol. I get on and check if you are online here and there.
RadethDart wrote:
I get on occasionally. I am never at my computer for long periods of time now that I work on a computer all day at work. :P I have to give my eyes a rest sometimes, lol. I get on and check if you are online here and there.


haha its cool^^ thansk for the help and hope you will enjoy the short demo!
I enjoyed it with every moment! It surprised me when I couldn't play past a few levels...it wasn't fair! :( I was getting into it!

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=75759