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:
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.
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).
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).
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
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.