Jump to content
  • Advertisement
Exoaria

Flow for creating a basic inventory system from scratch...

Recommended Posts

I have an inventory system that I am trying to make as part of my first programming venture.

Creating the inventory doesn't seem to pose the challenge, but rather the control flow and code organisation that is needed. I have done some research, but I can't find the answers that I need. Instead, I have become confused, which you will see if you read my sheets I've been scribbling on trying to figure out how to work it.

Most of the information that I think anyone would need to take part in this discussion can be found in that link. I am using flawed logic, but I don't know how it is flawed, since I am coming from the perspective of someone who is new to code and does not have a lot of experience with the optimal interactivity between functions and the logic that should be used in these situations.

Essentially, I hope to gain some seeds of wisdom from someone else that may have been in my position or a nudge in the right direction from someone else who, in fact, can see where my logic is flawed and where it needs to be shifted.

Share this post


Link to post
Share on other sites
Advertisement

I'm really not seeing anything that immediately sticks out as "flawed". It makes perfect sense to me that both the Room and Player objects need to have their own way of managing items (Lists). It is also logical that once the player picks up the object, it cannot exist on the floor and in the player's inventory. You could tag your items with IDs and simulate moving it from the room's inventory to the player's.

 

Item is removed from the room's inventory and then a new item object is added with the removed item's ID, thus creating the same item. 

 

roomInventory.Remove(item) 
playerInventory.Add(new Item(item.ID)); 

EDIT: ID can be a string, integer, or however you want to organize your items. 

 

Edited by jazzyspazglobal

Share this post


Link to post
Share on other sites

Copy the item from the rooms list to the characters list.  I'm a C++ guy with little C# experience but I would make my items unique_ptrs and just std::move them from one to the other.  Another idea, have a item system that holds ALL items in the level & on the player with an extra variable for it's parent ID.  Either the player, NPC or room, or static object in a room like in a desk drawer for example.  Then you just change the items parent ID.  When/if levels change you bring forward only the players items to the next/new level.

Share this post


Link to post
Share on other sites

It might be helpful to view the items as two separate things: items that are spawned and on the ground, and items that are acquired and in the player's inventory. If it were me, I'd use an Event System and throw out an event when an object was "picked up" by the player. There would be classes controlling the items on the ground and the player's inventory, each subscribed to that event to destroy and create the item appropriately, imitating a transfer.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!