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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Calahagus
Prole
Posts: 6
Joined: Thu Jun 06, 2013 1:16 am

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

Post 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?
Last edited by Calahagus on Sat Jun 15, 2013 9:59 pm, edited 2 times in total.
User avatar
NightKawata
Party member
Posts: 294
Joined: Tue Jan 01, 2013 9:18 pm
Location: Cyberspace, Room 6502
Contact:

Re: How to read a specific line of a file

Post by NightKawata »

"I view Python for game usage about the same as going fishing with a stick of dynamite. It will do the job but it's big, noisy, you'll probably get soaking wet and you've still got to get the damn fish out of the water." -taylor
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

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

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post by bartbes »

I wonder what the problem is with keeping the entire file (as lines, probably) in memory?
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests