adding value/amount to an item in a list

OrdorTheGreat

  • Posts: 2
hello.

I'm in the process of sorting an inventory behaviour and I'm after some advice on how do I go about adding amounts to an item. Currently my inventory works by adding the item to the game attribute when the player collides with it providing there is space then a scene behaviour display the item in the inventory but I'm hoping to be able to hold multiple of the same item in just one space for when I eventually add shop and crafting systems.

so e.g
index 0 is holding 4 potions
index 1 is holding 60 wood
ect.

Any help will be much appreciated, thanks.

Luyren

  • *
  • Posts: 2646
There is an inventory behavior available here: https://luyren.itch.io/luyrens-rpg-elements-resource-pack
There are custom blocks to add and remove items to the inventory, as well as custom blocks to check for item amount and other things.

As for your own code:
You can use two lists, one with the item name and another with the amount, and make sure their indexes always match. So if you are referencing index 0 in one, you are also referencing index 0 in the other.

If your inventory can only have one item stack, you can have a map attribute with the name as the key and its value as the amount.

Another option is to store in one list both name and amount with a separator, for example "Wood/60", and use the split text block to retrieve the amount. This will require more text manipulation when modifying the amount.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

OrdorTheGreat

  • Posts: 2
Hi Luyren, Thank you for your response, I had been using your inventory behaviour for the past month and it really helped me understand lists and learn a lot so thank you for that I admire your work, however I wanted to be more self sufficient with this current game.  I will try your suggestions tonight, Thank you again.