Computer Science Canada Need Some Calrification On Saving |
Author: | Archi [ Tue Jul 22, 2003 12:42 pm ] |
Post subject: | Need Some Calrification On Saving |
I've tried to look at a few of the tutorials on how to save something to a txt file, but I'm not qutie getting it. I'll be using the save feature to save the progress of the game so people can start where they left off. The only thing is, I dunno what the code would look like as the tutorials weren't too clear to me. Could someone maybe post the code which I could use to save and also a few examples of how to save the various pieces of info that will have to be saved? |
Author: | Tony [ Tue Jul 22, 2003 12:49 pm ] | ||
Post subject: | |||
Well what you do is that you write the values of all the variables to a textfile and then to load you read the values in the same order. By saving/loading variables such as X/Y position, inventory, status, etc you can "load" game to be to the same state as when the variables were saved. Perhaps someone like Mazer could show you an example of how to save using read/write and encription.
|
Author: | Mazer [ Tue Jul 22, 2003 2:26 pm ] | ||||
Post subject: | |||||
tony... you ok?
in case you're wondering, fileStream is an integer. before you go and save/load stuff you use the variable to open the text file with this line
that'll open the file for getting data. instead of the ", get" you could have ", put" and that would allow you to write to the file. but keep in mind as soon as you do that it will clear everything inside the file. |
Author: | Mazer [ Tue Jul 22, 2003 2:35 pm ] | ||
Post subject: | |||
tony wrote: Perhaps someone like Mazer could show you an example of how to save using read/write and encription. encryption... if you're referring to the encryption in the accounts for my game, i have to tell you it was really lazy just a simple encryption function
as for the strange and unreadable account files, it's just that i used binary file handling to read and write the data which was useful because that way people can't edit the file themselves. |
Author: | Archi [ Tue Jul 22, 2003 2:47 pm ] |
Post subject: | |
But in my case where I don't want to allow the player to edit the information i could use the write and read commands? |
Author: | Mazer [ Tue Jul 22, 2003 2:58 pm ] | ||||||
Post subject: | |||||||
if you don't want the user to edit the information then yes, i would suggest considering binary file handling (read and write as opposed to get and put). binary file handling is used for storing data that's in a record more easily but i like it best because of the fact that if someone tries to f*** around with the file it gets screwed up. anyways, have you're players information set up in a record like so:
that's just an example, you're probably storing more stuff so you'll have more variables. now when you want to store everything in the file:
note that you only have to write the player variable. that's really good if you have lots of variables to save and don't want to type out a put line for each one. and to read it's pretty much similar:
|
Author: | Archi [ Tue Jul 22, 2003 3:43 pm ] |
Post subject: | |
Well I got that ot work. Thanks for the help. Now comes another question. Is there any possible way to put the entire contents of a file onto the screen? Like I have a starting story that is rather long. If i write it into a *.txt file, then is there anyway that i could use the read/write, get/put combinations to take the contents of that file and place it directly on the screen? Also in doing so is there any way to have it read so many lines, then wait for payer input before placing the next so many lines? Also, how can i make the name of the file which the stats are saved to, dependant on the name of the player? So to allow multiple people to play on the same computer? |
Author: | Mazer [ Wed Jul 23, 2003 11:54 am ] | ||||
Post subject: | |||||
for showing a starting story to a game, you'll want to use normal file handling as opposed to binary. maybe show 6 or so lines of the story at a time then wait for.
that should do it as for the player's name and stuff, just save/load the file using the player's name. like:
that should load the player's info |
Author: | Archi [ Wed Jul 23, 2003 10:03 pm ] |
Post subject: | |
How do I make it so that it puts more than one word on a line? |
Author: | PaddyLong [ Thu Jul 24, 2003 12:30 am ] |
Post subject: | |
same way you do to output to the run window, just put a .. after it |
Author: | Archi [ Thu Jul 24, 2003 12:45 am ] |
Post subject: | |
i'm not sure i get what you mean... Well rather..i dunno where ot put the ".." |
Author: | PaddyLong [ Thu Jul 24, 2003 10:54 am ] |
Post subject: | |
well you know how when you're outputting to the run window and want two put statements to be on the same line... you can do it as put var1, var2 or put var1 .. put var2 |
Author: | Archi [ Thu Jul 24, 2003 11:15 am ] |
Post subject: | |
That I understand. Its where to put it in the loop that mazer gave me... |
Author: | Archi [ Thu Jul 24, 2003 2:00 pm ] |
Post subject: | |
I don't know where I'm to put the ".." in the part of the code Mazer gave me.... |
Author: | PaddyLong [ Fri Jul 25, 2003 2:16 pm ] |
Post subject: | |
o, it's because you don't need to... in mazer's he's using read/write rather than get/put. read/write makes a binary file that isn't really readable with a regular text editor (you can read it, but it will look a little wrong). so with read/write you don't need to worry about putting it on the same line or whatever |
Author: | Mazer [ Fri Jul 25, 2003 3:58 pm ] | ||
Post subject: | |||
i think he's talking about the first bit of code for showing the story of the game.
sorry, forgot about basic string input. since there are spaces and you want the whole line, you need to put :* after the get part |
Author: | Archi [ Fri Jul 25, 2003 5:27 pm ] |
Post subject: | |
Sweet, that works.. Now i gotta figure out how to make it so that it will exit that routine after the user presses a key. |
Author: | AsianSensation [ Fri Jul 25, 2003 8:47 pm ] | ||
Post subject: | |||
this will do it |
Author: | Archi [ Fri Jul 25, 2003 11:10 pm ] |
Post subject: | |
Got it to work a different way. Now it doesn't want to end the loop when I want it to. In order for it to continue processing I have to minimize the window and bring it back up... |