Hello! I am trying to make an inventory system, and my plan is that my 9 slots will have a true/false value, and when an item is picked up, it will pick the highest-ranked empty slot, and go there. The issue is that all the slots are connected to the same script. I can’t even use a global variable, because I need to seperatly detect for each slot. I might be able to do it all manually, but I plan on having much larger inventory upgrades and such.
I don’t know what code you need to see, so here is the code for the dropped item.
Hello! You should have a look at Octodemy’s inventory system tutorial; I used it for my own inventory, and it works great! For picking up items, the _on_body_entered(): checks if the body that entered is a player; then, it uses a for loop to find an empty slot in the inventory for the item. It uses resources for every item for the icon in the inventory, name, tooltip, etc.
This would go into the _on_body_entered function in the item’s pick up script:
if body.is_in_group("player"):
if Input.is_action_just_pressed("interact"):
#For loop that looks for every slot in the GridContainer
for slot in body.get_node("%GridContainer").get_children(): #Or whatever node holds the slots
#If a slot has an item resource (has an item in it already) it continues to find an empty one.
if slot.item: continue
#Adds the data from the dropped item to the slot
slot.item = self.get_meta("item_data")
#Gets rid of itself.
self.queue_free()
break