Having Only One of Each Tool


Author: Zoleda Davila

Posted on 2/8/2024

A special feature I wanted for the inventory is that the player could only have one of each tool at a time. An issue I was having was even though the limit was one for each tool in the Data Table, when the player was in range to interact with each tool, they could still pick up the tool and put the tool in a different slot. For the way we want our game to function, this is an issue, because we want the inventory to be maximized for the player. In order to do this, I first wanted to edit the Handle Interact function that is in all items that we can interact with. This was not working, because we had to have access to both the player's inventory, how much the item gave you, and the information in the data table. 

After reverting back the changes that I made to the item's Handle Interact, I decided to check in the inventroy component when we have to add the item to inventory. First, I edited the Find Slot function to see if we already had a slot with that specific item. If we did, then we would check if the quanitity in that slot was equal to the limit of how many we could have for that item. If we did then we will return that we could not find a slot and an index of zero. Then, when we call the Find Slot fucntion, we check if we found a slot. If we did not, then we check if the index is -1. If yes, then we find empty slots and add to inventory. If not, that means we are at our limit for that one item and we do not complete the process of adding the item to our inventory. During testing, it does not work if you try to add a tool you already have in your inventory.


Leave a comment

Log in with itch.io to leave a comment.