Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » dyanmically preventing sprites from spawning on another sprite
- wavewavegame
-
26 posts
dyanmically preventing sprites from spawning on another sprite
i have this project and i want the sprites to not spawn on top of eachother, is there any way to implement this?, the solution i have is currently not working
https://scratch-mit-edu.ezproxyberklee.flo.org/projects/1136380670/
i dont want any brute force solution
https://scratch-mit-edu.ezproxyberklee.flo.org/projects/1136380670/
i dont want any brute force solution
Last edited by wavewavegame (Feb. 19, 2025 23:30:42)
- p-p-p-p-p-p-p-p-p-p-
-
1000+ posts
dyanmically preventing sprites from spawning on another sprite
you could place sprites one by one, and then make sure each one is not touching any of the ones before it, or you could just do the math in a list and make sure that the distance between any two spawn points is a certain ammount.
Idk what you mean by “i dont any brute force solution” because if you want the spawn points to be truly random, you can't not “brute force” this kind of situation.
Idk what you mean by “i dont any brute force solution” because if you want the spawn points to be truly random, you can't not “brute force” this kind of situation.
- 10goto10
-
500+ posts
dyanmically preventing sprites from spawning on another sprite
I wonder if it is a race condition between building the list of sprite names and checking for overlap. every one of your sprites deletes and creates the sprites list and also starting with a green flag are the scripts in each sprite that check for overlap. There is some chance that length of the sprites list will be zero when one of the main scripts with the testing is started.
What you might try is just having the sprite list built one time, then having that script end with a broadcast to “start main”, and then have your current “start with a green flag” scripts ( the ones that place and move the sprites) start with a “when I receive start main” block.
And I never miss an opportunity to mention my Pitfalls studio for reference because this looks like number 11 in that studio.
What you might try is just having the sprite list built one time, then having that script end with a broadcast to “start main”, and then have your current “start with a green flag” scripts ( the ones that place and move the sprites) start with a “when I receive start main” block.
And I never miss an opportunity to mention my Pitfalls studio for reference because this looks like number 11 in that studio.
- wavewavegame
-
26 posts
dyanmically preventing sprites from spawning on another sprite
I mean i dont want to make a really big or statement with every other sprite you could place sprites one by one, and then make sure each one is not touching any of the ones before it, or you could just do the math in a list and make sure that the distance between any two spawn points is a certain ammount.
Idk what you mean by “i dont any brute force solution” because if you want the spawn points to be truly random, you can't not “brute force” this kind of situation.
- RokCoder
-
1000+ posts
dyanmically preventing sprites from spawning on another sprite
You have six sprites with identical code but different costumes - there's no reason not to use clones here. Duplicating code is rarely a good idea.
if they were all clones of the same sprite, brut forcing wouldn't involve any OR statements.
if they were all clones of the same sprite, brut forcing wouldn't involve any OR statements.
when I start as a clone
set position
define set position // Non-refresh custom block
show
go to [random position v]
repeat until <not <touching (thisSpriteName)?>> // Where thisSpriteName is set to the name of this sprite
go to [random position v]
- Discussion Forums
- » Help with Scripts
-
» dyanmically preventing sprites from spawning on another sprite