Posted: 8th Sep 2011 6:34
So was hoping to get a little help, can't quite figure out how a text file should be set up to be able to read back from it. I'm hoping to store a bunch of coordinates for sprites and other level data, but right now I can't get it to read anything. Anyone have an example file to read from and some code that works? Thanks.
Posted: 8th Sep 2011 6:45
Just load up the example read and write projects that come with AGK. That should get you started.
Posted: 8th Sep 2011 8:11
Hmm, I just pulled those up but its not writing out the .txt file that it is supposed to, no errors that I can tell either.
Posted: 8th Sep 2011 9:37
Hmm, I just pulled those up but its not writing out the .txt file that it is supposed to, no errors that I can tell either.

AGK has a default file writing folder which is located in Documents and it doesn't write to the project folder. So check your documents folder. It should be something like Documents - AppGameKit - some madly long folder name. AppGameKit does this because on some platforms like iOS there is only one place an app is permitted write files to.
Posted: 8th Sep 2011 12:31
As Hodgey says, AppGameKit puts the file where it must. It's kind of like the ID system for entities, where you don't know what the ID of the sprite is, and you don't care what the ID of the sprite is.

In your case, does it matter where the file is? Post some code so we can see what might be the problem.

If you want to know where AppGameKit is writing to and reading from, you can us GetWritePath().

Here's an example based on the one that comes with AGK.

+ Code Snippet
OpenToWrite ( 1, "myfile.txt", 0 )
    WriteInteger ( 1, 10 )
    WriteFloat ( 1, 1.23 )
    WriteString ( 1, "hello" )
CloseFile ( 1 )

// reading from a file
OpenToRead ( 1, "myfile.txt" )
    a = ReadInteger ( 1 )
    b# = ReadFloat ( 1 )
    c$ = ReadString ( 1 )
CloseFile ( 1 )

d$ = GetWritePath()

do
    Print("Integer: " + str(a))
    Print("Float  : " + str(b#,2))
    Print("String : " + c$)
    Print("")
    Print("Your file path is:")
    f = 0
    for e = 1 to len(d$)
        if mid(d$, e, 1) = "\"
            print(mid(d$, f, e - f + 1))
            f = e + 1
        endif
    next c
    sync()
loop



The filepath is really long, probably so long that it would run off the right side of the screen, so I broke it up into separate strings. It's sloppy, but it will show you where your files are going. The last part is so long that you may need to set your screen to a landscape type resolution (640, 480) to see it.
Posted: 8th Sep 2011 18:01
Ah, I thought I had read somewhere that it would write out to the media folder, I'll have to look at that other directory when I get off work. Thanks again.
Posted: 9th Sep 2011 3:06
Ok, so after playing around with this for a bit, I realize the issue I had understanding it. It is not actually writing out ascii values to the file. I had hoped to use a csv file or something as the source of the data but it looks like that will not work like I planned. Thanks both of you for the help.
Posted: 9th Sep 2011 3:21
Oh, hey, what you want is ReadLine instead of ReadString, it will read in each line as text.
Posted: 9th Sep 2011 3:39
Well, that doesn't really do what I was after easily either. This works, and actually solves the issue of putting some slight tamper protection on the level/score data. I just made a helper program now to write out the data file to use, vs exporting it from a spreadsheet.