interacting with txt files?

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
Evil_Bartek
Prole
Posts: 43
Joined: Sun Dec 25, 2011 5:13 pm

interacting with txt files?

Post by Evil_Bartek »

Is there a way to read a txt file? Like getting the contents of it and putting it into a string?
User avatar
IMP1
Prole
Posts: 43
Joined: Mon Oct 03, 2011 8:46 pm

Re: interacting with txt files?

Post by IMP1 »

love.filesystem seems to be what you're looking for. Particularly http://love2d.org/wiki/love.filesystem.read ?
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: interacting with txt files?

Post by Ellohir »

This may not be the proper way to do it but I find it very easy to use:

Code: Select all

mapstring = love.filesystem.load("map1.lua")() -- the last parenthesis execute the code
and on "map1.lua", in the working directory:

Code: Select all

return { "0011000\n0000001\n0010011"  }
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: interacting with txt files?

Post by Jasoco »

Both are correct. The former will load a text file in as lines. The latter executes it as if it's code. Using the return in the loaded file will return it through the load function.
Post Reply

Who is online

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