Setting up simple 3 item HUD inventory system?

Howdy,

I am trying to set up a very simple 3 item inventory system with HUD. I want the character to be able to pick up to 3 items (at the time only Axe available) and put them into the respective HUD slot, however I am running into a problem. Please see my environment / game screenshot below:

FULL ENVIRONMENT: https://imgur.com/a/BVjRuOG

Game screenshot:

When I walk over the first axe, it picks it up - however it’s put in all 3 of the boxes on the bottom. It should go to Inventory #1 if its empty and stop there. I tried including the 3 Inventory events as a child under the main axe pick up event, it does not work.

Here’s my simple game so far, you can see for yourself the issue I am having:
https://games.gdevelop-app.com/game-2144bbd2-a303-4d70-bf97-c280280d180f/index.html

Any help is welcome. Thank you in advance.

Perhaps this example will help you: GDevelop - Inventoralia - Inventory & shop Template for GDevelop 5 by Ulises Freitas
There are also several videos on this topic in Youtube, but I cannot recommend you any specific one.

@E1e5en I will watch that. How wrong am I doing it with the way I have right now?

Lets follow your logic this far:

  1. Player collides with axe, you delete it.
  2. Check if the inventory has the axe, and if the slots are empty. It is true, so the axe is added to the inventory (The slot is set to true).
  3. Check if the inventory has the axe, and if the two last slots are empty. It is true since we just made the first one true in step 2, so axe is added to inventory (Second slot is set to true).
  4. Chick if inventory has axe, and if the last slot only is empty. Since we change the other two slots, this is true, so axe is added to the inventory (Last slot is set to true).

One way to avoid it could be to do the check on the inventory when the player collides with the axe, in inverse order. First check if one slot is free, then if two slots are free, then if every slot is free.

  • If player collides with Axe…
    • Inventory…

If I may suggest it, axe, hammer, shovel… the items you may need could be put in a group so you can change the condition to

  • If player collides with Item (group)…
    • Inventory…

I hope it helps

1 Like

As @oscuridad666 described, the problem is that you need to interrupt the check after placing the item in an empty slot. He also indicated one of the options: to change the check order.
I can suggest this option: add a variable that will answer whether the item was put into inventory. Let’s enter the variable is_put (of type Boolean). When the player picks up an item, the variable is set to False. Now, in each check for an empty cell, we add a check for the value of this variable: if the value of the is_put variable is False. And when a free cell was found and the object was put there, then we set the value of the is_put variable to True. Accordingly, other checks will no longer occur.

1 Like