2 more bugs in the Inventory system

Move the item defination node to the inventory scene not inside slot, so when the mouse entered in slot, it will emit a signal with its details eg description, and the inventory scene will receive the signal and show the item defination and setup it with the description. I am 100% sure it will work. If you need codes then first give me the full codes of slots and inventory

slots:

extends Control

@onready var icon=$ColorRect/icon
@onready var quantity=$ColorRect/quantity
@onready var detail=$description
@onready var item_name=$description/name
@onready var item_effect=$description/effect
@onready var item_type=$description/type
@onready var usage_pannel=$ui_interaction
# Called when the node enters the scene tree for the first time.
var item=null


func _on_button_pressed():
	if item!=null:
		usage_pannel.visible = !usage_pannel.visible


func _on_button_mouse_entered():
	usage_pannel.visible=false
	detail.visible=true


func _on_button_mouse_exited():
	detail.visible=false
func set_empty():
	icon.texture=null
	quantity.text=""
	
func set_item(new_item):
	item=new_item
	icon.texture = item["texture"] 
	quantity.text=str(item["quantity"])
	item_name.text=str(item["name"])
	item_type.text=str(item["type"])
	if item["effect"]!="":
		item_effect.text=str("+ ", item["effect"])
	else:
		item_effect.text=""

inventory:

extends Control
@onready var grid=$GridContainer
# Called when the node enters the scene tree for the first time.
func _ready():
	Globalinventory.inventory_updates.connect(_update_inv)
	_update_inv()


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _update_inv():
	clear_inventory_grid()
	for item in Globalinventory.inventory:
		var slots=Globalinventory.invetory_slots.instantiate()
		grid.add_child(slots)
		if item != null:
			slots.set_item(item)
		else:
			slots.set_empty() 
func clear_inventory_grid():
	while grid.get_child_count() > 0:
		var child = grid.get_child(0)
		grid.remove_child(child)
		child.queue_free()

and there is the global script which i call in the inventory script:

extends Node
@onready var invetory_slots=preload("res://Scenes/case_slots.tscn")
var inventory =[]
signal inventory_updates
# Called when the node enters the scene tree for the first time.
var player_nod: Node=null
func _ready():
	inventory.resize(6)

func add_item(item):
	for i in range(inventory.size()):
		if inventory[i] != null and inventory[i]["effect"]==item["effect"]and inventory[i]["type"]==item["type"]:
			inventory[i]["quantity"]+=item["quantity"]
			inventory_updates.emit()
			return true
		elif inventory[i]==null:
			inventory[i]=item
			inventory_updates.emit()
			return true
		return false

func remove_item():
	inventory_updates.emit()
func increase_item():
	inventory_updates.emit()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func set_player_ref(player):
	player_nod=player

Slot.gd:

extends Control
signal slot_entered(description)
signal slot_exited

@onready var icon=$ColorRect/icon
@onready var quantity=$ColorRect/quantity
@onready var detail=$description
@onready var item_name=$description/name
@onready var item_effect=$description/effect
@onready var item_type=$description/type
@onready var usage_pannel=$ui_interaction
# Called when the node enters the scene tree for the first time.
var item=null


func _on_button_pressed():
	if item!=null:
		usage_pannel.visible = !usage_pannel.visible


func _on_button_mouse_entered():
        var description = "It is the best tool for mining"
        slot_entered.emit(description)

func _on_button_mouse_exited():
        slot_exited.emit()

func set_empty():
	icon.texture=null
	quantity.text=""
	
func set_item(new_item):
	item=new_item
	icon.texture = item["texture"] 
	quantity.text=str(item["quantity"])
	item_name.text=str(item["name"])
	item_type.text=str(item["type"])
	if item["effect"]!="":
		item_effect.text=str("+ ", item["effect"])
	else:
		item_effect.text=""

Inventory.gd:

extends Control
@onready var grid=$GridContainer
# Called when the node enters the scene tree for the first time.
func _ready():
	Globalinventory.inventory_updates.connect(_update_inv)
	_update_inv()


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _update_inv():
	clear_inventory_grid()
	for item in Globalinventory.inventory:
		var slots=Globalinventory.invetory_slots.instantiate()
		grid.add_child(slots)
		if item != null:
			slots.set_item(item)
		else:
			slots.set_empty()
     slots.slot_entered.connect(_on_slot_mouse_enterted)
 
     slots.slot_exited.connect(_on_slot_mouse_exited)

func _on_slot_mouse_entered(description):
         $ItemDefination.show()
        $ItemDefination.position = get_global_mouse_pos()
        $ItemDefination/Description.text = description 

func _on_slot_mouse_exited():
       $ItemDefination.hide()

func clear_inventory_grid():
	while grid.get_child_count() > 0:
		var child = grid.get_child(0)
		grid.remove_child(child)
		child.queue_free()

It is possible that I made some spelling mistake or tab space mistake because I am on mobile

1 Like

is these 2 lines inside the for?

slots.slot_entered.connect(_on_slot_mouse_entered)

slots.slot_exited.connect(_on_slot_exited)

Yeah, it is

same problem, item description doent come up and the button doesnt reconise the coruser

I think or sure you made some mistakes with codes. Please show the slot and inventory codes screenshot and a screenshot of inventory scene tree

Before screenshot, try to print something when the mouse entered in slot.gd (please do not get bored)


I tried, and nothing happend.
dont worry mate I enjoy coding… even tho im horrible at it XD

Ohh, where is the item defination node in inventory scene? I said you that to move it from slot to inventory

uuuummm… never had one? I was worried that u added it in the inventory script… the description of the items are in the slot scene

1 Like

Ok so move it to inventory (if not working then again send me a screenshot)

1 Like

thank you for your patience with me .
a question: what was your item defination node and what was the description?
$ItemDefination/Description.text = description
I use color rect and use the label for the name and effect and etc

1 Like

It’s just an example, actually I want to say to replace it with your item defination node, what ever you named maybe “description”, I saw in the scene tree of slot (a color rect)

Is it working?

Nope

Try to print something when mouse entered in slot.gd, tell me is it working?

If it’s working then please give me the project (not full), I think just a screenshot is not enough

ok, so even it doesnt print anything in the slots scene but the detail color rect does come up:

func _on_button_mouse_entered():
	print("hello")
	var description = "It is the best tool for mining"
	detail.show()
	slot_entered.emit(description)

func _on_button_mouse_exited():
	slot_exited.emit()
	print("bye")

just added the detail.show() to be sure

give me your email