Can anyone give me a hint on how to save my heroes health that is in a PLAYER class that would be GetHealth() because it inherited that from the base class entity.
SetHealth() is in the base class Entity. I know I am just a couple line away from solving the problem. If you guys need more info let me know. I'm thinking this is enough code though...

void save()
{
 
 
	//save player name, life, and current coordinates on the board
             ofstream saveGame;
             saveGame.open("save.txt");
             saveGame << playerName << " " << player.GetHealth() << " " << x << " " << y << " " 
                 << m << " " << n << " " << g << " " << h << " " << Currentroom << endl;
             saveGame.close();
}
void continueGame()//I think my problem is here...
{
 //open save file for previous matrix position and health
 	
 
	ifstream continueData;
	continueData.open("save.txt");
	continueData >> playerName >> player.GetHealth() >> x >> y >> m >> n >> g >> h >> Currentroom;
    continueData.close();
 
					
 
}

Recommended Answers

All 4 Replies

I don't know what GetHeath() returns, but you can't use it when reading the data file. What does that function return? And what are the parameters to SetHeath() ?

In the read function you will need to do something like this:

char something[255];
continueData >> playerName >> something >> x >> y >> m >> n >> g >> h >> Currentroom;
player.SetHeath(something);
commented: Once agin you've helped me out of a jam! +1

GetHealth() returns the persons life and places it on the screen. Originally, (nit sure if you remember) I had put the health variable called int life; in the main cpp. I believe I have the save function part correct. On the continue function when I try to do the same thing I keep getting some type of binary error saying it should be << instead of >>. Any thoughts on how I should get around that while still getting what I want from the class? I have to do it like that so that when my character gets experience his life can go up too.

void save()
{ 
 
 	 PLAYER player;
	//save player name, life, and current coordinates on the board
             ofstream saveGame;
             saveGame.open("save.txt");
             saveGame << playerName << " " << player.GetLife() << " " << x << " " << y << " " 
                 << m << " " << n << " " << g << " " << h << " " << Currentroom << endl;
             saveGame.close();
}
void continueGame()// My problem is here...
{
 //open save file for previous matrix position and health
 PLAYER player; \\ I'm to replace the integer life with it's counter GetHealth() 
 ifstream continueData;
	continueData.open("save.txt");
	continueData >> playerName >> life >> x >> y >> m >> n >> g >> h >> Currentroom;//life to getlife
    continueData.close();

Thanx a lot Ancient Dragon! Here is my solution in case anyone else ever runs into this type of problem.

void continueGame()// My problem is here...
{
 //open save file for previous matrix position and health
 PLAYER player;
 
 int something;
 ifstream continueData;
	continueData.open("save.txt");
	continueData >> playerName >> something >> x >> y >> m >> n >> g >> h >> Currentroom;
player.SetLife(something);
    continueData.close();

}

Change the variable something to a more meaningful name.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.