Can't destroy sprites using get in a group

Trying to destroy baddies in remix of show examples in game lab of group → get(i) example.

See screen if I take out line 30 temp.destroy(); I can set the animation fine. However, if I try and destroy the sprite being accessed via the index, I get an error in the setAnimation line above, which is weird.
27 for (var i = 0; i < 50; i++) {
28 var temp = mgroup.get(i);
29 temp.setAnimation(“sax”);
30 temp.destroy();}

// Stay cool! Keep all the bad vibes from getting you down.
// Uses createGroup to make a bunch of bouncing baddies,
// createEdgeSprites to make sure the baddies don’t just fly off.

var cool = createSprite(200, 200);
cool.setAnimation(“kidportrait_05_1”);
cool.scale = 0.15;
createEdgeSprites();
var mgroup = createGroup();

for (var i = 0; i < 100; i++) {
var sprite = createSprite(randomNumber(0, 400), randomNumber(0, 100), 10, 10);
sprite.velocityY=randomNumber(5, 10);
sprite.velocityX=randomNumber(-5, 5);
sprite.bounciness = 1;
mgroup.add(sprite);
}

mgroup.setAnimationEach(“gameplaywacky_01_1”);
mgroup.setScaleEach(0.25);

function draw() {
background(“white”);
drawSprites();
cool.x = World.mouseX;
cool.y = World.mouseY;
for (var i = 0; i < 50; i++) {
var temp = mgroup.get(i);
temp.setAnimation(“sax”);
temp.destroy();

}
mgroup.bounceOff(cool);
mgroup.bounceOff(bottomEdge);
mgroup.bounceOff(topEdge);
mgroup.bounceOff(leftEdge);
mgroup.bounceOff(rightEdge);
}

I did it a different way. I was really trying to get the good guy to vacuum up all the badies. This worked.
if (mouseIsOver(mgroup.get(j))) {
mgroup.get(j).destroy();

Not sure why the other way should not work but if you try to do an isTouching test between the current member of the group and the “good guy”, you get an error (can only check overlap between groups or sprites.

Looks like you found a workaround… these kinds of issues are hard to debug with just a screenshot of the code. If you want someone to look closer, please send us a shared link.

Good luck with your game!

thanks,

Mike