Reading and writing
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Reading and writing
How would one go about reading and writing to text files with love?
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: Reading and writing
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
I see the functions are there, but I don't know how to use them. How would I use those functions?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.
- trubblegum
- Party member
- Posts: 192
- Joined: Wed Feb 22, 2012 10:40 pm
Re: Reading and writing
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?Delibrete wrote:I see the functions are there, but I don't know how to use them. How would I use those functions?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.
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
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.trubblegum wrote: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?Delibrete wrote:I see the functions are there, but I don't know how to use them. How would I use those functions?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.
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.
- trubblegum
- Party member
- Posts: 192
- Joined: Wed Feb 22, 2012 10:40 pm
Re: Reading and writing
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
But Rome wasn't built in a day, so don't give up just yet
Re: Reading and writing
I've been trying for years to become a programmer and a designer, hopefully I'll get there eventually. Thanks mantrubblegum 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
Re: Reading and writing
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.
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?
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
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
Hi!
1.
should be
and
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
1.
Code: Select all
if key == "space" then
Code: Select all
if key == " " then
Code: Select all
txt:open('w')
txt:write("hello text file!")
Code: Select all
text:open('w')
text:write("hello text file!")
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
Why should text.txt become text.lua?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Who is online
Users browsing this forum: Ahrefs [Bot] and 2 guests