getting colors of RectBoxes After changing them programmatically ...

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

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)
:bust_in_silhouette: Reply From: exuin

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

box.modulate worked.
thanks!

kaz3m | 2021-09-09 16:26