Computer Science Canada

SAVE / LOADING games

Author:  SNIPERDUDE [ Mon May 08, 2006 5:26 pm ]
Post subject:  SAVE / LOADING games

I'm creating a game and I've made it so I can save and return to a given area, but I don't know how to make it so I can save the game so that I can close the applet and return to the saved game.

How do I do this

Any help would be appreciated . Scatter

Author:  pavol [ Mon May 08, 2006 5:46 pm ]
Post subject: 

if you know how to work with files, then you can just save the value of your variables in it and when you load the game, just open the file and read the values into your variables. if you don't know how to work with files then just ask

Author:  SNIPERDUDE [ Mon May 08, 2006 6:04 pm ]
Post subject: 

I tried a tut, but it didn't help much. How can I save the integers on a txt, would the ints just be considered a string. I am just confused, so if you can help me out by being specific and posting a code example - that would be great. Confused

Author:  HellblazerX [ Mon May 08, 2006 6:27 pm ]
Post subject: 

Have you tried this tutorial, cuz it's pretty simple. And if you properly write those integers into the file, then you should be able to read them as integers. A simple program that would use a file would look like this:

code:
var file : int %Variable for the file
var fileName : string := "file.txt" %File name
var input : int %Variable to store input from the file
open : file , fileName, put
put : file , 5
close : file
open : file, fileName, get
get : file , input
close : file
put input

Author:  SNIPERDUDE [ Mon May 08, 2006 6:37 pm ]
Post subject: 

[code]put : file , 5[/code]

/\
what does the 5 mean?

Author:  HellblazerX [ Mon May 08, 2006 7:06 pm ]
Post subject: 

With that code, I'm writing the number 5 into the file. So with the put command, the first variable, file, states which file I'm writing to, and the second part states what I am writing, which in this case is the 5.

Author:  SNIPERDUDE [ Mon May 08, 2006 7:58 pm ]
Post subject: 

Seems to make sense, but how do I save several ints?

And how would I get back and read several ints?

Author:  Bored [ Mon May 08, 2006 9:02 pm ]
Post subject: 

Well after each put statement it will add a new line tab so when you want to read an integer it would be:
get : file, variable
When putting to a file it's the same as putting to the screen only it's save as a txt and not displayed in the window. Then each line is like a predefined user input so you simply get the information with the get command. It works the same as user input with the put and get commands only it's getting from a file rather then the user and putting to a file rather then the screen.

Author:  SNIPERDUDE [ Tue May 09, 2006 6:46 am ]
Post subject: 

Thx, I'll try it out...

I'll b back if I need any more help.


: