How can I choose between 2 of the same instances in the code?

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

I am trying to modify Johnnygossdev’s drag and drop script, so that I can use it to have sort of a building spaces, using Area2D draggables and dropzones. I would like to have a draggable with dropzones around, so that I can put another draggable item on one of the dropzones.

Here’s the tutorial I am using:

And here’s the plan:
The plan

Yet it ends up dragging the right scene and then changing the position of the other.

The result

The question is, how can I make it so the code uses the right draggable element? In the tutorial he seems to be using the set_input_as_handled() function but there’s not much about it to be found.
I’ve also thought about using instances but it seems way over my level

Here’s the code, only thing I’ve modified is that I used the dropzone as a child element of the draggable and added a signal for a button release on the dropzone area.

extends Area2D

var previous_mouse_position = Vector2()
var is_dragging = false


func _on_Draggable_input_event(viewport, event, shape_idx):
	
	if event.is_action_pressed("ui_touch"):
		print(event)
		get_tree().set_input_as_handled()
		previous_mouse_position = event.position
		is_dragging = true


func _input(event):
	
	if not is_dragging:
		return
	
	if event.is_action_released("ui_touch"):
		previous_mouse_position = Vector2()
		is_dragging = false
	
	
	if is_dragging and event is InputEventMouseMotion:
		position += event.position - previous_mouse_position
		previous_mouse_position = event.position


func _on_DropZone_input_event(viewport, event, shape_idx):
	if event.is_action_released("ui_touch"):
		global_position = event.position

Thank you for helping.

:bust_in_silhouette: Reply From: lucaslcode

You need to separate the drop zone and the draggable object into separate scenes. If the are in the same scene, they will both move when you move that scene.