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

#1 2012-11-25 00:02:18

froggy12
New Scratcher
Registered: 2012-11-24
Posts: 2

using "pick_random"

How can i make a sprite move left or right randomly, but by the same amount of steps, after hitting an object. So that it will continue on the same path whilst travelling down the stage.

Offline

 

#2 2012-11-25 09:31:59

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: using "pick_random"

point in direction (((pick  random (0) to (1)) * (180)) - (90))//either 90 or -90
repeat until <touching [something v]?>
move (10) steps

Last edited by joefarebrother (2012-11-25 09:32:49)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#3 2012-11-25 09:39:31

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: using "pick_random"

joefarebrother wrote:

point in direction (((pick random (0) to (1)) * (180)) - (90))//either 90 or -90
repeat until <touching [something v]?>
move (10) steps
end

Fixed, though I think froggy12 wants the random movement to start after the sprites hits an object, in which case another block is needed:

wait until <touching [something v]?>
point in direction (((pick random (0) to (1)) * (180)) - (90))//either 90 or -90
repeat until <done?>
move (10) steps
end

I hope that this helps!

Last edited by ErnieParke (2012-11-25 09:41:32)


http://i46.tinypic.com/35ismmc.png

Offline

 

#4 2012-11-25 13:18:43

froggy12
New Scratcher
Registered: 2012-11-24
Posts: 2

Re: using "pick_random"

Thanks for your help I was in brain lock.

Offline

 

#5 2012-11-25 13:41:19

curiouscrab
Scratcher
Registered: 2012-06-25
Posts: 100+

Re: using "pick_random"

ErnieParke wrote:

joefarebrother wrote:

point in direction (((pick random (0) to (1)) * (180)) - (90))//either 90 or -90
repeat until <touching [something v]?>
move (10) steps
end

ErnieParkie wrote:

Fixed, though I think froggy12 wants the random movement to start after the sprites hits an object, in which case another block is needed:

wait until <touching [something v]?>
point in direction (((pick random (0) to (1)) * (180)) - (90))//either 90 or -90
repeat until <done?>
move (10) steps
end

I hope that this helps!

curiouscrab wrote:

Don't you mean

point in direction (((pick random (0) to (1)) * (180)) - (90))//either 90 or -90
repeat until <touching [something v]?>
move (10) steps
end

Fixed, though I think froggy12 wants the random movement to start after the sprites hits an object, in which case another block is needed:

wait until <touching [something v]?>
point in direction (((pick random (0) to (1)) * (180)) - (90))//either 90 or -90
repeat until <touching [other thing v]?>
move (10) steps
end
?

Last edited by curiouscrab (2012-11-25 13:42:31)


http://i50.tinypic.com/dopbtw.png

Offline

 

#6 2012-11-25 14:37:24

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: using "pick_random"

ErnieParke wrote:

joefarebrother wrote:

point in direction (((pick random (0) to (1)) * (180)) - (90))//either 90 or -90
repeat until <touching [something v]?>
move (10) steps
end

Fixed

umm... in what way was that fixed? It looks the exact same as how I had it.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#7 2012-11-25 14:43:01

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: using "pick_random"

joefarebrother wrote:

ErnieParke wrote:

joefarebrother wrote:

point in direction (((pick random (0) to (1)) * (180)) - (90))//either 90 or -90
repeat until <touching [something v]?>
move (10) steps
end

Fixed

umm... in what way was that fixed? It looks the exact same as how I had it.

I fixed it two ways:

1). You forgot to put end after the [move (10) steps] block.
2). I had fixed the pick random number block, though you had already fixed that before I had posted this, so it was a bit of an outpost.


http://i46.tinypic.com/35ismmc.png

Offline

 

#8 2012-11-25 15:23:36

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: using "pick_random"

curiouscrab wrote:

ErnieParke wrote:

curiouscrab wrote:

Don't you mean

point in direction (((pick random (0) to (1)) * (180)) - (90))//either 90 or -90
repeat until <touching [something v]?>
move (10) steps
end

Fixed, though I think froggy12 wants the random movement to start after the sprites hits an object, in which case another block is needed:

wait until <touching [something v]?>
point in direction (((pick random (0) to (1)) * (180)) - (90))//either 90 or -90
repeat until <touching [other thing v]?>
move (10) steps
end
?

No, I didn't mean that because, as far as I can see, froggy12 never mentioned when (s)he wanted the sprite to stop moving.


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer