Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
MrPickle
Prole
Posts: 24
Joined: Thu Jul 10, 2008 11:43 pm
Location: United Kingdom, Lincolnshire

I'm struggling to read a file under löve?

I know love.filesystem.open( file ) but that returns a boolean? so how can that boolean be the file? I'm confused by that.

Could someone provide an example of how to open a file and read it line by line? (The tutorials could do with one on reading files if I do say so myself)

Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

### Re: Reading files under Löve

I believe it opens a buffer or some shit and the boolean is the success of it.

Once you have opened it you then need to manually read line by line or a given string length. Maybe you have come from an unprofessional shit thing like Garry's Mod where everything is handed to you on a plate with a knife, fork, and dessert. However, here you have almost direct access to the file system.

cag
Citizen
Posts: 65
Joined: Sun Jun 29, 2008 5:09 am

### Re: Reading files under Löve

Psst:
love.filesystem.newFile( filename, mode )

it's not *just* for making new files. you can create a buffer to open your file in with this as well!
that said, booleans are not files. however, booleans can tell you if something is successful or not. newFile returns a file, which can be opened.

MrPickle
Prole
Posts: 24
Joined: Thu Jul 10, 2008 11:43 pm
Location: United Kingdom, Lincolnshire

### Re: Reading files under Löve

Kudomiku wrote:I believe it opens a buffer or some shit and the boolean is the success of it.

Once you have opened it you then need to manually read line by line or a given string length. Maybe you have come from an unprofessional shit thing like Garry's Mod where everything is handed to you on a plate with a knife, fork, and dessert. However, here you have almost direct access to the file system.
I haven't come from Garry's Mod, but I do play Garry's Mod and I've never coded for it, Löve is the only LUA experience I have.
If you really must know my background I started with TGE and I normally code with C++ & OpenGL but I had an idea and felt like making in with Löve.
cag wrote:Psst:
love.filesystem.newFile( filename, mode )

it's not *just* for making new files. you can create a buffer to open your file in with this as well!
that said, booleans are not files. however, booleans can tell you if something is successful or not. newFile returns a file, which can be opened.
I was reading the documentation and saw that, thought it would just be for creating files so I didn't have a look I'll take a gander at it.

rude
Posts: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

### Re: Reading files under Löve

Related info:
In the next version, you'll be able to use love.filesystem without having to manage file handles.

Code: Select all

-- Read file contents directly

-- Iterate over the lines in a file:
for line in love.filesystem.lines("filename.txt") do
...
end


MrPickle
Prole
Posts: 24
Joined: Thu Jul 10, 2008 11:43 pm
Location: United Kingdom, Lincolnshire

Ahh, cool.

### Who is online

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