Slashdot Mirror


Object-Oriented 'Save Game' Techniques?

GreyArtist asks: "I took a course in C++ a year ago in which the instructor claimed that global (file-scope or inter-file-scope) variables were antiquated and not to be used under any circumstances. I immediately thought of a counter argument that involved the method I use for saving game data. The games (and many of the other programs) I write use not only global variables, but consecutive global variables declared in their own separate module. To save the game (or user settings) to file, I simply save a single large segment of data that contains all the necessary information. How do other coders do it? Would they create a 'MyObject.savemyself()' method for every object in their game? Do they save all the game code along with the data? Either way, it seems like a horrid case of code (or data) bloat. What do you die-hard object-oriented fanatics have to say about this, and what method they would you use for saving games?"

6 of 229 comments (clear)

  1. Actually... by orangesquid · · Score: 2, Funny

    The proper way to do this is:
    int main(int argc, char *argv[])
    {
    Game *theGame = new Game;
    theGame->setup(argc, argv);
    int retval = theGame->run();
    delete theGame;
    return retval;
    }

    Then, theGame can have private variables that are effectively global variables ;)

    --
    --TheOrangeSquid Is it any wonder things seem so awry? We swim in a sea of confusion and don't have to think to survive
  2. easy by DrSkwid · · Score: 5, Funny

    just ignore the instructor

    there are no rules !

    --
    There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
  3. Passcodes by FLAGGR · · Score: 4, Funny

    Screw save games, just give the user a password to get back to the level. Simple. (Just kidding)

  4. Re:Single instance by Anonymous Coward · · Score: 4, Funny
    Sounds like your a C user lost in OO land

    Yes my am.

  5. Re:"Serialize" by miu · · Score: 2, Funny
    Toss all those old saved games?

    Oooh, aren't we fancy Mister "toss all those old saved games". The proper answer according to the programmers of many of the games I've played is to do nothing, blindly load the now badly formated chunk of memory, and then crash the game trying to use it. The user will eventually figure out the problem, so make sure to wipe out their preferences in one of the crashes - to give em something to remember you by.

    --

    [Set Cain on fire and steal his lute.]
  6. Use these passcodes: by Chemisor · · Score: 2, Funny

    Use these passcodes. Then we won't have to memorize another 120 meaningless numbers.