Jump to content
  • Advertisement
Sign in to follow this  
lookyboop

c++ inventory

This topic is 3902 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

hello i am making a c+++ game. it is text based that opens in command prompt. i decided to give your charector an inventory. i beleve that best way to do this would be by using a class. but my question is if he bought something or won a battle how would i the item add to the inventory.

Share this post


Link to post
Share on other sites
Advertisement

#include <vector>;
using namespace std;

vector<Item> inventory;

void winBattle(){
inventory.push_back(new Item("cheeseburger",6,12));
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Kaze
#include <vector>;
using namespace std;

vector<Item> inventory;

void winBattle(){
inventory.push_back(new Item("cheeseburger",6,12));
}





i dont really understabd what you mean

Share this post


Link to post
Share on other sites
Quote:
Original post by Kaze
#include <vector>;
using namespace std;

vector<Item> inventory;

void winBattle(){
inventory.push_back(new Item("cheeseburger",6,12));
}





i dont really understabd what you mean

Share this post


Link to post
Share on other sites
Quote:
Original post by lookyboop
hello i am making a c+++ game. it is text based that opens in command prompt. i decided to give your charector an inventory. i beleve that best way to do this would be by using a class. but my question is if he bought something or won a battle how would i the item add to the inventory.


This is really too general to answer usefully. How do you represent items in your game? How do you represent the character?

Share this post


Link to post
Share on other sites
Quote:
Original post by Kaze
*** Source Snippet Removed ***


You try to insert a (Item*) into an (Item) container. You'd also have a memory leak if your code compiled. The semicolon at the end of the #include statement is also in error. While pointing him in the direction of containers is good, he's only going to be mislead by broken examples.

Share this post


Link to post
Share on other sites
Quote:
Original post by MaulingMonkey
You try to insert a (Item*) into an (Item) container. You'd also have a memory leak if your code compiled. The semicolon at the end of the #include statement is also in error. While pointing him in the direction of containers is good, he's only going to be mislead by broken examples.


i missed the * but the semicolon is becouse i tried to edit and the forum messed up all the <> into lt;gt;

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!