2 more bugs in the Inventory system

Godot Version

4.2.1

Question

I’m making an inventory system which and it should work based on the tutorial, but there are 2 bugs: 1 that only one type of item gets added to the inventory. and 2 that the slot button doesnt work in the inventory UI. for example when the cursor goes on the button, item deffination should come up and it does in the slot scene:


but not in the inventory UI scene:

I tried a couple of things, like instead of mouse entering the button i used the area2D which it did kinda work but it was glitchy:

here are the slots scene code:

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=""

this is the inventory UI code:

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 this is the Globalinventory code:

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

I am not sure why the number 1 problem happening but the second problem is for the slot guards by any node, make sure the mouse filter of slot is set to “stop”, is there any control node after the slot container?

there are 2 control nodes, 1 being the slot and 1 being the UI

Please give me a screenshot of the scene tree. And try to print anything in the set item function


apologies for not understanding

I means Inventory scene tree

scenetree

The mouse filter of the slot is set to stop?

1 Like

I have no idea what that is… mouse filter? where is that?

found it

1 Like

didnt work

and mouse stop is in the inventory UI too

Inventory ui is not matter, please tell me is the grid container mouse filter stop? If so then experiment by setting this to ignore or pass. Tell me is it working?

yeah none of them work unfortunately

What happened when you tried to do this by area?

it kinda had a glitch

I can understand why it’s happening. Please try add the slots with codes (loop), without using grid container. I am 90% sure it will work. Or test it just by adding yourself the slots without codes. You can do this inside a control, name it slots

yeah but without the container, how can I contain the slots? thats the problem

With loop, it’s possible, if you need codes then you can tell me

Wait I have another correct way

please do:

@onready var grid=$GridContainer
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()