| | |
Help with saving/loading system.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 29
Reputation:
Solved Threads: 0
I have no idea how to make somthing like this, and i'm kind of new with file I/O.
How would you start somthing like this?
O.k. here is what I have to save,
I have roughly 56+ variables that need to be counted in this.
But what I am having trouble with is when you write in a word doc it can't save the actual vairable values.
I need to save like if somthing is 1 or 0. Like if you equiped a weapon or not, or if a quest if active. And then acess that when you load the game back up, but I can't seem to get the variable to show up when you access the load screen so the game locks up when you access portions of the map that "are not acessed yet." Which should have been saved during the previous play.
(it's also annoying when you have to start over agian when you start up the game)
For example,
int x;
x = x + 1;
I need to save the value of x, being that it is a coordinate to the map, and load it from the file agian exactly as it saved it.
Anybody know how to do this, or at least give me a brief walkthrough with file I/O and or how to access and save to files?
Here is an example of two code snippets;
could someone tell me how to access those x and y variables?
Yes this was orginally posted in game dev, but i would think i would have more success with an answer here.
How would you start somthing like this?
O.k. here is what I have to save,
I have roughly 56+ variables that need to be counted in this.
But what I am having trouble with is when you write in a word doc it can't save the actual vairable values.
I need to save like if somthing is 1 or 0. Like if you equiped a weapon or not, or if a quest if active. And then acess that when you load the game back up, but I can't seem to get the variable to show up when you access the load screen so the game locks up when you access portions of the map that "are not acessed yet." Which should have been saved during the previous play.
(it's also annoying when you have to start over agian when you start up the game)
For example,
int x;
x = x + 1;
I need to save the value of x, being that it is a coordinate to the map, and load it from the file agian exactly as it saved it.
Anybody know how to do this, or at least give me a brief walkthrough with file I/O and or how to access and save to files?
Here is an example of two code snippets;
C++ Syntax (Toggle Plain Text)
{ loadgame: savefile1.open ("savefile1.txt", ios::out | ios::app); savefile1.close(); goto maptest; }
C++ Syntax (Toggle Plain Text)
{ save: savefile1.open ("savefile1.txt"); savefile1 <<"x ="<<x<<"\n"<<"y ="<<y<<"\n"; savefile1.close(); goto jumpto; }
Yes this was orginally posted in game dev, but i would think i would have more success with an answer here.
you will need to do some form of string parsing. Firstly you need to read from the file you can use the following method
once you have something to work with then you can begin parsing the string.
string streams useful here,
That way word[1] would be "y" word[2] would be "=" and word[3] the variable.
Another method would be to read the file word by word using the >> operator.
Chris
C++ Syntax (Toggle Plain Text)
ifstream f("savefile1.txt", ios::in, ios::binary); string line; getline(f, line);
once you have something to work with then you can begin parsing the string.
string streams useful here,
C++ Syntax (Toggle Plain Text)
#include <sstream> ... ostringstream streams; streams.str(line); string words[3]; streams >> words[1] >> words[2] >> words[3];
Another method would be to read the file word by word using the >> operator.
Chris
Last edited by Freaky_Chris; Dec 6th, 2008 at 2:14 pm.
Knowledge is power -- But experience is everything
•
•
Join Date: Nov 2008
Posts: 29
Reputation:
Solved Threads: 0
Sorry this did not help. Your thing with >> doesn't work at all. Could you please explain how and what it does exactly so I can at least understand how it works, and figure out how to write it to fit my code.
Or could someone tell me how to load up a file, and change the variables in a program to the numbers of the file, scince that's exactly what I am trying to do.
Or could someone tell me how to load up a file, and change the variables in a program to the numbers of the file, scince that's exactly what I am trying to do.
•
•
Join Date: Sep 2008
Posts: 90
Reputation:
Solved Threads: 12
http://www.daniweb.com/forums/post31214.html
This link should help you. It teached me well how to use ifstream objects.
This link should help you. It teached me well how to use ifstream objects.
•
•
Join Date: Feb 2008
Posts: 628
Reputation:
Solved Threads: 46
You should try to make the question as limited as possible.
"I would like to write a number to a file, and then later retrieve that number from a file." is much clearer than something about a game and a quest, etc.
Try to get a sample application working (using unbeatables post as a starting point) before you try to integrate it into your game. You sample program should do exactly what you're trying to do and nothing else (ie. write a number to a file, and then read it in again.)
If you get that to work on its own, you should have no problem integrating it into the game.
Post back with results from the sample program.
Dave
"I would like to write a number to a file, and then later retrieve that number from a file." is much clearer than something about a game and a quest, etc.
Try to get a sample application working (using unbeatables post as a starting point) before you try to integrate it into your game. You sample program should do exactly what you're trying to do and nothing else (ie. write a number to a file, and then read it in again.)
If you get that to work on its own, you should have no problem integrating it into the game.
Post back with results from the sample program.
Dave
![]() |
Similar Threads
- Object oriented design: Graphics editor (Java)
- how to validate text file, loading into listbox (Visual Basic 4 / 5 / 6)
- Hey check out my prog. It has an error can u find it? (Java)
- Having problems saving objects into an array, then accessing the data later for repo (Java)
- Help with a reservation program! GUI Messed XD (Java)
- via82xx soundcard configuration in debian sarge (*nix Hardware Configuration)
- "cannot resolve symbol"problem (Java)
- HD Failing Cloning Issues (Storage)
- bridge dll and termination errors (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: reading from serial port way too slow (C++)
- Next Thread: open new Form in project
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector visualstudio win32 windows winsock word wordfrequency wxwidgets





