Hello everyone,

I am trying to make a simple inventory system. I followed the resource based inventory tutorial form Heartbeast on youtube and am now at the point where i want to add items i pickup to the array.

I have ready about the void insert ( int position, Variant value ) but don't understand it.

Is there someone that could help me with this and explain how this should be done? im not totaly new to godot, but still need to learn a lot

8 days later

I think that we can do it by colliding to an area2d(the item) and then use the array variable and change one of the null variables to a resource (the item u want to put into).

I have also asked this question to heartbeast in his latest inventory video, i hope that we get the response soon.

4 months later

Hey, There's 2 ways for adding something to an array.

Let's say you made this array (for the sake of comprehension I used strings but you can use your custom resource type) var inventory = ["Sword", "Shield", "Potion"]

You can add an item to a specific position


#insert an item after the "Shield" item, so at the 2d position
inventory.insert(2, "Apple")
#new inventory will be ["Sword", "Shield", "Apple", "Potion"]

Or you can simply add it to the end of the array

inventory.append("Apple")
#new inventory will be ["Sword", "Shield", "Potion", "Apple"]
2 years later