Discuss Scratch

MRdido
Scratcher
2 posts

How do I make a sprite go to a random position out of 3 chosen positions?

The only ways I can think of doing it is using a operator that can't use numbers and that just doesn't work.
Darkblade12
Scratcher
100+ posts

How do I make a sprite go to a random position out of 3 chosen positions?

you could try making 2 lists, one containing 3 random x positions and the other containing 3 random y positions. then somehow access those integers with some coding stuffs

when green flag clicked
repeat (3)
add (pick random (-240) to (240)) to [x pos v]
add (pick random (-180) to (180)) to [y pos v]

end
unless you actually want to have the numbers be set, then just get rid of the repeat and add two more add item to list blocks for each list

Last edited by Darkblade12 (Jan. 16, 2019 17:29:52)

T_om
Scratcher
19 posts

How do I make a sprite go to a random position out of 3 chosen positions?

The above script will work if you want constantly different positions each time, but if you want pre-defined positions, you could try an if else if else.

when green flag clicked
set [random v] to (pick random (1) to (3))
if <(random) = [1]> then
go to x: (...) y: (...)
else
if <(random) = [2]> then
go to x: (...) y: (...)
else
if <(random) = [3]> then
go to x: (...) y: (...)
end
end
end

Last edited by T_om (Jan. 16, 2019 19:18:48)

Flipped_
Scratcher
500+ posts

How do I make a sprite go to a random position out of 3 chosen positions?

You could also use custom blocks.
define go to position (position number) of pos1 x: (pos1x) pos1 y: (pos1y) pos2 x: (pos2x) pos2 y: (pos2y) pos3 x: (pos3x) pos3 y: (pos3y)
if <(position number) = [1]> then
go to x: (pos1x) y: (pos1y)
end
if <(position number) = [2]> then
go to x: (pos2x) y: (pos2y)
end
if <(position number) = [3]> then
go to x: (pos3x) y: (pos3y)
end

when trigger started :: events hat
go to position (pick random (1) to (3)) of pos1 x: () pos1 y: () pos2 x: () pos2 y: () pos3 x: () pos3 y: ()
This might seem unnecessarily complicated, but it allows you to use a single block to pick a random position between the 3 positions you specify. This might help you be more efficient and compress your code.
I hope I helped you
CreativeCoder8
New Scratcher
4 posts

How do I make a sprite go to a random position out of 3 chosen positions?

I use scratch.mit.edu which keeps updating and ruining everyones understanding of it, and am trying to make a game that involves clones of a sprite falling from random positions at the top of the screen without changing the y position, i can't figure out custom blocks and I need a way to set the x position to a random number without changing the y position, please help.
semmiesem9
Scratcher
100+ posts

How do I make a sprite go to a random position out of 3 chosen positions?

CreativeCoder8 wrote:

I use scratch.mit.edu which keeps updating and ruining everyones understanding of it, and am trying to make a game that involves clones of a sprite falling from random positions at the top of the screen without changing the y position, i can't figure out custom blocks and I need a way to set the x position to a random number without changing the y position, please help.
This is an old topic, so in the future please make your own new topic for your problems rather than commenting on existing topics.

But to have a certain y with a random x just do this:
go to x: (pick random (-240) to (240)) y: (180)

Powered by DjangoBB