This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-03-21 09:46:21

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

Click-to-move in Scratch

I'm attempting to make a script that when a spot is clicked on the stage the sprite will move to it. It is exactly the same as Warcraft3 where you select a unit, click somewhere, and it moves to it. So far I have the selector working to select single units and tried a code that I thought should have the basic functionality that I am looking for but it always tells the sprite to go to 0,0 and not where I clicked on the stage.
http://tinypic.com/r/ayohlh/6

That is what the code looks like that I thought would work.
The GoTo was initiated by a 'when stage is clicked'
Any help would be appreciated, thanks.

Offline

 

#2 2013-03-21 09:50:56

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Click-to-move in Scratch

You're not moving the mouse to the middle after clicking? Is there perhaps another script sending it ti the middle?

Offline

 

#3 2013-03-21 09:58:59

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

Re: Click-to-move in Scratch

No there isn't I am not on the computer where all my current work is, I wish I could link it all. I actually wasn't using the exact script that I posted. Here is the exact one that I was using http://tinypic.com/r/2zit3tk/6
I'm not sure why I added the extra 'x position of' seems a bit redundant. Maybe that was the problem. It seems to be reading the mouses x and y position as 0,0 all the time with the script that I was actually using. This could have been the problem but I doubt it.

Offline

 

#4 2013-03-21 14:12:22

shadowmouse
New Scratcher
Registered: 2013-02-03
Posts: 100+

Re: Click-to-move in Scratch

It might have something to do with that when you click the mouse, it broadcasts Goto, but then the mouse is still clicked so it broadcasts it again and threfore the script restarts. Could you put what you've done so far on the scratch website please?

Offline

 

#5 2013-03-21 14:29:23

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

Re: Click-to-move in Scratch

Yes, I will in about an hour.

Offline

 

#6 2013-03-21 15:32:56

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

Re: Click-to-move in Scratch

http://tinypic.com/r/vy0ajd/6
There is the picture of the code that works, I figured out the movement, the extra 'x position of' was the problem, or it was just acting weird previously.

I now face the problem of making it look realistic when walking. Here is my first attempt that failed. http://tinypic.com/r/2egenfm/6

Offline

 

#7 2013-03-21 15:36:05

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

Re: Click-to-move in Scratch

My guess is that my attempt with the costume changing's main problem was order of operations.

Offline

 

#8 2013-03-21 17:35:44

troyk
New Scratcher
Registered: 2013-02-06
Posts: 14

Re: Click-to-move in Scratch

Figured it all out!!!! Here are screenshots of all code. Please give credit where credit is due if my code is posted on other forums to answer similar questions or if you will be uploading a game and you found this helpful. I normally wouldn't ask this but I could not find anyone else showing how to do this.

http://tinypic.com/r/10z35w5/6

All I have left to do is figure out how to make proper costume changes so that he faces where he is moving. Also my 'Move' is broadcasted from the stage, 'When Stage is Clicked' 'Broadcast: Move' and the peon that has my green selector around it will move. If anyone wants to see my code for the selector just ask!

Offline

 

Board footer