Hey all, I'm trying to learn how to save a high score variable into a file that DB can read back.
I've looked at the DB example program 'Open to Write' (Code:
Dim HighScore$(10,10)
for mode=0 to 1
rem Clear screen
cls rgb(rnd(100),rnd(100),rnd(100))
rem Delete file
if file exist("data.dat") then delete file "data.dat"
rem Write or Read..
if mode=0
rem Open file for writing
open to write 1,"data.dat"
rem Write data types
write byte 1,1 : print 1
write word 1,2 : print 2
write long 1,3 : print 3
write file 1,4 : print 4
write float 1,5.5 : print 5.5
rem Write matrix of strings
for x=1 to 10
for y=1 to 10
a$=str$(x)+str$(y)
HighScore$(x,y)=a$
write string 1,a$
next y
next x
rem Close file
close file 1
rem Rename file
if file exist("store.dat")=0
rename file "data.dat","store.dat"
endif
else
rem Move file
move file "store.dat","data.dat"
rem Open file for reading
open to read 1,"data.dat"
rem Display data types
read byte 1,a : print a
read word 1,a : print a
read long 1,a : print a
read file 1,a : print a
read float 1,a# : print a#
rem Read matrix of strings
for x=1 to 10
for y=1 to 10
read string 1,a$
HighScore$(x,y)=a$
next y
next x
rem Close file
close file 1
rem Move file back
move file "data.dat","store.dat"
endif
rem Display matrix of strings
print
for x=1 to 10
for y=1 to 10
print HighScore$(x,y);" ";
next y
print
next x
rem Wait for key press
print
if mode=0 then print "Press Any Key To Read Data"
if mode=1 then print "Press Any Key To Exit"
suspend for key
next mode
rem Make an empty file if none exist
if file exist("scores.txt")=0
make file "scores.txt"
endif
rem End of program
end), but I have no idea how I would implement it into my game. The question I have is, how do I save my variable ('Score') to a file? What commands would I use? I've tried searching the help files...I don't really understand the process that well. Does anyone know of any online tutorials that show you how to save a high score file? And help/comments or whatever is appreciated!
Check out my programming blog!