How to prevent change the status of pressed on a checkbutton?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tautologias345
func _on_CheckButton_toggled(button_pressed):
    if button_pressed:

This function is connected with the toggled signal of the checkbutton. But when I click on the checkbutton, this error happens on the debugger:

Stack Overflow (Stack Size: 1024)

:bust_in_silhouette: Reply From: tautologias345

Solved by me!

func _process(delta):
	for i in self.get_children():
		if i is CheckButton:
			if $Label_Status_Valor.get_text() == "STATUS_PENDING_VALUE":
:bust_in_silhouette: Reply From: Inces

Stack overflow means that there is almost endless loop somewhere in code. Setting pressed to false in code triggers toggled signal again, which sets pressed to false and so on. Easiest way out is to use BUTTON_PRESSED signal instead and set_deferred(“pressed”,false). Button_pressed signal should be emitted once on being clicked, button_toggled emits every time its state is changed from pressed to unpressed and vice versa.