Discuss Scratch

A-MARIO-PLAYER
Scratcher
1000+ posts

"Delete All Clones" block

I am making a Scratch mod with some more blocks, including some clone blocks. I am trying to add a block like this:
delete all clones::control
^^ Does exactly what it says on the tin.
How do I even program the block anyways? I was able to program stuff such as a true/false block and even a turbo mode boolean block, but when I tried to create the delete all clones block, it either does nothing or throws an infinite error loop..
ThisIsTemp1
Scratcher
1000+ posts

"Delete All Clones" block

Doesn't

delete this clone

delete all clones, if not using clone id?

Last edited by ThisIsTemp1 (Aug. 27, 2024 20:48:31)

A-MARIO-PLAYER
Scratcher
1000+ posts

"Delete All Clones" block

ThisIsTemp1 wrote:

(#2)
delete all clones, if not using clone id?
uhh this isnt the clone id suggestion this is about scratch 3 modding. yes you could make clone ids in scratch 3 mods but i dont have time to do that since it would involve modifying a bunch of code in the scratch-vm
meunspeakable
Scratcher
100+ posts

"Delete All Clones" block

There is an easy workaround
When the “delete all clones” broadcast is sent, all clones will be deleted.
when I receive [delete all clones v]
delete this clone

BigNate469
Scratcher
1000+ posts

"Delete All Clones" block

meunspeakable wrote:

There is an easy workaround
When the “delete all clones” broadcast is sent, all clones will be deleted.
when I receive [delete all clones v]
delete this clone

They're not asking about inside a Scratch project, they're making a mod and want to know how to do that in a single block.
Maximouse
Scratcher
1000+ posts

"Delete All Clones" block

The “delete this clone” block is implemented like this:
deleteClone (args, util) {
    if (util.target.isOriginal) return;
    this.runtime.disposeTarget(util.target);
    this.runtime.stopForTarget(util.target);
}
To delete all clones, you will need to do the same thing as above, but for every clone, not just the one running the block. The code could look like this (not tested):
deleteAllClones (args, util) {
    const clones = util.target.sprite.clones;
    for (let i = clones.length - 1; i >= 0; --i) {
        // iterating backwards because disposeTarget() removes the clone from the array
        if (clones[i].isOriginal) continue;
        this.runtime.stopForTarget(clones[i]);
        this.runtime.disposeTarget(clones[i]);
    }
}

Powered by DjangoBB