Quote: "How can I write these floats to a file ?
And how can I load it and tell the program what is what ?
"
Why you are using floats for those variables is beyond me, as float precision is not needed. It would be better to simply use integers. Anyway, it can be done by converting the floats to strings, and back, like this:
dim DataToSave#(6)
level# = 14.0 : DataToSave#(1) = level#
health# = 22.3 : DataToSave#(2) = health#
character# = 17.0 : DataToSave#(3) = character#
money# = 1004.0 : DataToSave#(4) = money#
experience# = 54.0 : DataToSave#(5) = experience#
weapon# = 9.0 : DataToSave#(6) = weapon#
gosub DisplayVars
file$ = "media\MyData.ck"
if file exist(file$) = 1 then delete file file$
open to write 1,file$
for d = 1 to 6
a$ = str$(DataToSave#(d) )
write string 1,a$
next d
close file 1
// zero out all of the values
for d = 1 to 6
DataToSave#(d) = 0.0
next d
// display the contents of the variables
gosub DisplayVars
open to read 1,file$
for d = 1 to 6
a$ = str$(DataToSave#(d) )
read string 1,a$
DataToSave#(d) = val(a$)
next d
close file 1
gosub DisplayVars
end
DisplayVars:
repeat
cls
for d = 1 to 6
text 100,d * 20,"DataToSave#(" + str$(d) + ") = " + str$(DataToSave#(d) )
next d
text 400,400,"Press any mouse button to exit."
until mouseclick() > 0
cls
repeat : // wait until the user lets go of the mouse button before returning
until mouseclick() = 0
return
You will need to create a folder that has within it a folder named 'media'. The code will write the file in the media folder.