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 counts as a CR(\n) for ReadLine ( ) ?

Author
Message
Rknight
20
Years of Service
User Offline
Joined: 25th Sep 2003
Location: NJ
Posted: 26th Nov 2013 08:45
Help says:

Reads a CR(\n) terminated string from the given file, which must have been opened for reading. If you use this command in tier 2 you must delete the returned string when you are finsihed with it.

...

What counts as a CR(\n) terminated string? In ASCII?

I tried adding CHR(10) and CHR(13) to line ends, no success. Since ReadString reads the entire text file, and byte by byte is too slow, I need to find out what the delimiter is?
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 26th Nov 2013 09:18
You should use chr(13)+chr(10), not chr(10)+chr(13) - 13 is the carriage return, 10 is the line feed, and text is delimited with 13+10, but chr(10) works as a new line in text in AGK.

I don't think reading the whole string is wise though, there seems to be some unpredictable-ness with loading strings. I would suggest loading the file byte by byte, but then saving out your own neat, delimited version... maybe just need to ensure that each line is <256 characters.

I am the one who knocks...
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 26th Nov 2013 09:25 Edited at: 26th Nov 2013 09:30
Well text files I make in notepad++ create lines that AppGameKit successfully reads separately. With all characters displayed I see those lines are ended with CRLF which is chr(13) and chr(10) next to each other with no spaces obviously. That should work. If it doesn't, I suspect there is something amiss in the text file you're reading.

Edit: Van beat me to it, and now he will take his rightful place as Emperor.

Rknight
20
Years of Service
User Offline
Joined: 25th Sep 2003
Location: NJ
Posted: 26th Nov 2013 09:42
Well, no I did try it both ways, and singly each. Hmm. I wonder what is wrong.
Rknight
20
Years of Service
User Offline
Joined: 25th Sep 2003
Location: NJ
Posted: 26th Nov 2013 09:45 Edited at: 26th Nov 2013 09:47
Ah, I think FileEOF() is saying it's at file end after ReadLine() that is actually the trouble.

Hmm.
Rknight
20
Years of Service
User Offline
Joined: 25th Sep 2003
Location: NJ
Posted: 26th Nov 2013 09:49
Yup, that's it. It reads one line, but the REPEAT/UNTIL ends instantly with FileEOF().
Rknight
20
Years of Service
User Offline
Joined: 25th Sep 2003
Location: NJ
Posted: 26th Nov 2013 09:50 Edited at: 26th Nov 2013 09:50
Ah, it was my mistake all along. I had it UNTIL FILEEOF(1) instead of UNTIL FILEEOF(1)=1.

So simple a thing. My mistake! I've made that one before. Thanks for the help!
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 26th Nov 2013 10:51
Yeah, that bugs me a little. I often do "if function(blah)" statements, assuming the return of 1 will evaluate it to true, but apparently it doesn't (or doesn't always). Now I always add the "= 1".

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 26th Nov 2013 15:56
Also, make sure that you want ReadString and not ReadLine.

ReadString is for reading a binary file, one that is not generally meant to be human readable. It goes along with ReadByte/Integer/Float for binary files.

If you are editing the file in Notepad, then you probably mean to use ReadLine.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 26th Nov 2013 18:20
Quote: "Also, make sure that you want ReadString and not ReadLine."


Yep, made that mistake myself before a couple of times.

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 26th Nov 2013 18:31
Lol, I have to check the manual every time! Although Ancient Ladies explanation should help me remember in future

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 26th Nov 2013 19:01
WriteLine and ReadLine are for text files.

Read/Write Byte/Integer/Float/String are for binary.

And remember, it is extremely important to read the binary data using the same order of command as it was written. You won't get an error if you use the wrong command, just the wrong data and all subsequent reads will be incorrect.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 27th Nov 2013 00:06
Totally agree with AL. Binary files have their uses, but it's possible to get stuck with a format that becomes very hard to extend. I only use them for encrypted data for security reasons. Text files can be extended very easily without causing problems for older systems, which should ignore any fields they don't understand.

-- Jim - When is there going to be a release?

Login to post a reply

Server time is: 2024-05-20 13:29:16
Your offset time is: 2024-05-20 13:29:16