How do I press a TouchScreenButton via script?

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

I have a TouchScreenButton that player can press directly. However, I also need it to be periodically pressed by an NPC. I thought it was gonna be as simple as something like $TouchScreenButton.pressed = true, but it doesn’t seem to be like this. I tried to simulate a touch like that:

onready var button = $TouchScreenButton
func bird_button_press():
	var touch =
	touch.position = button.global_position
	touch.pressed = true

but not sure I’m doing it properly andbutton.is_pressed() always returns false. The correct way to do it is probably easy, but I don’t have much experience to tell what’s wrong.

:bust_in_silhouette: Reply From: GlitchedCode

I have 2 options that you can try



to emulate a press assuming your button is hooked up to an input action.

Option 2:
Make sure your signal is connected, even try reconnecting it

is_pressed() just returns whether or not the touchscreenbutton is being pressed or not.
The pressed property is for the pressed texture