Earlier tonight, I wanted to add in a feature to my app that saves scores each time the user plays, so I tried to get some file reading/writing working.
Rather than put this into my app, instead I made a really simple program to do it - but it just won't seem to work.
I made a file called "savedata.txt", which contains the following text:
Quote: "SCORE_DATA_10_TOP_SCORES
110
100
90
80
70
60
50
40
30
20
10"
I then put this into my app's "media" folder, as well as the following folder:
C:\Documents and Settings\MY NAME\My Documents\AGK\C_ProgramFiles_TheGameCreators_AGKTrial_Projects_Basic_WriteReadFile_WriteReadFileexe\media
Here's the complete program:
global SAVE_FILE as integer
SAVE_FILE = OpenToRead( "savedata.txt" )
global teststring as string
do
Print("hello world")
teststring = ReadString(SAVE_FILE)
print(GetFileExists( "savedata.txt" ) )
print(teststring$)
Print(timer())
Sync()
loop
I'm expecting, on startup for it to print:
"hello world"
1
SCORE_DATA_10_TOP_SCORES
A timer (so I can see if it's crashed)
However, it gives me an error saying the file isn't there. I can guarantee it is there. I'm staring at it right now.
So, then I decided to try WRITING a file. I changed around the statements to get the program to write a new file (one I hadn't yet created) called "test.txt", and just to write:
test test test test
over and over again, in that file. It did this fine; I have a 400kb file just saying "test test test" etc. over and over again. So then, I tried to read this file and display the strings onscreen each frame, like in the example above. Naturally I expected:
"hello world"
1
test
A timer
But instead I got this:
"hello world"
1
<blank line>
A timer
So now I'm really confused. I can't see what I'm doing wrong. Does AppGameKit have file reading disabled or something in the trial version?