Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » how do you move a sprite to choices of random positions ?
- SweetyBubbles
-
Scratcher
100+ posts
how do you move a sprite to choices of random positions ?
so, I'm trying to make a game, where there's a sprite, who goes to a random position.
but that's not my problem.
I need the sprite to go to a random spot, but I choose which places they can go.
Usually, we use this block:
but, I need this one to be like, I don't know how to explain xD so it goes to a random position I had already chosen. like, there's a ball. this ball can go anywhere it'd like to go. although, they only have limits for where they can go;
but it doesn't seem to work! can anyone help me how to do this with a block demonstration or a project?
thanks so much ! I appreciate you reading all down here, because I have a game to finish hehe.
but that's not my problem.
I need the sprite to go to a random spot, but I choose which places they can go.
Usually, we use this block:
go to [random postion v]
but, I need this one to be like, I don't know how to explain xD so it goes to a random position I had already chosen. like, there's a ball. this ball can go anywhere it'd like to go. although, they only have limits for where they can go;
<<x: 23 y: -52 > or <x: -125 y: 12 >>
but it doesn't seem to work! can anyone help me how to do this with a block demonstration or a project?
thanks so much ! I appreciate you reading all down here, because I have a game to finish hehe.
- EpicGhoul993
-
Scratcher
1000+ posts
how do you move a sprite to choices of random positions ?
Store the x and y positions in a list, then pick a random one.
- deck26
-
Scratcher
1000+ posts
how do you move a sprite to choices of random positions ?
Use a list for the x positions and a separate list for the corresponding y positions. If each list has 5 values set a variable to a random number 1 to 5 and then go to that position.
go to x: (item (myvar) of [xlist v] :: list) y: (item (myvar) of [ylist v] :: list)
- SweetyBubbles
-
Scratcher
100+ posts
how do you move a sprite to choices of random positions ?
Store the x and y positions in a list, then pick a random one.hm, can you show me the code from turbowarp?
- SweetyBubbles
-
Scratcher
100+ posts
how do you move a sprite to choices of random positions ?
Use a list for the x positions and a separate list for the corresponding y positions. If each list has 5 values set a variable to a random number 1 to 5 and then go to that position.ah, I'll try that! thanks!go to x: (item (myvar) of [xlist v] :: list) y: (item (myvar) of [ylist v] :: list)
- jD2R
-
Scratcher
24 posts
how do you move a sprite to choices of random positions ?
Can you just use a pick random block within the selected positions?
go to x: (pick random (x1) to (y1)) y: (pick random (x2) to (y2))
- The_Imaginarium
-
Scratcher
1000+ posts
how do you move a sprite to choices of random positions ?
Can you just use a pick random block within the selected positions?No because the OP want the random choice between two specific positions.go to x: (pick random (x1) to (y1)) y: (pick random (x2) to (y2))
- ---raspberryy
-
Scratcher
2 posts
how do you move a sprite to choices of random positions ?
hmm, good question! I think this would work: make a sort-of rectangle, that serves as a wall. make the rectangle the same color as the backdrop, and name it, say, “barrier”. then go into the ball spite, and go:
so that you can almost move back a step when it touches the barrier. idk if ANY of that made sense, I'm very bad at explaining!
<touching [barrier v] ?>then
move ()-1 steps
so that you can almost move back a step when it touches the barrier. idk if ANY of that made sense, I'm very bad at explaining!

- legendary34678
-
Scratcher
1000+ posts
how do you move a sprite to choices of random positions ?
If you want to make the sprite move to one of two preset positions, you could create a variable to keep track of which position it'll teleport to (let's call this variable “Position”). Before it teleports, let's say you have 2 preset positions. So, you'd set Position to either 1 or 2. Then, have two if loops so that if Position is 1, go to x: 10 and y: -203 and if Position is 2, go to x:0 and y:0 (for example). You can add more if loops and coordinates as necessary (but it may get lengthy if you have lots of positions).
If you didn't understand my very confusing explanation, here's what I meant:
Hope this helped!
If you didn't understand my very confusing explanation, here's what I meant:
set [Position v] to (pick random (1) to (2))
if <[(Position)] = [1]> then
go to x: (10) y: (-203)
end
if <[(Position)] = [2]> then
go to x: (0) y: (0)
end
Hope this helped!
- SweetyBubbles
-
Scratcher
100+ posts
how do you move a sprite to choices of random positions ?
If you want to make the sprite move to one of two preset positions, you could create a variable to keep track of which position it'll teleport to (let's call this variable “Position”). Before it teleports, let's say you have 2 preset positions. So, you'd set Position to either 1 or 2. Then, have two if loops so that if Position is 1, go to x: 10 and y: -203 and if Position is 2, go to x:0 and y:0 (for example). You can add more if loops and coordinates as necessary (but it may get lengthy if you have lots of positions).wow! I think this'll work among the others. thank you so much!
If you didn't understand my very confusing explanation, here's what I meant:set [Position v] to (pick random (1) to (2))
if <[(Position)] = [1]> then
go to x: (10) y: (-203)
end
if <[(Position)] = [2]> then
go to x: (0) y: (0)
end
Hope this helped!
- SweetyBubbles
-
Scratcher
100+ posts
how do you move a sprite to choices of random positions ?
thank you to everyone, I appreciate your effort to help me with this situation :')
- Discussion Forums
- » Help with Scripts
-
» how do you move a sprite to choices of random positions ?






