I need a Timer Node to programmatically press a button after a certain time. What am I doing wrong with .Connect()? Should I even use that?

Godot Version

4.2

Question

Just like the title says, I have a timer that is suppose to trigger the “_on_button_pressed()” function of a button, after a certain time occurs.

Both the timer and button are in the same tree/scene.

^If the above photo doesnt load , here is the code:

@onready var autoTime = 0

func _on_auto_play_timer_timeout():
autoTime += 1
print("autoTime: ", autoTime)

if autoTime % 2 == 0:
	
	texture_button.connect("pressed",_on_button_pressed)

I have done multiple google searches, but no result has actually worked. The godot docs aren’t helpful either.

At one point, I gave up entirely on using code and tried forcing “auto play” with an animation player. That didn’t work, so now I’m back to square 1.

This is not my first time working with signals/connect so IDK why it’s not working now? It has been awhile so maybe I’m just missing something here . . .

I could have sworn the connecting nodes used to be $Node.connect(self,“----”,“—”), but maybe it was changed?

You should use:

texture_button.pressed.connect(_on_button_pressed)

But what is your _on_button_pressed method?

this is godot 4, this kind of 3 arguments of .connect was used for godot 3

this one should work. but this only Connecting your signal to a callable. in which the signal is pressed and the callback is _on_button_pressed
you only need to connect this Once.

if you want to press the button programatically, you just:

texture_button.pressed.emit()

above should work if you already connected the signal to a callable Once

1 Like

Thank you so much. I don’t know if you realize this, but you have literally helped make my dreams come true.
Ty. Honestly.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.