How do I fix this Inventory System?

0 favourites
  • 12 posts
From the Asset Store
Create complex dialogues with ease with this tool/template!
  • Hi guys, I've been having trouble figuring out how to fix a particular issue in my Inventory System.

    Currently, the desired output is:

    When I click on an item, a message is displaying asking me if I want to use the item or cancel the operation.

    If I click on use, the item is unloaded from the inventory array.

    Right now, if I add items to the Inventory and I use them, I cant add items in the order it should be (first current empty slot in the inventory).

    A link to a basic project file.

    https://drive.google.com/file/d/1SZzIiJjgqI7N_EJEIdCSbAVv1grkcKBR/view?usp=sharing

    The 3 squares in the top of screen are used to add items to the inventory.

    Thanks in advance!

  • Looking at your array_inv_items the cheese(sword) and apples which are loaded into the array are not being removed from the array when given away. Therefore I would say that no other items can be loaded into the array because all of the array elements are full.

    There are other issues such as multiple instances of an item being destroyed when giving one of theose item types away.

    Is the desired behaviour this: Move item into 1 of 4 inventory slots, when the item is used/given away that inventory slot then becomes empty?

    Are you also wanting to move other remaining items towards the left when one is used so that when a new item is added it is added at the end or right hand side?

  • The actions that handle clearing an inventory slot when giving away an item were disabled in the event sheet. Enabling them solves the problem of not being able to add more items. However it also destroys other similar sprites, but does not remove them from the array which means they can never be removed because they don't exist to click on

  • using if sprite var itemname="string" and then destroying that sprite is what is causing the problems as it destroys all sprites that equal match that string but the array events are only triggered for the one that was clicked on

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi!

    No, for now my intention wasnt of moving the items.

    And yes, previously, if clicking on an object, the object would be deleted from the array. So technically it was working fine.

    But the moment I added an extra interaction, I didnt figure out how to make it work.

    For now, I compare the name of the items, which deletes all the items of the same name, but my first though was that I could compare their actual position in the array instead. So once I click on a slot, I use the position I clicked on to compare it with an array.

  • I would trim this down or start again because it looks highly convoluted for such a simple thing. You're using an array but at the same time have made it all about the visible slot objects. To delete an item of the array should not require that much logic and it's made it super confusing, you will likely encounter more bugs. To delete an item from an array, should be set item at slot_ID,0 to "" when the slot is clicked. There is a lot of variable setting on the slot too, this isn't required either because you're using a slot_ID to gather info from the inventory to use at any time.

  • I understand what you say but at this point I dont think I would be restarting it.

    Theres some extra variables such as posx and posy which I should have deleted.

    Apart that, the rest are used to communicate with a companion app.

    The system was working when you click on an item, since the array would be updated properly, but once I added the new rule, I couldnt figure out a way to make it work (delete keys from the array).

  • To fix what you requested you need to change the logic for the add item function. You shouldn't base it on slot object matching a slot ID that increases when you add an item. You should instead run a loop for each x to check for an empty slot which is "" in the array and then add the item at the array position 'loopindex', or if it doesn't find "" then the inventory is full.

    edit: looks like you might be doing that already if you remove the slot object condition. The other problem is that using 'give' is not removing items from the array. It looks for an invslot_1.slotID that is not referenced by conditions

  • Thanks

    I'm a bit confused though. I did that for FindEmptySlot once I get an item, so what exactly would be the error?

    Am I doing extra steps which are not needed?

  • Yeah see my edits above, it is actually working as you want for adding items just that when you remove items they are not removed from the array so there are no empty slots.

  • "For now, I compare the name of the items, which deletes all the items of the same name, but my first though was that I could compare their actual position in the array instead. So once I click on a slot, I use the position I clicked on to compare it with an array."

    While I agree that the system is too complex and it would help you to redo it, you could append the item name with the array position number when it is added, then use that to handle the deletion like you said.

  • I agree it ended up being overly complex. The problem is I have to present a small demo in 1 week and a half, so I don't have much of a luxury to redo it at this point. But after, I probably will since I might end up having much more trouble with it in the long road.

    Thank guys, I'll test your suggestions and I'll come back if I have more questions.

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