How to make NPCs use inventory items

Godot Version

4.2.2

Question

Hello, im new user to godot and whole programming.
Im created a inventory system with a youtube tutorial.
This inventory is an array which hold slot data and inside slot data there is different item classes(normal, consumable, etc.)
I want npcs search the inventory and find consumable items and use them to heal.
How i can write a code for this? I tried to search in internet but i couldn’t find anything.
Thank you and sorry for my bad english…

Well, it depends on your specific code, but if you have an array with all the items in the inventory, you probably want the npcs to loop through the inventory and check, for every item, if it is a consumable. Once you’ve found what you wanted, you can delete that slot.

If you are new to programming, you may want to check some tutorials before jumping to your first game. You can learn some basics for GDScript here: GDScript Tutorials

After that, there is this good tutorial on how to create a simple 2d game: Your first 2D game — Godot Engine (stable) documentation in English

Good luck and have fun!

1 Like