Godot Version
4.5.1
Question
So I’m currently making an inventory system, but the problem is that for my items, I simply duplicate the items in the editor (Creating Item and Item2) but the problem with this is that my code specifically references just Item, which means that Item2 is completely unaffected. My other problem is that when the mouse enters the item, a variable is set (Shown below) but because both items have the same script, if the mouse is in Item2, Item will be teleported. Help?
Inventory Slot code (Sorry for bad formatting, I dunno how to do it with the colors)
class_name InventorySlot extends Area2D
var is_in = 0
var mouse_is_in = 0
@export var Itemz: Array[Node] = [$"../Item", $"../Item2"]
@export var Item_textures: Array[Node] = [$"../Item2/item_base_texture", $"../Item/item_base_texture"]
#Detects when item enters
func _on_area_entered(area: Area2D) -> void:
is_in += 1
# Detects when item exits
func _on_area_exited(area: Area2D) -> void:
is_in = 0
#Moves the item into the slot
func _process(_body) -> void:
if is_in == 1:
if !Input.is_action_pressed("Click"):
print("if works")
is_in = 0
$Item_texture.texture = $"../Item/item_base_texture".texture
$"../Item".visible = false
#Script to take item out of slot
if mouse_is_in == 1:
if Input.is_action_pressed("Click"):
# $"../Item".visible = true
$Item_texture.texture = null
$"../Item".visible = true
#Does nothing rn
func _ready() -> void:
pass
#Detects if the mouse enters
func _on_area_mouse_exited(area: Area2D) -> void:
mouse_is_in = 0
#Detects when the mouse exits
func _on_area_mouse_entered(area: Area2D) -> void:
mouse_is_in += 1
Item code (I dunno why this formatted and not the other, sorry)
class_name Item extends Node2D
var mouse_is_in = 0
@onready var item:= $"../Inven_Slot"
# Nothing rn
func _ready() -> void:
print(mouse_is_in)
# Moves it to the mouse when clicked
func _process(_delta) -> void:
if mouse_is_in == 1:
if Input.is_action_pressed("Click"):
$"../Item".global_position = get_global_mouse_position()
#Detects if the mouse enters
func _on_area_2d_mouse_entered() -> void:
mouse_is_in += 1
#Detects when the mouse exits
func _on_area_2d_mouse_exited() -> void:
mouse_is_in = 0