Page 1 of 1
I'm Having a little trouble.. Can anyone help?
Posted: Sun Oct 17, 2010 12:45 pm
by draa0gon
I'm having Some trouble with love.filesystem.write, it works when I use
Code: Select all
data, size = love.filesystem.read("opts.txt", all )
a = data * 1
love.filesystem.write("opts.txt", a, all )
but not when I use
Code: Select all
stuff = {}
for line in love.filesystem.lines ("opts.txt") do
table.insert (stuff, line)
end
a = stuff[1] * 1
love.filesystem.write("opts.txt", a, all )
-- error: Could not open file.
So, Could someone please tell me what I am doing wrong?
Thanks in advance.
Re: I'm Having a little trouble.. Can anyone help?
Posted: Sun Oct 17, 2010 12:48 pm
by nevon
draa0gon wrote:-- error: Could not open file.
So, Could someone please tell me what I am doing wrong?
Thanks in advance.
Which line is causing the error? Is it love.filesystem.lines or love.filesystem.write?
Re: I'm Having a little trouble.. Can anyone help?
Posted: Sun Oct 17, 2010 12:54 pm
by draa0gon
The error is from "love.filesystem.write("opts.txt", a, all )"
Re: I'm Having a little trouble.. Can anyone help?
Posted: Sun Oct 17, 2010 1:02 pm
by draa0gon
Also..
The first part of each code is run in love.load,
But the second parts are run when a key is pressed.
I just omitted that code 'cause I figured it wouldn't make a difference.
I'm not getting any errors anywhere else, but if you need the whole code I can put it up.
Re: I'm Having a little trouble.. Can anyone help?
Posted: Sun Oct 17, 2010 1:39 pm
by Robin
I think maybe love.filesystem.lines doesn't close the file... that would be a bug in LÖVE.
Re: I'm Having a little trouble.. Can anyone help?
Posted: Sun Oct 17, 2010 2:47 pm
by draa0gon
Yeah... I thought so.. *sigh* I hoped I just did something wrong..
oh well, is there any way to force close the file,
or another simple way to get lines?
I guess I could just write a function to take the lines I want myself, but I hoped I wouldn't have to..
Less work = better, yes?
Re: I'm Having a little trouble.. Can anyone help?
Posted: Mon Oct 18, 2010 9:59 am
by draa0gon
Well, I wrote the function, it works by finding spaces.
I'm sure any of you could make something like this, But hopefully it helps someone.
Please excuse my sloppy programing, I'm told it burns eyes.
Code: Select all
function love.load()
stuff = {}
data , size = love.filesystem.read("YourFileNameHere.txt",all)
findspaces(data,size,stuff)
a = stuff[1] * 1
end
function findspaces(text,size,Table)
oi = 1
flow = 0
for i = 1,size do
flow = flow + 1
dig = string.sub(text,i,i)
if dig == " " then
line = string.sub(text,oi,flow - 1)
table.insert(Table,line)
oi = flow
end end end
function love.draw()
love.graphics.print(a,200,200)
end