Page 1 of 2

Reading and writing

Posted: Wed Apr 18, 2012 10:12 am
by Delibrete
How would one go about reading and writing to text files with love?

Re: Reading and writing

Posted: Wed Apr 18, 2012 12:43 pm
by Roland_Yonaba
In pure Lua, you should have IO library... Working with löve, ou should take a look at love.filesystem. All functions you do need to perform what you want are packed in that table.

Re: Reading and writing

Posted: Thu Apr 19, 2012 8:01 am
by Delibrete
Roland_Yonaba wrote:In pure Lua, you should have IO library... Working with löve, ou should take a look at love.filesystem. All functions you do need to perform what you want are packed in that table.
I see the functions are there, but I don't know how to use them. How would I use those functions?

Re: Reading and writing

Posted: Thu Apr 19, 2012 9:14 am
by trubblegum
Delibrete wrote:
Roland_Yonaba wrote:In pure Lua, you should have IO library... Working with löve, ou should take a look at love.filesystem. All functions you do need to perform what you want are packed in that table.
I see the functions are there, but I don't know how to use them. How would I use those functions?
Is it really more work to click a link than it is to write a forum post asking someone else to do it for you?
If your attention span is so short that you didn't get as far as the example code at the top of the page in the docs, then programming is not for you.

Re: Reading and writing

Posted: Thu Apr 19, 2012 9:29 am
by Delibrete
trubblegum wrote:
Delibrete wrote:
Roland_Yonaba wrote:In pure Lua, you should have IO library... Working with löve, ou should take a look at love.filesystem. All functions you do need to perform what you want are packed in that table.
I see the functions are there, but I don't know how to use them. How would I use those functions?
Is it really more work to click a link than it is to write a forum post asking someone else to do it for you?
If your attention span is so short that you didn't get as far as the example code at the top of the page in the docs, then programming is not for you.
Well I've been trying for a few days now to read and write to text files, but it's ok now I've figured it out. But you're right, programming is probably not for me.

Re: Reading and writing

Posted: Thu Apr 19, 2012 10:43 am
by trubblegum
No worries .. some people are programmers, others are designers, and yet others are taxidermists.
But Rome wasn't built in a day, so don't give up just yet :)

Re: Reading and writing

Posted: Thu Apr 19, 2012 10:49 am
by Delibrete
trubblegum wrote:No worries .. some people are programmers, others are designers, and yet others are taxidermists.
But Rome wasn't built in a day, so don't give up just yet :)
I've been trying for years to become a programmer and a designer, hopefully I'll get there eventually. Thanks man :)

Re: Reading and writing

Posted: Sun May 13, 2012 4:27 am
by sanjiv
Help. In the following code, I'm trying to write 'hello text file!' to text.txt at the root of my game folder (same level as main.lua). Basically, I want to run the LOVE game, press a key, and have something written to a file.

Code: Select all


function love.load()

   text= love.filesystem.newFile( 'text.txt' )

end

function love.keypressed(key,unicode)

   if key == "space" then
	txt:open('w')
	txt:write("hello text file!")
   end

end

1) How do I get this to work?
2) What if I want to write to text.lua instead of text.txt?
3) What about navigating into folders within the game folder?

Re: Reading and writing

Posted: Sun May 13, 2012 9:48 am
by Zeliarden
Hi!

1.

Code: Select all

   if key == "space" then
should be

Code: Select all

   if key == " " then
and

Code: Select all

   txt:open('w')
   txt:write("hello text file!") 

Code: Select all

   text:open('w')
   text:write("hello text file!")
as you used text (not txt) as variable name at love.load()

2.
change 'text.txt' to 'text.lua'

3.
https://love2d.org/wiki/love.filesystem
love.filesystem can only read/write to that special directory. If you want to save at an other dir you have to use
http://www.lua.org/manual/5.1/manual.html#pdf-io.close
but I would not recommend it

Re: Reading and writing

Posted: Sun May 13, 2012 11:22 am
by Nixola
Why should text.txt become text.lua?