I have several items and several slots that can hold items. The item is a Node2D with Area2D attached and the slot is a Position 2D with Area2D attached. I want to check if the slot is filled and then inform the item. If the slot has another item on it, the item cannot be placed in that slot. How can I accomplish this? Here is my current code:
Item:
extends Node2D
var selected = false
var current_rest_point
var last_rest_point
var rest_nodes = []
var empty = true
func _ready() -> void:
rest_nodes = get_tree().get_nodes_in_group("zone")
current_rest_point = rest_nodes[0].global_position
last_rest_point = current_rest_point
rest_nodes[0].select()
func _on_Area2D_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
if Input.is_action_just_pressed("Left Click"):
selected = true
func _physics_process(delta: float) -> void:
if selected:
global_position = lerp(global_position, get_global_mouse_position(), 35 * delta)
look_at(get_global_mouse_position())
else:
global_position = lerp(global_position, current_rest_point, 10 * delta)
rotation = lerp_angle(rotation, 0, 10 * delta)
func _input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and not event.pressed:
selected = false
var shortest_distance = 200
for child in rest_nodes:
var distance = global_position.distance_to(child.global_position)
if distance < shortest_distance:
child.select()
print(child.get_name())
current_rest_point = child.global_position
shortest_distance = distance
Slot:
extends Position2D
var empty = true
func _process(delta: float) -> void:
pass
func _draw():
draw_circle(Vector2.ZERO, 75, Color.blanchedalmond)
func select():
for child in get_tree().get_nodes_in_group("zone"):
child.deselect()
modulate = Color.aquamarine
func deselect():
modulate = Color.whitesmoke
func deselect_last_point():
for child in get_tree().get_nodes_in_group("zone"):
child.deselect()
modulate = Color.webmaroon
func space_check():
if empty == true:
return true
else:
return false
Thanks for the help!!