Archived

This topic is now archived and is closed to further replies.

Vanz

Figuring out how to do LOAD/SAVE game...

Recommended Posts

Hi, I am trying to set up the LOAD and SAVE game portion of my game. I have several structures set up similar to: typedef struct _KeepStruct { int x,y, MonsterType[3], MonsterQuantity[3], KeepPicture; BOOL IsKeep, Explored; int Gold, Treasure, TurnsTillRestock; } _KeepStruct ; _KeepStruct Keep[30]; I save all my structures like this... stream = fopen( "save.txt", "w+" ); fwrite(Country,sizeof(struct _KeepStruct),66,stream); fwrite(Knight,sizeof(struct _KnightStruct),54,stream); fwrite(Castle,sizeof(struct _CastleStruct),8,stream); fclose(stream); Then try to load them back like this.... stream = fopen( "save.txt", "r+" ); fread(Country,sizeof(struct _KeepStruct),66,stream); fread(Knight,sizeof(struct _KnightStruct),54,stream); fread(Castle,sizeof(struct _CastleStruct),8,stream); fclose(stream); When I look at the text file it seems to save the info OK, and it reads the first structure back perfectly but every other structure is screwed. I even tried messing with using sizeof() and fgetpos() and fseek() but still could not get the stupid structures to load properly. I was thinking of using individual file names but I have about 20 structures and with say 10 save games thats like 200 files, gotta be an easier way. Any info would be greatly appreciated, thanks. Rob rhuala@yahoo.com

Share this post


Link to post
Share on other sites
try this

  
stream = fopen("save.bin", "b");

// for each keep structure, do this

fwrite(&aKeep, sizeof(aKeep), 1, stream);

// for each Kinght, etc do same thing


.
.
.
// read back

stream = fopen("save.bin", b");

fread(&aKeep, sizeof(aKeep), 1, stream);


That should do it

Share this post


Link to post
Share on other sites