0 votes

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

Godot version 3.4
in Engine by (12 points)

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

1 Answer

0 votes

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: https://docs.godotengine.org/en/stable/classes/class_basebutton.html#signals

https://docs.godotengine.org/en/stable/classes/class_basebutton.html#signals

by (1,142 points)
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.