Jump to content
  • Advertisement

Archived

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

Vanz

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

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

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
Advertisement
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

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