I'm able to save a variable in a file...
function savescore(score)
if file exist("datascore.dat") then delete file "datascore.dat" : ` remove the score file. use
open to write 1, "datascore.dat" : ` create a new one
write file 1, score : ` write the score to the file
close file 1 : ` close the score file
endfunction
It creates a file in that directory, but when I try to load the value with this...
function getscore()
if file exist("datascore.dat")
open to read 1, "datascore.dat" : ` Open the hiscore file
read file 1, score : ` read in the hiscore
close file 1 : ` close the hiscore file
else
score=0 : ` when the file does not exist, pass back a zero
endif
endfunction
... it doesn't work. Either my save function isn't saving the score value, or my load function isn't setting score to the saved value. I've used those two code snippets to save a score at the close of a program and load it again when the same program reopens. This time, I'm saving a score at the end of one program, closing that program, loading a different program, and trying to load the score value.
I don't have anything misspelled in the code. The functions are called correctly in the code. I can't wrap my head around why it works when saving and loading the same file within one program and why it doesn't work when saving in one program and loading in another.