Get reference to Clicked Item (in a Group)

I’m trying to Delete an item that is in a group. When an item in the group is clicked I want the selected item to be deleted. I’ve created a group of the items, but how do I get a reference to the clicked item?

To give a better understanding of what I’m trying to achieve. Rather than have a number of separate items that all behave the same (ie. when you click them they are deleted), I have created a group with an onClick event on that group. I am wanting to know how I can delete a single clicked item, rather than deleting the entire group.

1 Like

Ideally I’d do this in CoBlocks, but if I have to use Script that is probably ok (presuming that a script can run in parallel to the CoBlocks)

1 Like

@jandkw99 Hey Jan, I’ve made a little mockup of what you asked; I also explained how it works in the comments of the code, but I’ll explain here aswell, if you add a referral to a child directly into an event;
So like “when child 0 of group deleteItems is clicked, delete child 0 of group deleteItems” then the computer remembers it as such, the problem is it assigns the event to child 0 at the time of assigning, yet remembers the “delete child 0” regardless of the index that item now has. So deleting an item will cause all indexes above it to change but their indexes in the event not.
Solution is luckily quite simple all we have to do is make it into a function, since the parameter of the function will not remember the index of the group but rather the item specifically. So the text for the computer now reads; When [Item] is clicked, delete [Item]. Which will work regardless of its index.
Hope to have helped, and good luck with your game!

Hi Luc,
Thanks for the reply! I actually started thinking about a solution like this in script, but hadn’t yet been able to work it out. Doing it in the CoBlocks is much simpler. But I must say being able to actually access a property for the event click that gives you the individual item would be a nicer solution. Perhaps a feature request for future!

Thanks so much for the effort, this is still a far more elegant solution than having a separate when block per item (there was 20 of them)

2 Likes