Skip to content

clone

Clone lifecycle. Three procedures, all working.

clone.onStart() { ... } ✅ # hat
clone.create(target: CloneTarget | str) -> void
clone.delete() -> void
sprite Star {
events.onFlag() {
looks.hide(); # the original stays hidden
}
events.onKey(Key.SPACE) {
clone.create("_myself_");
}
clone.onStart() {
looks.show();
looks.setSize(50);
motion.goTo("_random_");
motion.point(0);
for (i, 30) {
motion.forward(5);
}
clone.delete();
}
}

clone.create takes "_myself_" or another sprite’s name.

This follows Scratch exactly:

Declared Per clone?
Top-level public / private variable No — one copy on the stage
Sprite private variable Yes — each clone gets its own
temp inside a proc No — a mangled global, shared by everything

So per-clone state goes in a sprite member:

sprite Star {
private speed: num = 0; # each clone has its own
clone.onStart() {
speed = 3;
while (true) {
motion.forward(speed);
speed += 0.1;
}
}
}

Scratch caps a project at 300 clones. Past that, clone.create silently does nothing — there is no error, the clone just never starts. Delete clones when they finish.

clone.CloneTarget Value
MYSELF "_myself_"

clone.CloneTarget.MYSELF and "_myself_" compile to the same block. The menu also lists sprite names, so the parameter keeps its | str arm and takes a computed name.