So I was making it so in my game you have an inventory, and that each item that you have can be displayed through a mini menu. So I made it so when you pick up an item, it sets it to a value in an array and the mini menu displays a list of the arrays. Then the player can choose what item they want to use.
Except I can’t figure out how to make it so that when you pick up an item it adds it as a values without messing with the rest of the values. The only way that I can think of to get this is
on selected value 0: if value selected = ExampleItem1, then do this with the item. If value selected = ExampleItem2, then do this with the item.… and so on.
Can anyone help me make this simpler?
3 Likes
I not quite sure I’m understanding the question, but what I would do is have an array called “items” that stores all the item names of everything in the game (maybe in alphabetical order or something). Then a second array “quantities” that is as long as the first array but all filled with zeros.
Then when the player picks up an item, you search for the item name in the “items” array and whatever position in the array is that item, you increase the number in the “quantities” array at that position.
So if “banana” was the third item in the “items” array, I would increase the third number in the “quantities” array by one when I picked up a banana.
Then, when the player opens the inventory, I search the quantities array for numbers that are not 0 and add a menu item with that name + quantity info to the menu items array. Then just create a menu with that array and it will be all the items that you have more than 0 of all in alphabetical order in the menu!
1 Like