How do I compare clones?

This is my first post so I might not format everything right

(I’m using version 1.19.3)

I’m trying to make a rhythm game, and I’m trying to make it so that only the earliest spawned arrow clone will be removed when the corresponding key is pressed.

I’ve tried using an if statement to see if the clone is the first in the clones array.

if(this.isClone){
    if(this.d){
        this.remove();
    }
    this.y-=tempo/(project.framerate/2);
    if(this.hits(LeftPlayer)){
            if(isKeyJustPressed("a")){
                if(this.n==LeftArrow.clones[0].n){
                    if(Math.abs(this.y-90)<5){
                        score+=10;
                    }
                    else if(Math.abs(this.y-90)<50){
                        score+=5;
                    }
                    else{
                        
                    }
                    this.d=true;
            }
        }
    }
}
else{
    if(songlayout[beatcounter/2]==1){
        this.clone();
        this.n+=1;
        this.clones[this.clones.length-1].n = this.n;
        this.clones[this.clones.length-1].d = false;
    }
}

Rhythm Game3-28-2022_9-49-47.wick (4.6 KB)

Hi @Donut, welcome to the forums!
(That’s a nice username :doughnut: )

Try using “ClipName.clones”

It will return an array of the clones for the object with the “ClipName”

The first clones in the array were spawned earlier than the last ones.

The first clone in the array can be defined as “ClipName.clones[0]”
The last clone in the array can be defined as “ClipName.clones[ClipName.clones.length-1]”
(of course, without the quotation marks)

You can use

if(this === ClipName.clones[0]){
this.remove();
}

to remove the earliest spawned clone.

You’ll probably need to edit the code a bit before implementing it.

Just to add, I’d recommend putting all of your arrow objects in one clip just to make them a bit easier to manage (this is just a suggestion).

Good luck with your project :four_leaf_clover:

1 Like