how to check the variable of an object in an array

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

so, i have an array of some scenes (gun attachments).
i want to know if the new attachment iam adding to my gun has the same type of an already existing attachment.
to do so, i must check the type of the new attachment against the type of all the already existing attachments. problem is, i dont know how to access/check the value of a variable of an object in an array.

#if module.type == modlist.objectA.type:

> do this

where module is the new attachment
modlist is the array
objectA is one of the attachments already in the array

:bust_in_silhouette: Reply From: nuclearatomic

Lol. literally 5 minutes later i figured it out. iam gonna keep this post up in case anyone else runs into a similar problem:
first, we need a loop that runs an equal number to the array size:
for i in array.size()
then, we can pass i to the array to check each individual object in it and ask for the variable:
so something like this:
for i in modlist.size():
if module.type == modlist[i].type :
do this

:bust_in_silhouette: Reply From: zhyrin

If you don’t need the array index, you can also iterate like so:

var new_module
for existing_attachment in modlist:
    if new_module.type == existing_attachment.type