Can you get specific members in a for loop?

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

I want a clean way of getting specific index members in an array during a loop. I want to provide an array of values and have the for loop retrieve the indexes specified by the array. I don’t want to write a massive if statement with a bunch of ORs. Basically like this:

for i in (1,2,3,5,7,9, 18, 19) in get_children():


for i in get_children():
	if i == (1,2,3,5,7,9, 18, 19):

How can I do this?

:bust_in_silhouette: Reply From: exuin
if i in [1,2,3,5,7,9, 18, 19]:

Thanks. For my use case it doesn’t seem to be working.

for i in get_children():
	if i in [0,1,3,5,7,9, 17, 18]: 
		i.visible = true
		i.mouse_filter = 1 

For some reason, nothing becomes visible. Without the if statement, the whole VBoxcontainer becomes visible.

John97 | 2021-04-26 12:30

get_index() fixes this.

John97 | 2021-04-26 12:35

Oh I see, sorry

i is not an index but rather the child node. You should do this or this

for i in get_child_count():
    if i in array:
        var child = get_child(i)

for child in get_children():
    if child.get_index() in array:

exuin | 2021-04-26 12:35