Finding resource "Item" in an array.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By anaccount1299

I’m trying to make some sort of basic item pickup system but I’m not sure how to approach the way I want it to work.

I have a VBoxContainer full of instanced scenes (which are just labels with scripts), each label is assigned a certain item on instancing (selected from item group) and when I click on the label I want it to tell me the exact index that item is in, in the item group.

Every item a label gets assigned it is from an array in my Interaction script (the item group), right now I’m just doing items.find(item) (items being the item group) but if I have multiple of the same items like 2 apples then it will return the first apple it finds, not the one that is assigned to the label

Example:
Items array has 3 apples, they are each assigned to 3 labels I click on the third label and search for the item assigned to it using items.find(item) and .find returns the first apple I want it to return the index of the label I selected.

How would I go about getting the correct item?

:bust_in_silhouette: Reply From: Magso

each label is assigned a certain item on instancing

Here you can give the label the index so you can use items[index] instead of using find()

Is there any way to make each instanced resource special?

anaccount1299 | 2020-10-30 17:31

Oh I think I did it how I want, instead of adding the item resource directly to my item_group array I made a new dictionary and added the item to that then added it to the array and now each one is special and I can just do items.find(item) :smiley:

here is a pic if anyone cares
Imgur: The magic of the Internet

anaccount1299 | 2020-10-30 18:31