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.


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

@CodeAlpaca can you please make an import for this ty

1 Like

Yes of course @Death68093! Though I’m not sure what you mean by this.

You can already import it, would you like a single object that has all the bundles so it’s easy to make sure you have all of it?

sry i havent replied @CodeAlpaca , i havent used flowlab in a minute. i don’t need it to be a single object but I would like if you could make a button that shows and hides this and if you could just use e to pick up items on the ground and add any item into the inventory. I don’t know if that’s possible but I would greatly appreciate it!

Yes this is indeed possible, however I can’t really update the example as I don’t have much time atm with school. If you want you can make a help request and see if someone else is available to help.

I don’t remember the exact code I made, but to make it show/hide, I believe if you just delete the objects and spawn them back in it’ll work fine.

To pick up any item, check if the player is near one, then press E. What you’ll want to happen is for the object to send a message with the proper value. So it’ll be something like this.

// in the player object looking for Items
If an Item is found, turn a Switch on
When E is pressed, send a raycast to that nearest item
// You can use the X, Y,  of the item to get the angle it needs to be at
Then send a message to "Last Ray Casted"
The Item will then received this message and send a message to the inventory
of the item value
// In the current example you'll see how apple, potato, and banana are all
different values (1, 2, 3).

That should give you a decent roadmap to follow and should also be a good method for performance. You could have the Items have a proximity instead of the player, but performance would be slightly worse depending on the number of items you have,