> ... save variables in a file and then be able to read them
> off. ive got 2 variables i want to save - playername$,
> totalscore#. ive tried putting them into arrays and saving/
> loading them but it just comes up with 'array name not valid'.
...
> also when i made the .sav file and opened it in notepad i
> forgot that i had the 'always open with this program' checked
> and now all of my .sav files are opened with notepad - is
> there any way of reversing this?
Try saving the data as a text file, then notepad becomes a feature and not a liability.
Yes, it can be changed. You need to open My Computer, click on the tools menu, select folder options, click on the file types tab, and find the SAV file extension in the list. You can then edit the settings.
SCORESAVE:
REMSTART
Design-wise you should not be loading the old score table
here and checking for new high scores. It is much better
to have the score table pre-loaded at the start of the game
so you can display it and edit the table right after a game
session has ended.
This should be done in a separate routine or function.
REMEND
` remove the old score table
if file exist("saves\score.sav") = 1 then delete file "saves\score.sav"
` create file and write data
open to write 1, "saves\score.sav"
` assume that the high score table has ten entries in it
for a = 1 to 10
write string name$(a)
write string str$(score#(a))
next
close file 1
return
`------------------------------------------------
SCORELOAD:
` check for score table
if file exist("saves\score.sav") = 1
` open file and read data
open to read 1, "saves\score.sav"
` assume that the high score table has ten entries in it
for a = 1 to 10
read string 1, name$(a)
read string 1, temp$: score#(a) = val(temp$)
next
close file 1
else
` no save data - create bogus high score table
for a = 1 to 10
` random initials from ascii codes
r1 = int(rnd(26))+65
r2 = int(rnd(26))+65
r3 = int(rnd(26))+65
name$(a) = chr$(r1)+chr$(r2)+chr$(r3)
` count down from 10,000 to 1,000
score#(a) = (11-a)*10000
next
endif
return