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