Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Randomly choosing between 4 set coordinates
- DIUUAcod1ng
-
7 posts
Randomly choosing between 4 set coordinates
I've been busy working on a school project and I was wanting to have my sprite to go to a random selection of 1 of 4 coordinates, can someone please help me?
- DIUUAcod1ng
-
7 posts
Randomly choosing between 4 set coordinates
This is my game so far https://scratch.mit.edu/projects/729077638
- nsuarezl26
-
17 posts
Randomly choosing between 4 set coordinates
You can have a list that has all of the coordinates (one list has to be the x coordinates and the other the y coordinates) and then make this script.
- deck26
-
1000+ posts
Randomly choosing between 4 set coordinates
But if you want the corresponding x and y values set a variable to the random number and use that for both lists. The script above will give you an x value randomly selected from the list and a similar, but unrelated, y value. You can have a list that has all of the coordinates (one list has to be the x coordinates and the other the y coordinates) and then make this script.
- nsuarezl26
-
17 posts
Randomly choosing between 4 set coordinates
But if you want the corresponding x and y values set a variable to the random number and use that for both lists. The script above will give you an x value randomly selected from the list and a similar, but unrelated, y value. You can have a list that has all of the coordinates (one list has to be the x coordinates and the other the y coordinates) and then make this script.
Yeah i forgot about that
I fixed it

Last edited by nsuarezl26 (Sept. 19, 2022 15:21:23)
- DIUUAcod1ng
-
7 posts
Randomly choosing between 4 set coordinates
Thank you. I will see if this works
- nsuarezl26
-
17 posts
Randomly choosing between 4 set coordinates
Thank you. I will see if this works
Just make sure to use the fixed version.
- DIUUAcod1ng
-
7 posts
Randomly choosing between 4 set coordinates
To add the coords to the list do I just use the the add to list block?
- DeveloperTools
-
100+ posts
Randomly choosing between 4 set coordinates
Yep! you can also show the list and then click the “+” button to manually add one. To add the coords to the list do I just use the the add to list block?
- DIUUAcod1ng
-
7 posts
Randomly choosing between 4 set coordinates
Thank you all for the help! I decided to use that original design but change the 1-4 to a 1-2 because I had two coords in the x list and y list each. This also fixed the problem of it occasionally 0 0 which I didn't want. Will credit you all when I'm done.
- RT_Borg
-
1000+ posts
Randomly choosing between 4 set coordinates
Hi DIUUAcod1ng,
If you only have a small number of coordinate choices, lists are more than you need. You can just do (for the 4 point version):
I hope this helps. Happy to answer any questions.
– RT_Borg
If you only have a small number of coordinate choices, lists are more than you need. You can just do (for the 4 point version):
I hope this helps. Happy to answer any questions.
– RT_Borg
- DIUUAcod1ng
-
7 posts
Randomly choosing between 4 set coordinates
I was too lazy to change the code but I decided to add sharks which if killed would get points deducted so I'll use this basic layout RT_Borg
- Discussion Forums
- » Help with Scripts
-
» Randomly choosing between 4 set coordinates