0 votes

so i have a series of RectanglBoxes
i update their colors to a random color every time scene loads using this:

func update_colors():
var nodes = get_node("box").get_children()
var num = 0
for box in nodes:

    rng.randomize()
    var current_color = colors_array[rng.randf_range(0, 6)]
    box.modulate = Color(current_color)

then i need to read each of those colors later so i wrote a function like this and its being used in a button click so im sure its after the boxes have been updated and got new random colors

func print_first_10_colors():
var nodes = get_node("box").get_children()
var num = 0
for box in nodes:
    if num < 11:
        var starting_point = box.color
        print( starting_point )
    num += 1

but the output prints same value for all 10 boxes:

0.811765,0.47451,0.47451,1
   0.811765,0.47451,0.47451,1
0.811765,0.47451,0.47451,1
0.811765,0.47451,0.47451,1
0.811765,0.47451,0.47451,1
0.811765,0.47451,0.47451,1
0.811765,0.47451,0.47451,1
0.811765,0.47451,0.47451,1
0.811765,0.47451,0.47451,1
0.811765,0.47451,0.47451,1
0.811765,0.47451,0.47451,1

its printing the old color that each rectabglebox had but not the one after being updated using

box.modulate = Color(some_new_color_value)
Godot version 3.3.stable.official
in Engine by (22 points)

1 Answer

0 votes
Best answer

That's because you're printing the color of the box and not the modulate of the box. Those are two separate properties.

by (7,190 points)
selected by

box.modulate worked.
thanks!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.