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...?
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...?
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.
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?
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
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
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
Hmm...my compiler is not recognizing many of those functions...like if it is not meant to be possible to save/load in C++.Originally Posted by The Brain
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
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.
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
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.
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
Cool, I thank you all for helping. Now I can begin on my text-based RPG
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*Originally Posted by suzakugaiden
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