(SOLVED) Is it possible to subtract a specific amount of item from Gdevelop inbuilt inventory?

Is it possible to subtract a specific amount of item from Gdevelop inbuilt inventory?
if my inventory has 10 wood and i want to subtract 1 how should i do that?
image
all i can see is add and remove

There’s an extensions called Extra Inventory functions that adds those functions. There’s also a slot inventory extension and another extension that seems to creates it’s own inventory system. There’s a template or example in GD for that one.

Otherwise, you could use a repeat x times or do it the way the extension does it which is save the inventory to a variable, edit the specific child and then re-load the inventory from the variable.

1 Like


Here is some usage of the Repeat function, just make it run as many times as you need, and it will work. And cool thing is, you can use a variable to make it change how many times you want it repeated.

1 Like

I am sorry for late reply
I tried the Extra Inventory functions and it is working but the thing is that the inventory number doesn’t updates the text

Sorry for late reply i tried but it removes the entire amount of the object

You’ll have to update the text. I don’t know how you’re setting your setting the text. If you need help then you’ll need to post a screenshot of the relevant events.


this is the event for object picking and text modifying

Which part isn’t working top, bottom or both? It looks like the top adds to an existing slot and the bottom adds to an empty slot.

Is PickedItem a number or a string? I’m asking because in most places you get the value as a string but for the animation, it’s read as a number and converted to a string.

You would need to add a Trigger once condition, its repeating that many times every frame.

I don’t think a trigger once alone should be added. The count and items variables are reset so it won’t add more but the for each object is still running needlessly. It would help if the for each object was a subevent of a condition that checks if the item isn’t empty with a trigger once so it only triggers that code when there is something to add. (or delete) (unless that part is cropped from the screenshot)

PickedItem is a string
and both of the parts are working when i pick an object but when an object is subtracted from the inventory it doesn’t updates the inventorynumber unless i pick it up with my pointer


so i used this

but it just changes every item string

When you remove an item or display the inventory, it needs to be updated. You can update all of them or just one. You need to pick the text object first just like when you add it.

If animation of inventoryItemIndicator =item
Take into account inventoryNumber linked to inventoryItemIndicator
Set text to inventory count

Or you can use a for each object and update them all using the animation name within the event that checks the inventory. Again picking the text that’s linked to it.

1 Like


so i did this and it is working but the thing is it also removes the item from the chest
this is my chest setup

You need a way to differentiate between the 2 things. The easiest way would be to use different objects for each type. One object for inventory and a separate object for chests.

Otherwise, you would need to add another condition to determine which is which. Conditions work like filters. You need to “filter” or pick the objects that you want. You could use another object variable but using a different object would be easier.


So i changed it but now my pointer is not working with it

how can i do this?

I don’t know how your pointer works but I’m guessing you used the object that you just made a copy of. You could create a group object and put both objects into it. You would then use the group name in the conditions and actions.

What I meant by this is adding something like another variable either a text with the name of the type or a boolean like isInventory.

You could check the variable and then go through the picked objects with a for each object

Variable type of ItemInventoryIndicator is “inventory”
–for each object

This approach would require each instance to have a variable set to one of the values. Or a boolean.

Another approach would be to use a sprite as a hit box (it can be hidden) and test if the objects are in collision with it or (inverted) not in collision. The inventory objects would all be in collision with the hit box object.

ItemInventoryIndicator is in collision with inventoryHitbox
–for each ItemInventoryIndicator

(invertered) ItemInventoryIndicator is in collision with inventoryHitbox
–for each ItemInventoryIndicator

Either way the concept is you pick or filter the object list and then do whatever you want.

The group object approach would be easier if both objects use the same actions. Using a second condition or object would require each object type to have their own events.


this is my pointer setup
i mean the chest keeps the count but it removes the item image because of this condition which i used to change the image to emptyslot of inventory
IT ends up working on the chest as well

I’m not sure what the question is. Is it working?

I decided to try the inventory. I honestly haven’t used it much. (This is simplified and missing checks and balances like if the item exists in inventory. I wanted to keep it simple)

In this example I put the take into account lines as subevents. That way you can pick one text object and then pick the other without picking them both. Each time you add an event the conditions create a pick list. Each sub-event creates its own pick list. As you return to previous event (indentations) you return to that pick list.

It would probably be less confusing to use different objects for the chest count and the inventory count.

If this isn’t what you’re talking about then let me know.

Sorry for causing confusion
so in the first image i have same wood in the chest and in player inventory


but in the second image i have used the wood from inventory but the chest is still holding the value but the image is gone

You could use a different object for the inventory and the chest. Then you could change them independently without having to add move variables or other conditions to tell them apart. It would also be less confusing. You would know which was which. In my previous post, I used slot and chest.