Simple inventory system not working properly.

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Inventory Aid
$4.90 USD
Create grid-based game inventories and items easily.
  • Working on a survival horror game. This is actually my first time making an inventory for the player so I naturally ran into some problems.

    I've made a Frankenstein's monster from a bunch of tutorials and examples I could find.

    What I had in mind is to make a player collide with loot and destroy it, while putting the correct item in the inventory slot. When inventory gets full, the player stops destroying loot items on contact, so that they can pick it up later.

    The code mostly works fine, up until it needs to destroy the last item before inventory gets full. I'm not sure what causing this...

  • Here's how you can fix and optimize your code:

  • Here's how you can fix and optimize your code:

    Thanks a lot! I didn't really know what I was doing so the code had some unneeded parts. Your version works perfectly. BTW, can I also somehow make inventory contents persist between layouts?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • BTW, can I also somehow make inventory contents persist between layouts?

    At the moment your inventory is basically stored in ui_inventory_slot sprites.

    One option is to make this sprite global. It will then migrate to other layouts. Just make sure that other layouts have the same layer and that you are not making duplicates of inventory slots - it's a very common problem. Use the debugger (Shift+F4) to check the number of instances.

    A better solution is to store the inventory in some data object - an array, dictionary, or JSON. Then you can rebuild the inventory at the start of every layout. And also you will be able to store it in Local Storage between sessions.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)