How to delay Input Action

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

I am making a game where a KinematicBody2D (which has a Sprite in the shape of a paint brush) moves to the new mouse click position. With this click, a Line2D also adds a new point and a line is drawn to the new position.
All this is working, however there is a problem:
Before, I move the KinematicBody2D to the new click position, I have a mouse click on a TouchScreenButton (out of many) to pick up a colour for the Line2D trail. The problem is this press also moves the KinematicBody2D. This is an undesired result. In other words, the press on the TouchScreenButton inserts the colour as well as moves the KinematicBody2D. The press should only collect the colour for the Line2D(and change the value of a flag).
Some part of the code execution must not happen when the click is on a TouchScreenButton. Anywhere else, the click is fine as it moves the KinematicBody2D as required.
I have any an idea that call-deferred may solve the problem. But I am not able to write the correct code for execution of the TouchScreenButton thread only.
Please help.

Here is my code:

extends KinematicBody2D

onready var line = get_node("../line")
var speed = 100
var velocity = Vector2(0,0)
var adjust =Vector2(0, 0)
var old_position
var colour =[false, false, false, false, false, false, false, false, false,false, false, false,false]
var value = Color(0,0,0,0)
var new_position = Vector2(0,0)

func _ready():

func get_input():
	velocity = Vector2()
	old_position = position

	if Input.is_action_pressed("click"):
		new_position = get_local_mouse_position()
		velocity = new_position
	velocity = velocity.normalized() * speed

func _physics_process(delta):
	if velocity != adjust:
		var wide = 5.0
		line.width = wide

		old_position = new_position
func _on_Red1_pressed():
	value = Color(1,0,0,1)

Please notice that in the _ready function, I tried to connect a signal for a call-deferred call. However, I am not able to insert code or function correctly. Maybe, I need a different approach altogether.

:bust_in_silhouette: Reply From: heavyathan

A non-ellegant solution could be check with signals if mouse is over touchscreenbutton:

var not_click =false

func on_TouchScreenButton_mouse_entered():
 not_click =true

func on_TouchScreenButton_mouse_exited()
 not_click =false

And in your input function check if your mouse is out of the button(s)

if Input.is_action_pressed("click") and !not_click:
rest of your code

Notice that I’ve written signals by mind, maybe there are spelling mistakes

Elegant or not, this works.
Thanks a lot.
No Godot inbuilt signal of on_TouchScreenButton_mouse_entered((), so I have used on_TouchScreenButton_pressed()

Thanks again.

ashish | 2021-04-15 09:06