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
  • Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Bread Collector
      Hello guys.
      I am a programmer and artist looking to form a team to develop games. I am looking for programmers, animators and composers who are interested in working together to make games in order to gain experience and grow their skills. I plan for us to start off on small 1 month projects in order to to get used to the process of development and hopefully move on to bigger projects if we choose to do so. 
      I spend a lot of time learning new things but I always forget the importance of doing. So I am looking for people who want to learn and get better through the experience of working with an actual team.
      If you are a:
      programmer animator composer and want to give it a try, please leave a comment below or reach me through my discord channel : https://discord.gg/GTdceFD .
    • By bojanzarnoski@gmx.de
      Hello,
      I want to get into coding again by programming a 2D platformer to get started, but i don't know if i should use Java or C# with the unity engine.
      I am pretty fit with Java, but with c# i have to start from scratch. What do you recommend and why?
    • By Luca Falco
      https://www.youtube.com/watch?v=UMoc52DEoC8     ABOUT THE GAME: Room54 is a first-person Horror/adventure  Videogame for pc,mac and linux users. the game is currently under development by a very small team, we put so much effort in this project and we are keep doing our best for that we are going to launch a kickstarter campaing in order to reach our ideal budget to complete the project, we hope the GameDev community can help us a lot                      STORY:   Daniel is a family father like many other, one day he decide with your wife and his daughter  to spend her winter holidays at their mountain house that they have recently buy in  mountain ,a  wonderful place surrounded by the nature of the woods,  Completely far away from the caotic city life. During their holidays Daniel and his family will understand that they are not welcome there and they will discover an  hided and disturbing part of the valley that they have never seen before                       GAMEPLAY:   You will play as Daniel, a father that will try to save his family, your gameplay will be focused on discovering secrets places around valley,investigating and trying to survive, you will find object that will help you solve enigma and to stay alive. The immersive audio and  environment will make you feel constantly follow by an high anxiety dose  during the game.                         SOCIAL PAGES:     Follow us to get the latest development news and insights     IndieDB:     http://www.indiedb.com/games/room54   Twitter:       https://twitter.com/Room54Thegame   facebook:   https://www.facebook.com/Room54/
    • By SickTwistGames
      Ok, firstly, Hi.
       
      This is my first post on this forum. I am an Indie Dev making my first game so bear with me when I say dumb stuff, I'm on a huge learning curve.
       
      My first question is about inventory systems for unity. I am trying to make a survival type game with crafting. I have purchased Inventory manager pro by devdog from the unity asset store and it seems like a pretty powerful assett but for an intermediate coder its a little tough to use.  I'm beginning to wonder if it was the right purchase.
      So my question is.... does anyone have any experience of inventory plugins / systems for unity and can anyone reccomend a system to me?
      It needs to have the following: Loot system, crafting system, character sheet, blueprint system,  character stats system. Ideally with as little coding as possible.
       
      Thanks
  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!