Game Save Files

This is a discussion on Game Save Files within the C++ Programming forums, part of the General Programming Boards category; Anyone who has ever made a game, where you save attributes and then reuse them can you post your code ...

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question Game Save Files

    Anyone who has ever made a game, where you save attributes and then reuse them can you post your code for the saving, loading and applying to attributes code? It doesn't have to be specific to your code but it has to work, sorry if this sounds like just writing code for me, that's what it kind'a sounds like. But I want to examine the code to see for my self how I would use it, it would be a great help. Thanks.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    typedef struct
    {
       int Hp;
       int Mp;
       int Exp;
    }PLAYER;
    
    
    void SaveGame(PLAYER PlayerStatsToSave, char* FileName)
    {
       FILE* File;
       File = fopen(FileName, "wb");
    
       if(File != NULL)
       {
          fwrite(&PlayerStatsToSave, sizeof(PLAYER), 1, File);
          fclose(File);
       }
    }
    
    
    void LoadGame(PLAYER* PointerToPlayerStats, char* FileName)
    {
       FILE* File;
       File = fopen(FileName, "rb");
    
       if(File != NULL)
       {
          fread(PointerToPlayerStats, sizeof(PLAYER), 1, File);
          fclose(File);
       }
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need book to program game into multiplayer...
    By edomingox in forum Game Programming
    Replies: 3
    Last Post: 10-02-2008, 09:26 AM
  2. creating a game save (how do i do it?)
    By The_Hermit in forum Game Programming
    Replies: 3
    Last Post: 08-02-2008, 02:12 PM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 02:46 PM
  4. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  5. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21