Thread: Saving the game - help plz!

  1. #1
    Registered User
    Join Date
    Jan 2005
    Location
    Copenhagen, Denmark.
    Posts
    16

    Question Saving the game - help plz!

    I'm making an RPG in C++, but I don't know how to make it possible to save your game, so next time you play, you can load it again. I guess it's something with making a new file during play or something...?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    User chooses "Save"
    Your code opens a file, writes some stuff to it and closes the file.

    "Load" is the reverse.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Location
    Copenhagen, Denmark.
    Posts
    16
    OH so THAT'S how a save-load function works >.< - as I did'nt know...I'd like to know HOW to open the file, save the stuff, and close the file. I should be capable of saving the stuff - probably just setting some variables, but how to open and close the save file?

  4. #4
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Look up functions of the <fstream> library... it's not that hard.. it's just a matter of:

    1. creating objects of type ofstream and ifstream

    2. testing to see if a file exists (using your infile function)

    3. if file does not exist, create the file using your outfile function.

    4. offer the user options to write and read from the file


    The attached .cpp is a little something I whipped up, that basically follows the same logic.. that should help demonstate how to use the <fstream> library.

    this program basically just writes a single (encrypted) word to a file... then reads from the file to see if the user's password matchs the one encryped in the file.

    ^^^ if you can do this with one word.. you can do this with a bunch of words (or game variable information)
    Last edited by The Brain; 01-26-2005 at 12:45 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  5. #5
    Registered User
    Join Date
    Jan 2005
    Location
    Copenhagen, Denmark.
    Posts
    16
    Thx for the information. I'm still quite blank on how to do it though, but i'll try find out - at least now i know what it's about

  6. #6
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    http://www.cprogramming.com/tutorial/lesson10.html
    Also, I think it might be important to bitshift (<< and >>) a bit so users don't cheat. I have to go now but when I come back I'll explain in detail.
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  7. #7
    Registered User
    Join Date
    Jan 2005
    Location
    Copenhagen, Denmark.
    Posts
    16
    Quote Originally Posted by The Brain
    The attached .cpp is a little something I whipped up, that basically follows the same logic.. that should help demonstate how to use the <fstream> library.

    this program basically just writes a single (encrypted) word to a file... then reads from the file to see if the user's password matchs the one encryped in the file.

    ^^^ if you can do this with one word.. you can do this with a bunch of words (or game variable information)
    Hmm...my compiler is not recognizing many of those functions...like if it is not meant to be possible to save/load in C++.

  8. #8
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    thus begins the troubleshooting process....


    post your best code (probably on the c++ forum since this is geared more towards gaming theory) along with compiler errors please.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  9. #9
    Registered User
    Join Date
    Jan 2005
    Location
    Copenhagen, Denmark.
    Posts
    16
    what do u mean? u want me to post my best program?
    Or do u want me to post my best suggestion on a save/load function, and why it's not working?
    Last edited by Gamemaniac; 01-26-2005 at 01:32 PM.

  10. #10
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Arrow "help me.. help you...." -Jerry McGuire

    my fault.. let me rephrase...


    ahem...



    "Post your best code of your attempt at using the <fstream> library.. along with any compiler errors you may have encountered along the way."


    sometimes offering smart instructions can be just as important as asking smart questions.
    Last edited by The Brain; 01-26-2005 at 01:52 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  11. #11
    Registered User
    Join Date
    Jan 2005
    Location
    Copenhagen, Denmark.
    Posts
    16
    After searching a little on the net, I found this code.
    It creates a file, writes in it, and closes it again. I feel like being very close to making a save/load system...
    Now I just need to find out how to protect it, so that the user can't write in the save-file. Someone got any ideas?
    Last edited by Gamemaniac; 01-26-2005 at 02:33 PM.

  12. #12
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    Like I said, bitshifting is what you're looking for for protecting from user modifications.
    http://cboard.cprogramming.com/showt...4&page=3&pp=15
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  13. #13
    Registered User
    Join Date
    Jan 2005
    Location
    Copenhagen, Denmark.
    Posts
    16
    Cool, I thank you all for helping. Now I can begin on my text-based RPG

  14. #14
    Registered User
    Join Date
    Jan 2005
    Posts
    106
    You don't really need to use bitshift. Saving a plain-text file as anything other than .txt will probably deter most users. There are also a lot of non-complex deterents that you can without anything difficult involved. Saving in random dummy numbers that never get read back in sometimes works. Also, just leaving your save as cryptic and commentless as possible isn't really a bad idea. It's not so much a matter of using real protection as it is confusing people into thinking that it is actually protected.

  15. #15
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    Quote Originally Posted by suzakugaiden
    You don't really need to use bitshift. Saving a plain-text file as anything other than .txt will probably deter most users. There are also a lot of non-complex deterents that you can without anything difficult involved. Saving in random dummy numbers that never get read back in sometimes works. Also, just leaving your save as cryptic and commentless as possible isn't really a bad idea. It's not so much a matter of using real protection as it is confusing people into thinking that it is actually protected.
    You're right. Those are actually better methods than bitshifting. I haven't really looked for encryption methods. I wonder how many save game files I have that aren't encrypted... *gets devilish look on face and opens Windows Explorer*
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-22-2006, 12:23 AM
  2. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-26-2006, 12:14 AM
  3. Game Programmer's AIM Circle: Join Today
    By KingZoolerius66 in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 12-20-2003, 12:12 PM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM
  5. I got everything worked out now. Try my game plz
    By frenchfry164 in forum C++ Programming
    Replies: 4
    Last Post: 03-31-2002, 04:05 PM