Well, depending on how the game is made, what variables are stored as what, etc. will determine how to make the save function.
Let's say you just wanted to save the score. Maybe you have a variable called score. An easy way is to make sure that score is a string variable. If it's not, you can make it one with the STR$() function.
Ok score (an interger) equals 5000. Now let's turn it into a string and save it.
savescore$ = str$(score)
I just created a string variable called savescore$ out of the integer score. Now to save it:
file$="c:\my_program\score.txt"
open to write 1,file$
write string 1,savescore$
close file 1
to read it back:
open to read 1,file$
read string 1,savescore$
close file 1
The thing about saving and loading a file is, if it exists, it can't be created, if doesn't exist, it can't be loaded. So somewhere in your function you have to test if the file exist and then handle that condition. Here's a function that combines both the reading and writing of the score. You will have to modify the path to a location you want. I have a delete file call in the function so you'll want to make sure that a file named
highscore.txt that you want to keep isn't in the path you choose.
score=5000
savescore$=str$(score)
aftersave$=handle_file("S","c:\someplace\highscore.txt",savescore$)
print aftersave$
end
function handle_file(action$,path$,savescore$)
rem action determines save or load use S for save and L for load
rem path$ is the full directory and filename of the file you want to
rem save or load
rem savescore$ is the score for this example
rem save the score
if action$="S"
rem if it exists, delete it and replace it
if file exist(path$)=1 then delete file path$
open to write 1,path$
write string 1,savescore$
close file 1
endif
rem load the score
if action$="L"
if file exist(path$)=1
open to read 1,path$
read string 1,savescore$
close file 1
else
rem handle the file esit situation here - I'm just stopping the program
break "File <"+path$+">" does not exist"
endif
endif
rem return the score in either case back to the program
endfunction savescore$
You can apply this idea to whatever variables in the game that you want to save so that the next time someone wants to play, they can load up the saved values.
Enjoy your day.