I'm Having a little trouble.. Can anyone help?

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
User avatar
draa0gon
Prole
Posts: 5
Joined: Mon Jul 12, 2010 6:07 am

I'm Having a little trouble.. Can anyone help?

Post 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.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: I'm Having a little trouble.. Can anyone help?

Post 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?
User avatar
draa0gon
Prole
Posts: 5
Joined: Mon Jul 12, 2010 6:07 am

Re: I'm Having a little trouble.. Can anyone help?

Post by draa0gon »

The error is from "love.filesystem.write("opts.txt", a, all )"
User avatar
draa0gon
Prole
Posts: 5
Joined: Mon Jul 12, 2010 6:07 am

Re: I'm Having a little trouble.. Can anyone help?

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: I'm Having a little trouble.. Can anyone help?

Post by Robin »

I think maybe love.filesystem.lines doesn't close the file... that would be a bug in LÖVE.
Help us help you: attach a .love.
User avatar
draa0gon
Prole
Posts: 5
Joined: Mon Jul 12, 2010 6:07 am

Re: I'm Having a little trouble.. Can anyone help?

Post 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?
User avatar
draa0gon
Prole
Posts: 5
Joined: Mon Jul 12, 2010 6:07 am

Re: I'm Having a little trouble.. Can anyone help?

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 64 guests