Depending on how many inventory slots you have. The amount in the array should match.
You should be equal to the amount of spaces in your inventory array.
Then you should give every inventory slot an ID number starting with 0.
Let's say your inventory is 5 spaces wide and 4 height.
So with the Inventory ID it would look like his.
00, 01, 02, 03, 04
05, 06, 07, 08, 09
10, 11, 12, 13, 14
15, 16, 17, 18, 19
If you have 20 inventory slots then the array should be:
0, No Item
1, No Item
...
...
18, No Item
19,No Item
This is because 0 counts as 1.
Using the info in the Array you can then make up the inventory.
Make a variable that you can use to identify items.
You can have Variable "Item"
If the item the player picks up is a potion you can give the "Item" variable a value of "potion".
After the value of variable "Item" is changed it should put it's value into the array.
The array would be something like this.
0, Potion
1, Potion
2, Stick
3, Rock
...
...
18, No Item
19, Rock
When the inventory array is changed you should update the inventory instantly.
If the player uses the potion in Inventory ID 1 then you can grab that value and use it to change the value of that row in the Array.
It was a "Potion" so now it should be changed to "No Item"
You have to do this by comparing the used inventory ID to the Row of the Array.
Inventory ID 1
is the same as
Row 1 in the Array
0, Potion
1, No Item
2, Stick
3, Rock
...
...
18, No Item
19, Rock
If player picks up another Rock, check the Array for the first Row with the value of "No Item"
Grab that Row number. That would be Row 1 again since the player used it the potion in Row 1.
0, Potion
1, Rock
2, Stick
3, Rock
...
...
18, No Item
19, Rock
Every time you add a value into the the Inventory Array you should grab the Row ID it is being placed in.
If the item is placed in the Array in Row 1.
Then you should create the Rock Image in the X,Y location of the inventory ID of 1.
When the Item needs to be used then you should delete that Image of that object and get the ID location of the Item and change the Array Value in that row to "No Item".
If the player picks up an item you need to change the variable "Item" to what was picked up and then destroy that item. Insert it's value into the array. After it is put into the array using the "Item" Variable. Then you should use it's row to figure out where inventory ID it goes into in the inventory. Then you create the Rock image to the inventory ID spot.