Inventory Example

Hello, CodeAlpaca here :wave:! A ton of people ask for this so I wanted to make this while helping out another user.


:memo: What this example includes: It’s important to note that this isn’t a one-size-fits-all type of thing, so I have to clarify what this example does

  1. Allows you to easily add and remove items. :abacus:
  2. The number of items easily stack :chart_with_upwards_trend:
  3. Includes a way to display this inventory. (Spawns a grid as well) :tv:

Of course, there will most likely be minor changes that will need to be made to exactly fit your game, but it should be easy.


:x: What does it NOT do:

  1. There is no limit to the stacking. It doesn’t cap at 64 like Minecraft. However, this is really easy to add.
 A+1 > B? 0 : A+1
// If it's equal to 0, you DON'T want to add it.
  1. All items automatically move to the lowest slot. This means you CANNOT place items anywhere like you would in Minecraft.
  2. You don’t know if you picked it up or not. I didn’t want to overcomplicate this, so I did not include this.

Imagine you had an apple, and you try to pick it up. You should know if it was picked up before removing the apple from the ground. This can be done with “Reply to last message” after it is confirmed you picked up the item (You’ll know information when it is added to the inventory)


I’ll have to make a Minecraft style example after this, because I’m sure that’s the first modification people will want (being able to place it wherever you want, and a stack limit. Though the stack limit is easy). + also showing a way to not pick up and item if the inventory is full. Another relatively easy thing to do, but will still be included once I make a more Minecraft style version of this.

6 Likes

First, Thank You for the example :smile:
I have not looked at the code yet, but there is a bug (at least for me). Click apple, potato, banana on the bottom, then clicked potato up top. The apple disappeared and potato/banana slid down a spot.

1 Like

Ty very much for reporting this! I fixed the issue, I accidentally didn’t make sure the index was set before removing the item, causing the first one to be removed

1 Like