This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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 (8,580 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 Frequently asked questions and 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 [email protected] with your username.