Page 1 of 1

[SOLVED] How to read a specific line of a file

Posted: Sat Jun 15, 2013 9:03 pm
by Calahagus
EDIT: I'm an idiot and got it working.

Alright, get yourselves ready for a noobie question.

I don't understand how I'd read a specific line of a .txt file. I'm looking to draw lines of dialogue from a text file outside of my main script, so currently I'm defining the file like this...

Code: Select all

jewelText = love.filesystem.newFile ("library/text/jewelText.txt")
...and then I assume I have to use love.filesystem.read to get the text from it, but the wiki doesn't say how to get a specific line from it. Is that possible or do I need to approach this a different way?

Re: How to read a specific line of a file

Posted: Sat Jun 15, 2013 9:11 pm
by NightKawata

Re: [SOLVED] How to read a specific line of a file

Posted: Sun Jun 16, 2013 3:03 am
by T-Bone
The "lines" function does iterate over all lines. So if your text file is really large, it can be slower than if you could just magically get a single line (which you cannot). If your files are so large that it would make a difference in performance, split it up into more files.

Re: [SOLVED] How to read a specific line of a file

Posted: Sun Jun 16, 2013 8:50 am
by bartbes
I wonder what the problem is with keeping the entire file (as lines, probably) in memory?