Random beginner-question: en-/disable CheckButton

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

Hi everyone,

how can I enable or disable a CheckButton via code? Is there any simple way like “input pickable true/false” I use with collision shapes? I played around with control focus modes but didn’t succeed.

For example: I’d like to have a timer starting when button down / holding down and after a certain time the button shouldn’t react at release anymore. Just as if it was never put down in the first place…

There must be a simple command for that, right?

How about changing the button mask to 0 and restoring it to the previous value to enable it?

Splunk | 2020-11-12 16:20

Hi Splunk, that’s another hint I never thought of, thank you. “Mouse Left” is checked… how could I change “button_mask” to 0 and back on again in code? That wouldn’t be a true/false case, would it? (I am indeed a beginner!)

pferft | 2020-11-12 16:59

:bust_in_silhouette: Reply From: p7f

If you want to disable the button, you can use your_button.disabled = true

Hi p7f,

this leads to the error
Invalid set index ‘disabled’ (on base: ‘GDScriptNativeClass’) with value of type ‘bool’.

I’m not sure what I’m doing wrong here…

pferft | 2020-11-12 15:40

Can you share your code?

p7f | 2020-11-12 15:41


extends CheckButton

var timer

func _ready():
	timer = Timer.new()
	timer.connect("timeout", self, "_on_timer_timeout")

func _on_CheckButton_button_down():
	print("button down / timer started")
	CheckButton.disabled = true

func _on_CheckButton_button_up():
	print("button released / timer stopped")

func _on_timer_timeout():
	print ("Time is up!")

func _on_CheckButton_gui_input(_event):
	if Input.is_action_just_pressed("mousebuttonclick"):
		print ("action just pressed")

func _on_CheckButton_mouse_exited():
	print ("mouse exited")

pferft | 2020-11-12 15:47

you are using CheckButton.disabled. CheckButton is a clase, not a node. If that checkbutton is in your tree, then it should be $CheckButton.disabled

But i guess you want to disable the scene having that script (as the script extends checkbutton), then you should simply call disabled = true

p7f | 2020-11-12 15:54

Thank you! disabled = true indeed works (it appears that sometimes I don’t seem to trust things to be possible in the simplest way…).

(On a sinde note: It’s so weird that $ all too often leads to another error of “Node not found”. I stumble over this all the time and I’m sure I’m not alone. Is it because I’m trying to find the same node I attached the script to? Can I only find different nodes?)

What I see now is that even when disabled the mouse-exited still works. I thought that any input to the node should be completely turned off, say, until I turn it on again. (Just as it works fine with CollisionShapes and input_pickable.) Is there any way to do that?

pferft | 2020-11-12 16:19

I guess the only way to do that woud be, inside the _on_CheckBox_mouse_exited funciton, return if you see the button is disabled… like

func _on_CheckBox_mouse_exited():
    if disabled:

    # do all the stuff here

About the side note, you use $ to find nodes that are children of the node with the script attached. Is like a shortcut of get_node

p7f | 2020-11-12 16:52

It seems much clearer now, thanks a lot! I think I should be able to tweak things with some variables now that I know how to turn the thing off and on : )

$ is only for children then, but I can reach other nodes with their (complete) path or “find node”, right? Addressing the node I work within doesn’t need a “path” to be found, clearly. I need more practice… ; )

pferft | 2020-11-12 17:11

There is a loosly connected issue I’d like to ask you about if you don’t mind. Maybe you’d have an idea I couldn’t think of yet… is there any way to directly send you a message here?

pferft | 2020-11-13 12:56

you can contact me on Twitter (@AzagayaVJ) or discord (azagaya#5894).

p7f | 2020-11-13 14:55