#Help with the return function and setting a color only when a child node is of a certain type

1 messages · Page 1 of 1 (latest)

vale summit
#

Is it possible to check if the child of fore_layers is canvas modulate or colorrectangle before setting it? This is what I currently have
Im not sure exactly how to use the return function but whenever I set "layers" to type array on the function I get an error, same with trying to return as type Object or Node using ->, it says get_child is not a built in function of array despite me being able to run it on its own

dry barn
#

If you want to use a custom function:

if fore_layers[i].get_child_count() > 1 and is_correct_child_type(fore_layers[i]):

func is_correct_child_type(layer):
    if layer is CanvasModulate or layer is ColorRect:
        return true
    return false
vale summit
#

I need the child of fore_layers[i] not forelayers[i] itself, forelayers[i] is an array of canvaslayers

dry barn
#

Oh easy fix

#
if fore_layers[i].get_child_count() > 1 and is_correct_child_type(fore_layers[i]):

func is_correct_child_type(layers):
    for layer in layers:
        if layer is CanvasModulate or layer is ColorRect:
            return true
        return false 
vale summit
#

thank you

vale summit
vale summit
dry barn
#

@vale summit
fore_layers[i] is a canvaslayer right?

#

since i see u setting the follow_viewport_scale property

dry barn
vale summit
#

yes

dry barn
#

Okay give me a minute

#
if fore_layers[i].get_child_count() > 1:
    for child in fore_layers[i].get_children():
        if child is CanvasModulate or child is ColorRect:
            child.color = modulate_setter

@vale summit

#

Is this what ur expecting?

vale summit
#

I believe so, thank you.