Cloning is a feature that allows a sprite to create a clone, or semi-duplicate, of itself, while the project is running. Clones of a sprite will be the same as the original or parent sprite but as a separate instance. Clones inherit the parent's scripts, costumes, sounds, and properties, yet they can then be modified. There is a limit of 300 clones per project to prevent excessive lagging or crashes, but 301 can be made, as shown by Scratch Team member thisandagain in this project.
Usages for Cloning
Cloning is an essential aspect to many well made games and projects, reducing the number of sprites and scripts needed in a project, and therefore preventing unnecessary lag.
Clones and related blocks can be used in/for:
- Tower Defence games
- Many arcane-style games
- Special effects (e.g. fireworks, snow)
- RNG based projects
- Mouse trails
- Any project needing many repetitive sprites
Create Clone of ()
- Main article: Create Clone of () (block)
create clone of [myself v]
This Stack Block will clone a sprite inside of the project, depending on what was selected in the dropdown menu. Its version in the Scratch Day 2011 prealpha had no dropdown insert to select a sprite.
create clone :: control
It is also possible to clone other clones recursively.
When I Start as a Clone
- Main article: When I Start as a Clone
when I start as a clone
This Hat Block activates when a clone is created. It only runs in the newly created clone, not previous clones, other clones or the parent.
Delete This Clone
- Main article: Delete This Clone
delete this clone
This Cap Block will delete the clone it runs in and stop all of the scripts the clone is running.
Excluding cloning, there are two ways to duplicate a sprite:
Creating a New Sprite
Right click on a sprite in the sprites area or stage, and select "duplicate". Note that costumes, scripts and sounds will also be copied over as well.
Select the duplicate tool (a stamp-like figure) above the stage area and to the left of the presentation buttons. Then click on the sprite you want to be duplicated.
This will make the new sprite appear in the new sprites area with all of the same costumes, scripts and sounds.
Variables marked as "for all sprites" will be the same for each clone, but variables marked as "for this sprite only" will be personalized to each clone, i.e. each clone will have its own value for the variable.
Cloning in Scratch Mods
In Panther-style cloning, a clone inherits its parent's properties but is only a clone of it, not a new sprite. Other sprites can sense the clones, using the Touching ()? block, with the parent as its argument. The code for Panther-style cloning was actually implemented in Scratch 1.4, hinting that it was a planned feature, but wasn't added. Scratch 2.0 uses this style of cloning.
In BYOB-style cloning, a clone is a new sprite in the sprite list, with editable data all of its own. Clones are created with an Operators block "(clone)", which clones a sprite and reports a reference to it, which can then be used to control it.