Remove clones

Wick editor 1.18

Hi guys, I have some troubles with a project with clones.
My project aims to create clones et makes them move with cos and others stuffs, I want to know if I can delete clones once wick generates them and how i can make that.
I can’t join you the wick project because I’m new here but i let you a part of the code which we talk about.
Thanks for reading me and sorry for my english.

-In Update tab

let fondClone = fond.clone();
fondClone.x = 360;
fondClone.y = 360;

/* RANDOM

for (let y = 60; y < 720; y = y + 60){
for (let x = 60; x < 720; x = x + 60) {
let h = random.float(0, 10);
let carreClone = carre.clone();
carreClone.x = x + h;
carreClone.y = y + h;
}
}

*/

console.log(Math.cos(anim));

var decalage = Math.cos(anim) * 100;
var marge = 0;
for (let y = 60; y < 720; y = y + 60){
for (let x = 60; x < 720; x = x + 60) {
let h = random.float(0, 10);
let carreClone = carre.clone();
carreClone.x = x + decalage + marge;
carreClone.y = y ;
}
marge = marge + 10;
}

anim = anim +1;

-In default tab

anim = 0;

You can tell an object to remove itself by going in it’s update script, seeing if it’s a clone or not, then have it removed if true. Like this:

if(this.isClone){ // If this object is a clone
this.remove(); // Remove this object from the project
}

You can also add an “if” statement in order to make sure that the clone is in a certain condition before removing it.

Another thing

The “anim” variable in the default script is a different “anim” variable than the one in the update script. What you can do instead is have the variable connected to an object, and therefore refer to it through that object, like this:

// Default script
Clip_Name.anim=0;
// Update script
Clip_Name.anim+=1;
1 Like

you can also get an array of all clones of an object with:
this.clones

1 Like

thanks for answers, I’ll be checking that soon, I’m gonna telling you if it works but I think it’s good

1 Like

Hello Wick Editor community,

thank you for all these tips.
Removing the parent clip don’t work, cause we cannot generate clones after that.
Working an a loop for removing all clones with “this.clones” works, but in a weird way.
It only remove one on two clones , but not all of them … Here is an exemple :
http://esac-cambrai.net/A3/square.wick

for (let y = 60; y < 720; y = y + 60){
for (let x = 60; x < 720; x = x + 60) {
let carreClone = carre.clone();
carreClone.x = x ;
carreClone.y = y ;
}
}
for (let i = 0; i < 60; i ++){
carre.clones[i].remove();
}

Is it possible to delete them one by one ?
Thank you for your precious help

I think that something like

for (i = (carre.clones.length -1); i >=0; i–) {
carre.clones[i].remove();
}

should work. Did not tried tough

2 Likes

It works , thank you !