Collect several items into one slot in the inventory

  • #1, by nataliaWednesday, 04. December 2019, 10:35 A year ago

    I'm just started with VS and I need some help.
    Is it possible to put several items in the same slot of the inventory? 

    Ex.: I have 2 identical items on my scene; I take the first one and it goes into a slot in my inventory. I take the second item and I do not want it to occupy the next slot, but I need it to go to the same slot as the first one (not replacing it). 

    Thank you in advance


    6 Posts

  • #2, by afrlmeWednesday, 04. December 2019, 11:15 A year ago
    You need to create 2 items (or how ever many items you want to combine) to do that, then remove & replace the old item.

    The only other thing you could do is create the item as an animation only & force it to loop a specific animation frame using Lua script. & maybe you could use a value that you increment each time you pickup the same type of item to determine which frame to show.

    Is it some kind of money/token system that can go up & down?


    6986 Posts

  • #3, by nataliaWednesday, 04. December 2019, 13:01 A year ago
    You need to create 2 items (or how ever many items you want to combine) to do that, then remove & replace the old item.

    Thanks for quick reply, afrlme. Do I understand right: I take the 1st item - I've got image with it in my slot, I take the 2nd - another image with both items together replaces the first image, and so on? And when I use these items one by one, I need to do the same from the end to the beginning?

    Yes, I’m trying to make several classes of resources (including money) which I need to be able to keep in one inventory slot but to use separately. For example: I collect 5 apples, give one to a npc, the rest 4 sell at a shop.


    6 Posts

  • #4, by afrlmeWednesday, 04. December 2019, 14:29 A year ago
    Yeah, kind of.

    What you need to do is use a value to keep track of the amount of coins, apples, whatever that you have. You should probably add a limit to the amount the character can carry at the same time.

    Alternatively you could do like what they did in the monkey island games where they had a few images that represented one item, a small handful of said item, a medium amount of said item, & a lot of said item, that way you don't need to create images for every single addition, because that would be an insane amount of work. Instead you would use the values & query a range between 2 numbers to determine which image to show...

    Let's say, you have 1 coin, so you show an image with 1 coin. now let's say you have 2-10 coins, so now you should an image with a small amount of coins, now let's say you have 11-25 coins, so now you show an image with a medium amount of coins, & so on, & so on - it would work both ways seeing as you can add & subtract from a value.

    ok, I don't really know how to explain how to set this system without an example, but I don't have the time/resources available to create one, so text will have to do.

    1. Create a value somewhere in the editor - somewhere easy to access, like on your main character. Name it something along the lines of "money", & set the default value to 0.

    2. Create an item, & call it "itm_money".

    3. Now create some images for it that represent 1 coin, a small handful of coins, a decent amount of coins, & a lot of coins. Add each of those images to the item you just created in step 2.

    4. edit each frame of the animation & open up the "actions" popup window & create an execute a script action part & add this code inside - edit as needed.
    if Values["money"].Int <= 1 then

    ActiveAnimations["itm_money"].FirstFrame = 1
    ActiveAnimations["itm_money"].LastFrame = 1

    elseif Values["money"].Int > 1 and Values["money"].Int <= 10 then

    ActiveAnimations["itm_money"].FirstFrame = 2
    ActiveAnimations["itm_money"].LastFrame = 2

    elseif Values["money"].Int > 10 and Values["money"].Int <= 50 then

    ActiveAnimations["itm_money"].FirstFrame = 3
    ActiveAnimations["itm_money"].LastFrame = 3

    elseif Values["money"].Int > 50 then

    ActiveAnimations["itm_money"].FirstFrame = 4
    ActiveAnimations["itm_money"].LastFrame = 4


    You need to add that same script in each frame as that will auto-force the animation to the correct frame whenever it is shown.

    5a. Again on your main character, open up the actions tab & create a called by other action part & rename it to something along the lines of "check_money".

    5b. Now create these action parts...

    if Value "money" is equal to 0
     if character has item "itm_money"
      remove item "itm_money"
     end if
    elseif Value "money" > 0
     if character has item "itm_money"
      add item "itm_money"
     end if
    end if

    6. now whenever you add or remove money from the value, you need to call that called by other action you created in steps 5a & 5b, as that will add or remove the item from the characters inventory if you add money & they don't yet have the item, or you have spent all the money, but still have the item in their inventory.

    Hopefully these steps will help you come up with a working system.

    The alternative would be to use a UI based approach like a lot of platformer games such as super mario have where it shows coins/lives, etc permanently on the screen.


    6986 Posts

  • #5, by nataliaThursday, 05. December 2019, 10:58 A year ago
    dear afrlme, thank you very much for your really helpful and exhaustive instruction, that is exactly what I need. 


    6 Posts

  • #6, by NigecThursday, 05. December 2019, 11:39 A year ago
    There's a simplistic example here if you are interested, you need to collect 4 coins, you can only use coins on the drinks machine if you have the 4 coins in inventory.. after you've inserted 4 coins you get the drink..

    just look for coins! the example only had one inventory slot so if you add more items the invenory breaks

    Edit.. I've fixed the inventory it now has enough slots
    Edit 2: simplified lua script

    Key Killer

    588 Posts

  • #7, by NigecThursday, 05. December 2019, 11:41 A year ago
    Feel free to edit it if you wise Lee, I just cobbled it together to test the theory wink

    Key Killer

    588 Posts

  • #8, by afrlmeThursday, 05. December 2019, 13:53 A year ago
    Feel free to edit it if you wise Lee, I just cobbled it together to test the theory wink

    Ah I see what you did there. The reason I suggested adding the scripts to the animation frames is because not everyone has the interface open 24/7 - depends on the GUI style & command system each dev decides to use. Also, if the inventory interface is hidden then I believe the animations won't be active.

    But in your example it seems to be working ok, so well done. wink


    6986 Posts

  • #9, by NigecThursday, 05. December 2019, 14:03 A year ago
    Yeah, when there was only one inventory slot and the scroll buttons needed to be used the animation was running when the slot was revealed
    Its the only thing I had really, I had considered doing something new, we'll see smile

    Key Killer

    588 Posts

  • #10, by NigecFriday, 06. December 2019, 09:23 A year ago
    A different style using the pop up inventory,  you can see the coins pile decress as the coins are fed to the machine.

    I'll share a link if someone wants it

    Key Killer

    588 Posts

Write post