# 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 on other sites

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 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 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.

## Create an account

Register a new account

• 10
• 12
• 10
• 10
• 11
• ### Similar Content

• Hello. I'm newby in Unity and just start learning basics of this engine. I want to create a game like StackJump (links are below). And now I wondering what features do I have to use to create such my game. Should I use Physics engine or I can move objects changing transform manually in Update().
If I should use Physics can you in several words direct me how can I implement and what I have to use. Just general info, no need for detailed description of developing process.
Game in PlayMarket
Video of the game

• Good day!
My name is Roman Trestcov. I'm engaged in:
Producing the sound design of games and video clips; Exclusive creation of music, creation of music on references; Sound Design: Synthesis, Sampling.
I work with separate elements of the game, and I voice the whole project.
Examples of my work can be found below.
For this video, i write music and key sound elements (steps, explosions, noises, etc.).
For this trailer, also was written music and sound effects.
Below is a compilation of my works:

You can hear more of my work here:
https://audiojungle.net/user/knock-noise-room/portfolio
https://www.pond5.com/ru/artist/knock_noise_room#1/2064

If you like my work – cool! I'm always ready to join your project and give it a unique sound design.

Always online:
rtrestcov@gmail.com
https://vk.com/roman_trestsov

• Hi all. My project is coming along wonderfully, and am starting to consider alpha deployment, and would like your advice.
My project need access to 10,000 small PNG image files at runtime, each is only a few kilobytes each, which during development I used to load in directly from a fixed path on my HDD whenever one was needed (obviously not a solution for go-live), using something like this:
img = new WriteableBitmap(new BitmapImage(new Uri(@screenshotsPath + filename)));
The image would then be blitted onto a buffer screen, etc. etc. At a time, a few dozen would be being used.
Now I'm thinking about deployment, and also when I produce an update to my app, there could be more images to add to the folders. So I'm considering the best way of a) deploying the images to the user as part of the project, and b) how to most easily handle updates to the app, whereby more images will be added.
I have just experimented with adding them all as a Resource (!). This inflated the exe from 10mb to 100mb (not a major problem), increased the compile time from 3 secs to 30 secs (annoying), increased RAM usage from 500mb to 1.5gb (not a major problem either), but means that it solves my fixed directory issue, distribution issue, and update issue, simply by having the files all stuck into the executable. Here's the new code I'm using:
img = BitmapFactory.FromResource("Shots/" + filename);
The next thing I was going to try was to mark them as Content > Copy if Newer. This would resolve the executable size and RAM usage (and also the directory issue as well), however it seems that I'd need to highlight them all, and move them from Resource to Content. As an up-front job this isn't too bad, but as I add new images to the project, I'll need to go in and do this every time, which gets annoying, as the VS2015 default is Resource. Also, I'm not sure how this would work in terms of updates. Would something like ClickOnce deployment recognise new PNGs and install them to the users?

I also have 3,000 ZIP files (~500kb each) which also need deploying and updating in the same way. These are currently read directly from my HDD until I can find a permanent solution for adding these to the project as well.
Can anyone thing of a better way of doing what I'm trying to achieve?
Thanks for any help folks.

• hello, i'm steve and im designer, i can design any idea and i'm looking for projects to help, if you are interesting write and we can talk about it

• Good Evening,
I want to make a 2D game which involves displaying some debug information. Especially for collision, enemy sights and so on ...
First of I was thinking about all those shapes which I need will need for debugging purposes: circles, rectangles, lines, polygons.
I am really stucked right now because of the fundamental question:
Where do I store my vertices positions for each line (object)? Currently I am not using a model matrix because I am using orthographic projection and set the final position within the VBO. That means that if I add a new line I would have to expand the "points" array and re-upload (recall glBufferData) it every time. The other method would be to use a model matrix and a fixed vbo for a line but it would be also messy to exactly create a line from (0,0) to (100,20) calculating the rotation and scale to make it fit.
If I proceed with option 1 "updating the array each frame" I was thinking of having 4 draw calls every frame for the lines vao, polygons vao and so on.
In addition to that I am planning to use some sort of ECS based architecture. So the other question would be:
Should I treat those debug objects as entities/components?
For me it would make sense to treat them as entities but that's creates a new issue with the previous array approach because it would have for example a transform and render component. A special render component for debug objects (no texture etc) ... For me the transform component is also just a matrix but how would I then define a line?
Treating them as components would'nt be a good idea in my eyes because then I would always need an entity. Well entity is just an id !? So maybe its a component?
Regards,
LifeArtist