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.

Newcomers AppGameKit Corner / Can't read file - help?

Author
Message
Golelorn
2
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 18th Aug 2018 03:21 Edited at: 18th Aug 2018 19:08
EDIT:
I have solved this. Read the last post for the answer. This is not readily apparent to newbs. Spent way too much time on this. Perhaps, update in the help files that ReadLine will continue to read the next line if the file is open. That would have solved hours of frustration.



No idea why I can't get any command to read the lines in this file.

I have tried readline and readstring. I have seterror(mode) =2.

File content


Read file

Only the first line is returned so token_count = 8

Code to write to file




Not sure what I am doing wrong here. I have tried both line and string commands. Only getting the first line read.
Bengismo
1
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 18th Aug 2018 04:28
You dont appear to be opening file id 1 at all..

OpenToRead( "home_area_save.txt" )

this should be:

OpenToRead( 1, "home_area_save.txt" )

Golelorn
2
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 18th Aug 2018 14:08 Edited at: 18th Aug 2018 19:11
...
Golelorn
2
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 18th Aug 2018 16:26 Edited at: 18th Aug 2018 19:10
Not needed

Attachments

Login to view attachments
Golelorn
2
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 18th Aug 2018 17:34 Edited at: 18th Aug 2018 19:12
How to read every line:
I suppose you could also add a counter to read a certain amount of lines.
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 29th Aug 2018 13:48
Well, readline does exactly what the word says, it reads A line. You have 6 lines, therefore, you have to read the line 6 different times. If it read all of them at the same time, I suppose the command would be readLines instead, but that would be horrible inefficient and eat a lot memory on large files.

Quote: "This is not readily apparent to newbs. "

Well it does say in the help file "Reads a new line terminated string from the given file". But I'd agree with you, if you're not familiar with how sequential file reading works you might not understand there's an internal index pointer that moves along the opened file with each read command called on it.

Alternatively, you can think of a memblock as a sort of random-access file, in which you must specifically state the byte position you start reading from and how many bytes to read.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Golelorn
2
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 29th Aug 2018 17:56 Edited at: 30th Aug 2018 01:44
The missing part is the help files does not let the user know there is an "internal index pointer". Its not readily apparent that you can just use a loop - simple if you know it, but frustrating if you do not. I had no idea it would increment.

I knew it would read one line. The problem was I had no idea I could use a loop, to get to the next lines.

Login to post a reply

Server time is: 2019-09-22 03:29:24
Your offset time is: 2019-09-22 03:29:24