Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / What's up with OpenToRead and WriteToRead commands?

Author
Message
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 2nd Apr 2013 22:56
I'm trying the file access examples and none of them really works. Where is the "myfile.txt" in these examples located?

I also try to create a "myfile.txt" with openToWrite in my own project, but no file is created in the media folder.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Apr 2013 22:57
On windows, writing files go to the My Documents folder.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Apr 2013 23:00
It could be that they forgot to include it, or the intention is that you use any file you like.

Ensure that you close any file you open, whether to read or write to it.

Also, to read a line of text, use the ReadLine() command instead of ReadString - ReadString will load the whole file into one string, assuming that's not what you're after.

I got a fever, and the only prescription, is more memes.
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 2nd Apr 2013 23:10 Edited at: 2nd Apr 2013 23:11
Ok. Thanks.
So as I understand it - even if I use a project folder on another drive for my application - agk on windows will check the media folder in my documents for media and if it's not there - will then check the local media folder?
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Apr 2013 23:41
It checks the My Documents folder first, if the file is not located there, it will check the media folder.

That way you can ship with files you can read in the media folder, and any files you create at first run, will be saved into the "Sandbox Area", which on windows is my documents.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 3rd Apr 2013 00:01
Ok. But as a note: I created a textfile in my Project/Media map and deleted the one in User/My Documents/Agk/My Project/Media.
OpenToRead worked fine on this file.

But when I use OpenToWrite with the same filename it does not use the local one - it creates a new file in my documents. And I end up with two files.

I know you can't write to executables but you should be allowed to create a new file "wherever" you want. On some small projects I don't want to mess with user "centric" folders - I want to work in the applications folder. Just to keep things tidy.

Is this possible?
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 3rd Apr 2013 00:22
You can use SetRawWritePath on Windows to change the write path to wherever you want, but the user will need admin privileges to write to the Program Files folder. On Mac, iOS, and Android it is not possible to write to the executable folder.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 3rd Apr 2013 03:38
The OpenToWrite command works in the sand box area by default.

On Windows only, in theory anyway, you can use the SetRawWritePath to change that. But the app needs the proper permissions, as Paul says.

OpenToRead always checks in the sand box area first and then the local media area (the media directory for Tier 1 or the executable directory for Tier 2).

If you create a file with OpenToWrite that has the same name as one in the local media directory, that is the one used for the next OpenToRead for that file name. Unless you delete it, then the OpenToRead will go after the one in the local media directory again.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 3rd Apr 2013 12:43
Thanks a bunch. I've sorted it out.

Now I have a follow up:

What kind of format does agk use when writing to a file. I want to create a file that is readable and editable in a notepad. The result in the file is not.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 3rd Apr 2013 16:49
If you want it readable/writable by notepad, you use only the WriteLine and ReadLine commands.

The WriteString, WriteFloat, etc. output data in a binary format and the results is definitely not human readable.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 3rd Apr 2013 20:27
Ah. Great. Thanks.

Login to post a reply

Server time is: 2024-05-06 09:08:25
Your offset time is: 2024-05-06 09:08:25