Inventory System

Hello all,

I am trying to get the inventory system work but I just can’t figure out. I would really appreciate it if you can help me solve this ఠ_ఠ

  1. In a scene “battle1” When a Slime hp drop to 0 it will drop an apple ( ͡° ͜ʖ ͡°) ( I think I Made it right )

  1. In another scene “Food_items” ( Note that there are 4 scenes for 4 inventories), I want to add the apple I got from the scene “battle1” into one of the slots in “Food_items”. This is where I can’t get it right…

I actually think I mess it up so badly as I really don’t get it from the Inventory system tutorial =/

I hope you can help me with this ●︿● Thank you so much

do you know if inventories are global??
I’ve looked here
but don’t say if they are global

Hi xisco,

I think it’s global? or they would use global string instead of the inventory expression in the tutorial?

I just started using gdevelop for 2 weeks, so I can’t really answer you xD

i say it because maybe is the reason why it is not working.
You could use the debugger to see the contents of inventory when scene changes
Maybe you could use layers instead of scenes

You are looking for an item called “fooditem” in the inventory and you are trying to create an object called “fooditem” but in the previous scene you called the inventory item as “fooditem_apple”. Isn’t this the problem?

Also you are creating “fooditem” in position of the slot, but you don’t set the Z order, so the item may be created below the slot? Make sure the Z order of the item is higher than the slot. Personally, I would use animations instead of creating objects. If apple is present in the inventory, find an empty slot and set animation of slot to apple.

I made an inventory example included with GD, most people find it extremely confusing but not sure if I could do it more simple than that. It is pretty straight forward, if there is a cherry in the inventory, find empty slot and set animation to cherry since the slot animations also using names, the same names as the items. Take a look.

Also, the inventory is global, so you don’t need the events at the bottom to add items to inventory using the slots.
The slots should only display items if any exist, you should not add items to inventory using the slots.
The order should be = item collected → add item to inventory → is item exist in inventory? → add item to slot

However, in the example I did not calculate with using the inventory across multiple scenes, it does not work like that out of the box but should be easy to fix that.

Finally, I would recommend to use more comments in your project especially when you are asking for help so we know for certain what is that you are trying to do exactly and where, using which events.

Hi ddabrahim,

Thank you for your reply. I was learning from your template but I think overall I am confuse with GD inventory system. I would really appreciateif you can answer me a few questions to understand the inventory logic better. =)

Let say

If I have 2 Inventory: foodinventory, dishinventory. In food inventory, I have fooditem_apple, fooditem_orange, fooditem_banana. (Those items are added through killing monster in different scenes with the add an item features)

And I just want to have a text object to display all the items in the food inventory. What is the action and text for it in modified text/
Do I modified a text object to
=""+ToString(food inventory(fooditems))
=““+ToString(InventoryTools::(“foodInventory”, “fooditems”))

Is it how it works and if the action is right?

In my logic right now“Inventory = Alternative GlobalVariable for items"

And I will add more comments divider =)


I could be wrong but I believe the only expression the inventory system has is the Count expression that return the quantity of selected item in the inventory.

Inventory::Count("inventory_name", "item_name")

So if you want to display a list of items, all you need to do is change the text of a text object and enter this expression and pass the inventory name and the item name you want to display in the list, also don’t forget to convert to string because the expression return a number.

"Apple: "  + ToString(Inventory::Count("foodinventory", "fooditem_apple")) +
"Banana: "  + ToString(Inventory::Count("foodinventory", "fooditem_banana")) + 
"Orange: " + ToString(Inventory::Count("foodinventory", "fooditem_orange"))

So, initially it should display

Apple: 0
Banana: 0
Orange: 0

But then as you collect and add items to the inventory, it should update providing you update the text object too.

1 Like

Thank You ddabrahim,

I will try to work around with it. If I still can’t solve it I will just use Global Variable instead of Inventory expression =)

Did you figure it out? If so please post event sheet.