checkbox node returned irregular output while running

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

I have created spatial node and add checkbox node to it. i have attached following script to the spacial

func _process(delta):

if $CheckBox.pressed==false:
	print("True")
else:
	print("false") 

output result when box is checked
true
true
true

output result when box is unchecked
true
false
true
false

output of unchecked box must be false right?
why i am getting both, i am using godot v3.4

I had a similar problem for a while. this may be due to the initial state “$CheckBox.pressed”.

ramazan | 2021-12-21 09:09

:bust_in_silhouette: Reply From: spaceyjase

Surely you want toggled here and not pressed; pressed is emit when both pressed and toggled - the user will always press the checkbox to toggle its values. Toggled has the new state as a parameter.

Note the documentation: BaseButton — Godot Engine (stable) documentation in English