|
|
|
|
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
Certainly!
extends CheckButton
var timer
func _ready():
timer = Timer.new()
timer.set_wait_time(2)
add_child(timer)
timer.connect("timeout", self, "_on_timer_timeout")
func _on_CheckButton_button_down():
print("button down / timer started")
timer.start()
CheckButton.disabled = true
func _on_CheckButton_button_up():
print("button released / timer stopped")
timer.stop()
func _on_timer_timeout():
timer.stop()
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
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:
return
# 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
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).