I'm trying to make the clock (label) change color to random when clicked.

extends Label 

# Called when the node enters the scene tree for the first time.
func _ready():
	pass

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	var time = Time.get_time_dict_from_system()
	$".".text = str(time.hour) + ":" + str(time.minute) + ":" + str(time.second)
	
	
	
func _input(event):
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
			$".".add_theme_color_override("font_color", Color((randi() % 255), (randi() % 255), (randi() % 255)))
			print($".".get_theme_color("font_color"))

judging by what print() outputs, everything works, and I get 3 random numbers in the range from 0 to 255, but the color does not change.

at the same time, if I enter any 3 numbers myself instead of randi(), the text color will successfully change after clicking.
$".".add_theme_color_override("font_color", Color((randi() % 255), (randi() % 255), (randi() % 255))) -> $".".add_theme_color_override("font_color", Color((100, 41, 96))

what is the problem?

    psinax make sure that randi() is returning your color correctly.. do some print statements before and after..

    psinax Color components are expected to be floating point numbers in 0.0-1.0 range, not integers in 0-255 range.

    psinax randi() % 255

    In addition to the above replies, if you're using Color8(), use % 256. not % 255. The latter returns a value between 0 and 254, inclusive. (In this situation, the difference doesn't really matter.)

    When randomly generating colors, there's no benefit whatsoever in using Color8. It just makes your code longer and (a tiny bit) slower. Simply use Color(randf(), randf(), randf())

    most colors are either bright or darg, so just going randf is pointless.. many times will be that the color is barely changed..

    For a quick gains this enough but for real artsy thing you need a proper color management function, that takes into account contrasting colors, harmonics and etc..

    • xyz replied to this.

      kuligs2 I was just comparing randf() vs. randi()%256. From purely artistic perspective, of course they are exactly the same. But that was not the issue here.

      Using any kind of RGB or even HSL(V) is near useless for generating pleasing looking color combinations. You need to operate at least in Lab color space, and preferably in something even more perceptually stable like OKHSL