How is it already Friday? It feels like it was yesterday I was writing a blog post… Ah well, at least I have something to talk about this week – I’ve made actual progress! The inventory acts like an inventory now!
So, last week I was making my through refactoring my events and tidying everything up a bit. By doing that I could more clearly see where my issues were and how to fix them. I’ve managed to fix the scrolling issues I was having (while introducing new ones, but hey, that’s gamedev) so you can now look through each inventory separately. Each category displays what’s in its own array correctly and shows what’s on each page by calling content from appropriate array cells (previously it could only look at the first 20 cells.) And having a different number of ‘pages’ in each inventory is no longer an issue for the system!
That meant I could actually look at finally allowing the player to add items to the inventory. So, in the ‘overworld’ there are some green boxes which hold the information for the items they contain – a variable each for ItemName, ItemID, ItemCategory and NumberofItems.
When the player interacts with a box, the category variable is used to pick which inventory array the system needs to check. It then looks at the array to see if the ID for that item already exists in it. If it does, then we add the NumberofItems to the relevant key in a dictionary - the player is now holding more of an item they had.
If not, then we add the item ID to the array, and then update the dictionary. The dictionary is just used to keep track of how many of each item the player has currently - anything with a value over zero should have its ID stored in the array.
It’s still not perfect, but it’s so satisfying to see an inventory system doing inventory stuff! Hopefully, I can fix these last few issues, do a little more refactoring and then start commenting on the project ready for the tutorial!
Have a good weekend!