Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSatharis

Posted 03 May 2013 - 02:43 PM

ok so I have been on other forums, googled, read on most c++ websites and I can't understand how to get my code to save the data to a file which can be selected to loaded once in the game.

Well what is it you're trying to accomplish? There's nothing really mystical about saving and loading files, using streams as an example: you basically just insert or grab variables to a stream to write their value to the file or read the next value into the variable.
 

I have two ofstreams and ifstreams, one to save and load the highscore of the game the other supposed to save the progress and load it when you feel like it. The thing is I can't get the progress or game to save the data I believe I save it in wrong format and so on but I don't know how to fix that at the moment so I would be really gratefull if someone could help me out here.

I looked over your code a bit and I'm quite frankly not sure what it is you're trying to -do- from what I can tell it just opens a file, reads everything out of it and prints it to the console. That's not really going to change program flow at all.

I know some of the basics but not all still things I need to get explained but the major problem right now is to get it to save in any format except .txt (was thinking to save it as a .exe first but that didn't work out well tongue.png so now I'm thinking of something like .dat or .dll or such)

Extension is just a naming scheme, used to let programs "assume" what kind of data a file contains, or for the operating system to use(i.e. .exe files are executable code.) All files are binary but most people differentiate them as text or binary, text is just binary encoded to be read back as text(useful for opening the file to edit it easily, or being able to read it into strings and other business.)

Unless your game relies on being performant or you have some good reason to use straight binary writing/reading, text files would likely suit your purposes fine.

The extension doesn't really "matter" that much if you know which file you're loading, since it's just a label, but you really shouldn't label files with common extensions like .exe or .dll if they aren't in fact either of those file types.

Once I get a hang of how to use return properly i will use that and "call" on the things I need to main and not write it all in there but for time being I have done that so it looks messy.

Your code is very hard to follow honestly, you probably should read up on functions and scope and all that basic stuff before you worry about reading and writing files. Code with good flow is much easier to understand and to correct then a giant set of switches.

That said when it comes down to it I just don't even understand what your goal is, what are you trying to save and load?

#2Satharis

Posted 03 May 2013 - 02:40 PM

ok so I have been on other forums, googled, read on most c++ websites and I can't understand how to get my code to save the data to a file which can be selected to loaded once in the game.

Well what is it you're trying to accomplish? There's nothing really mystical about saving and loading files, using streams as an example: you basically just insert or grab variables to a stream to write their value to the file or read the next value into the variable.
 

I have two ofstreams and ifstreams, one to save and load the highscore of the game the other supposed to save the progress and load it when you feel like it. The thing is I can't get the progress or game to save the data I believe I save it in wrong format and so on but I don't know how to fix that at the moment so I would be really gratefull if someone could help me out here.

I looked over your code a bit and I'm quite frankly not sure what it is you're trying to -do- from what I can tell it just opens a file, reads everything out of it and prints it to the console. That's not really going to change program flow at all.

I know some of the basics but not all still things I need to get explained but the major problem right now is to get it to save in any format except .txt (was thinking to save it as a .exe first but that didn't work out well tongue.png so now I'm thinking of something like .dat or .dll or such)

Extension is just a naming scheme, used to let programs "assume" what kind of data a file contains, or for the operating system to use(i.e. .exe files are executable code.) All files are binary but most people differentiate them as text or binary, text is just binary encoded to be read back as text(useful for opening the file to edit it easily, or being able to read it into strings and other business.)

Unless your game relies on being performant or you have some good reason to use straight binary writing/reading, text files would likely suit your purposes fine.

The extension doesn't really "matter" that much if you know which file you're loading, since it's just a label, but you really shouldn't label files with common extensions like .exe or .dll if they aren't in fact either of those file types.

Once I get a hang of how to use return properly i will use that and "call" on the things I need to main and not write it all in there but for time being I have done that so it looks messy.

Your code is very hard to follow honestly, you probably should read up on functions and scope and all that basic stuff before you worry about reading and writing files. Code with good flow is much easier to understand and to correct then a giant set of switches.

#1Satharis

Posted 03 May 2013 - 02:40 PM

ok so I have been on other forums, googled, read on most c++ websites and I can't understand how to get my code to save the data to a file which can be selected to loaded once in the game.

Well what is it you're trying to accomplish? There's nothing really mystical about saving and loading files, using streams as an example: you basically just insert or grab variables to a stream to write their value to the file or read the next value into the variable.
 

I have two ofstreams and ifstreams, one to save and load the highscore of the game the other supposed to save the progress and load it when you feel like it. The thing is I can't get the progress or game to save the data I believe I save it in wrong format and so on but I don't know how to fix that at the moment so I would be really gratefull if someone could help me out here.

I looked over your code a bit and I'm quite frankly not sure what it is you're trying to -do- from what I can tell it just opens a file, reads everything out of it and prints it to the console. That's not really going to change program flow at all.

I know some of the basics but not all still things I need to get explained but the major problem right now is to get it to save in any format except .txt (was thinking to save it as a .exe first but that didn't work out well tongue.png so now I'm thinking of something like .dat or .dll or such)

Extension is just a naming scheme, used to let programs "assume" what kind of data a file contains, or for the operating system to use(i.e. .exe files are executable code.) All files are binary but most people differentiate them as text or binary, text is just binary encoded to be read back as text(useful for opening the file to edit it easily, or being able to read it into strings and other business.)

Unless your game relies on being performant or you have some good reason to use straight binary writing/reading, text files would likely suit your purposes fine.

The extension doesn't really "matter" that much if you know which file you're loading, since it's just a label, but you really shouldn't label files with common extensions like .exe or .dll if they aren't in fact either of those file types.

Once I get a hang of how to use return properly i will use that and "call" on the things I need to main and not write it all in there but for time being I have done that so it looks messy.

Your code is very hard to follow honestly, you probably should read up on functions and scope and all that basic stuff before you worry about reading and writing files. Code with good flow is much easier to understand and to correct then a giant set of switches.

PARTNERS