Jump to content
  • Advertisement
Sign in to follow this  
metal_kid43

inventory for RPG text game

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey everyone, so im kinda knee deep in making my first major program and i was wondering how i should go about making my inventory for the player. i'm using c++ and have considered using a class (but am not quite sure how since i just got started on classes) or using new to create new memory somehow for each new inventory item and then place it somewhere. . . .somehow. . . .to be recalled later. any help would be appreciated! thanks

Share this post


Link to post
Share on other sites
Advertisement
The simplest solution is:

#include <vector>

class Character
{
std::vector<Item> inventory;

...

};

Share this post


Link to post
Share on other sites
Use a vector to store your items in. You items must all be the same type.
Something like this:

struct item
{
std::string name;
std::string description;

...
};

std::vector<item> items;

Share this post


Link to post
Share on other sites
I recommend you use vectors, as previously mentioned.

Vectors are much like arrays, but have much more functionality and accessibility, along with them being dynamic (they can change their size easily).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!