Posted: 30th Dec 2011 7:25
Why isn't this working?. It doesn't matter if I set the append flag to 0 or 1 and doesn't make a difference what kind of data I'm writing to a file; WriteFloat()/WriteInteger()/WriteLine()/WriteString(); the file extension deosn't make any difference either, no changes appear in the file.

I wrote the following piece of code to confirm my suspicions.

The file "test.txt" is in the media folder. The program examples in the "AGK\Projects\Basic\Examples\Files" don't seem to be working either.

+ Code Snippet
fileName$ = "test.txt"
fExist = 0

if GetFileExists(fileName$) = 1
    file = OpenToWrite(fileName$, 0)
    WriteLine(file, "New Data")
    CloseFile(file)
    fExist = 1
endif

do
    print(fExist)
    sync()
loop
Posted: 30th Dec 2011 8:06
What's even more weird, if I run the program below I get the data on the screen but any file in the media folder doesn't get changed, the file isn't created in the media folder if it doesn't already exist either.

I'm coding my own level editor, so I really need the file to be in the folder so that I can copy and paste it into any game projects.

+ Code Snippet
fileName$ = "test.txt"
fExist = 0

if GetFileExists(fileName$) = 1
    file = OpenToWrite(fileName$, 0)
    WriteLine(file, "New Data")
    CloseFile(file)

    fExist = 1
endif

do
    file = OpenToread(fileName$)

    do
        if FileEOF(file) = 1 then exit
        print(ReadString(file))
    loop

    CloseFile(file)

    print(fExist)
    sync()
loop
Posted: 30th Dec 2011 8:19
the file isn't created in the media folder if it doesn't already exist either.

No it won't be.

It'll be created (on pc at least) in the "My Documents > AppGameKit > FULL_PATH_TO_AGK_PROJECT\" folder

As AppGameKit runs in a sandbox, you do not have write permissions to anywhere but a set folder. Anything using the write/read commands need to be located here.
Posted: 30th Dec 2011 8:33
I am using a PC and I'm attempting to use the files relative to the project folder.
Posted: 30th Dec 2011 9:01
Open to write will not write to the project folder, but to the my documents folder.
Posted: 30th Dec 2011 9:21
Thanks for that, I get what you mean, I can get on with the project now. You've been extremely helpful.

I thought I was going to have to revert back to DBPro or Blitz3D to do my tool making for a moment there. LOL
Posted: 30th Dec 2011 13:07
Another handy tip - on Android (And possibly others) the file is empty if the program doesn't close it (ie the program crashes). I use it for debugging, and have a system whereby the file gets closed and reopened regularly so that I have something to look at if the program bombs out.

On PC, it works ok, the data seems to be written immediately.
Posted: 30th Dec 2011 18:56
Steve, I have another thread where I was having similar problems. First, if you search on your C drive for "text.txt", you will see that it is being created as Mobiius stated.

I was having trouble with my app overwriting files using the append=0 parameter in the WriteToFile function. I just found the problem. I have to run the compiled .exe as the "administrator" on my computer. I'm running Vista and I have run across this problem before. It a pain. I have to compile, file the .exe in file explorer, right click, and select to "run as adminsitrator".

This solved it for me. What OS are you running?
Posted: 30th Dec 2011 19:25
I'm running Windows XP.
Posted: 30th Dec 2011 19:28
If it saves files to MyDocuments, how does it store game progress and score data on a device?.

[edit]I have an iPod touch but don't have a Mac to compile stuff on, so I haven't had chance to experiment properly yet.[/edit]
Posted: 30th Dec 2011 20:08
If it saves files to MyDocuments, how does it store game progress and score data on a device?


Every platform has a "safe storage" folder. On Android it is a subfolder of your AppGameKit executable.
Posted: 31st Dec 2011 20:54
Thanx for your help, I understand now.