Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Too many clones
- Larry_teh_Lobster
-
Scratcher
13 posts
Too many clones
I'm making a Bee Swarm Simulator fan game and when working on hives I've ran into an issue.
The sprite Open Slots is supposed to appear in untaken slots that are neighboring Taken slots. The problem? Some slots go off the hive, and with 2 or more bees, 1000s of clones are created.
https://scratch.mit.edu/projects/1256668940/
someone please help!
The sprite Open Slots is supposed to appear in untaken slots that are neighboring Taken slots. The problem? Some slots go off the hive, and with 2 or more bees, 1000s of clones are created.
https://scratch.mit.edu/projects/1256668940/
someone please help!
- 10goto10
-
Scratcher
1000+ posts
Too many clones
I’ve been calling this a pitfall (it’s #9 in my studio of pitfalls). Clones execute events.
All clones will execute the “when backdrop switches to the hive” event.
Usually people will create a variable “IsClone?”. Then set it to false in a green flag script and set it to true in a “when I start as a clone” script.
In the “when backdrop switches to the hive” you would start out with an if statement to test the IsClone? value and only let the sprite itself execute that script.
All clones will execute the “when backdrop switches to the hive” event.
Usually people will create a variable “IsClone?”. Then set it to false in a green flag script and set it to true in a “when I start as a clone” script.
In the “when backdrop switches to the hive” you would start out with an if statement to test the IsClone? value and only let the sprite itself execute that script.
- Ak0420
-
Scratcher
21 posts
Too many clones
You should make a variable called clones that tracks how many clones you are making. Then make if when I start a clone if clones greater than (how many clones you want) delete this clone. Hope it helps!
- Arvionyx
-
New Scratcher
40 posts
Too many clones
A tip is make sure that the clones are not creating clones of themself as it will cause immense lag and sometimes you will end up with clones multiplying themselves until they reach the clone limit.
- xylidine
-
New Scratcher
100+ posts
Too many clones
Usually people will create a variable “IsClone?”. Then set it to false in a green flag script and set it to true in a “when I start as a clone” script.
In the “when backdrop switches to the hive” you would start out with an if statement to test the IsClone? value and only let the sprite itself execute that script.
Here is a scratchblocks visualization in case you don't understand what 10goto10 meant:
Make sure the variable is local (for this sprite only)
when green flag clicked
set [isClone? v] to [false] //sets the variable to false for the og sprite
when I start as a clone
set [isClone? v] to [true] //sets the variable to true for all clones
when backdrop switches to [hive v]
if <(isClone?) = [false]> then //identifies if any clones or the og sprite have the variable set to false
your script here
end
The ‘isClone’ variable is basically a tag that helps you find out whether you're dealing with a clone or the original sprite. With local variables, you can make each clone have its own value of the same variable. With CloneID, you can control each clone individually.
You don't always need the name of the variable to be ‘isClone’, but make sure the og sprite and the clones don't have the same value.
Last edited by xylidine (Dec. 19, 2025 00:05:41)
- MarioManX
-
Scratcher
7 posts
Too many clones
You could try stamping the clones with the pen extension every frame instead of using clones.
- Discussion Forums
- » Help with Scripts
-
» Too many clones