Weird problem with code

You have to save how many crusades there are, so you know how many times to loop when loading them. And when loading a save you have to clear the vector you store crusades in, in case someone is loading a game from a game.

You also can't (or rather, shouldn't) save the pointer to the crusade. You don't know where in the memory it will end up next time. Where it was last time is not relevant when loading a save.
Add a crusade to the vector you use to keep track of them, then call the read(pStream) function for that crusade. You can't save crusades. You can only save the data they contain, then when loading make new crusades that load the data of the old ones.


You can pass pStream into any function you want.
 
so then:

Code:
//read in CvGame
       for(int i = 0; i < getNumCrusades(); i++)
       { 
              CvCrusade* pCrusade;
              pCrusade->read(pStream);
              addCrusade(pCrusade);
       } 
       
//write in CvGame   
       for(int i = 0; i < getNumCrusades(); i++)
       {
              CvCrusade* pCrusade = getCrusade(i);
              pCrusade->write(pStream);
       }

given that aCrusades is cleared when the reset method is called.
 
addCrusade(pCrusade);

This (is supposed to) add the crusade to a vector, right? That vector must be cleared before loading crusades from the save.

and you still don't write how many crusades there are. When you read the save, what is getNumCrusades() going to return? You must save how many crusades there are, so you know how many to load.
 
oh yeah, of course. I would have done that previously, I was highlight the important code.

And the vector will be cleared in reset() as I said
 
Back
Top Bottom