loading from love filesystem issue

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
DarkShroom
Citizen
Posts: 86
Joined: Mon Jul 17, 2017 2:07 pm

loading from love filesystem issue

Post by DarkShroom »

sorry to ask this but i have done quite a few googles and no-one seems to have the same issue, i can't seem to load my saved file:

Code: Select all

filename = 'save.txt'
if love.filesystem.exists(filename) then
    print('FOUND SAVE FILE!')
    print(love.filesystem.load(filename))
else
    print('NO SAVE FILE!')
end
love.filesystem.write(filename, 'this is my text string' )
the demo code there, run once saves my file just fine

run again, it does not want to load the file! I get:
FOUND SAVE FILE!
Error: main.lua:9: Syntax error: save.txt:1: '=' expected near 'make'

stack traceback:
[C]: in function 'load'
main.lua:9: in main chunk
[C]: in function 'require'
[string "boot.lua"]:429: in function <[string "boot.lua"]:275>
[C]: in function 'xpcall'
[Finished in 3.3s with exit code 1]
Can anyone help? I have tried updating Love 2D.... It's pretty damn fundamental this bug! For my saves :cry:
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: loading from love filesystem issue

Post by zorg »

You do know that love.filesystem.load loads in lua source code, right?
You probably want to open the file, and iterate through the lines, since it's a text file.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
DarkShroom
Citizen
Posts: 86
Joined: Mon Jul 17, 2017 2:07 pm

Re: loading from love filesystem issue

Post by DarkShroom »

oh right, i didn't know that

i assumed it saved like the normal lua way... do you have a link at all to just how to save a plain string?

i just want to save json myself that's all
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: loading from love filesystem issue

Post by bartbes »

If you just want one string containing all of the file's contents you can just use love.filesystem.read. Alternatively, if you want to iterate over all lines, there is love.filesystem.lines. Lastly, if you need something more complex you can create a File object and read it that way.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: loading from love filesystem issue

Post by grump »

bartbes wrote: Fri Nov 10, 2017 5:10 pm Alternatively, if you want to iterate over all lines, there is love.filesystem.lines.
love.filesystem.lines is extremely slow when loading from a love file. Avoid it if you want to read large files.

Code: Select all

local i = 0
for line in love.filesystem.lines("manylines.txt") do i = i + 1 end
print(i .. " lines")
love.event.quit()

Code: Select all

$ time love test
32768 lines

real	0m0.382s
user	0m0.132s
sys	0m0.104s

Code: Select all

$ time love test.love
32768 lines

real	0m55.186s
user	0m55.180s
sys	0m0.484s
DarkShroom
Citizen
Posts: 86
Joined: Mon Jul 17, 2017 2:07 pm

Re: loading from love filesystem issue

Post by DarkShroom »

thanks so much

yeah i just needed the "read" function... i was finding that very strange, i get it "load" for code, "read" for text

how i didn't spot that when it's the same wording as the lua functions i don't know... i don't really use lines type functions anyway thanks for the info
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 226 guests