• Question
  • (SOLVED) how can you delete individual items from groups in game lab

I'm trying to make a game lab thing where collectables are in a group. The group makes it easier to track what I'm trying to do. I want to make it so that if the player touched one of the groups items, it removes the touched item. Each item has its own number id to identify it as well.

Example: items are named collectible1 through collectible7 and if the player touches collectible5, it removes collectible5 only.

groups are treated as an array, so .splice(pos, amount, replace?) is also a viable option, but if your using groups it's probably just best to use the options they give

person I've used that but is there a way to check for the item the player touched?

you'll most likely have to write an iterator to go through all the instances in which groups perform this exact same action but have such a dumb callback that only evaluates to a Boolean so if you want to check a specific instance that same action will be done twice which is indeed very stupid.... i didn't recommend arrays before since i didn't think you'd want a purpose like this... but if you don't care about that then just do something like this

// for reference group: <createGroup> player <p5.Sprite>
for(var g = 0; g < group.length; g++) {
var instance = group[g];
if(player.isTouching(instance)){
// code goes here
break; // this may speed up collisions in some cases but it will be flawed if you have multi-collision encounters 
}
} ```
    Blockyheadman changed the title to (SOLVED) how can you delete individual items from groups in game lab .

    Chat