Restore settings in conf.lua

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
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Restore settings in conf.lua

Post by grump »

A function named love.config can be put into a file called conf.lua to make configuration changes before the main program starts.

If I want to restore configuration settings (e. g., window size and position) that my game saved when it was played the last time, how can I load them? love.filesystem is not available yet, so I can't call getSaveDirectory() to figure out the location of my save file.

I could (and currently do) change the window parameters later, but I'd really like to set the window size and position configuration before the window is created.
MrFariator
Party member
Posts: 512
Joined: Wed Oct 05, 2016 11:53 am

Re: Restore settings in conf.lua

Post by MrFariator »

You can always delay the window creation by disabling the window module in conf.lua and call love.window.setMode after conf.lua and/or your save file has been read by your game.

Quoting from the wiki page:
If you have disabled the window in conf.lua (i.e. t.window = false) and use this function to manually create the window, then you must not call any other love.graphics.* function before this one. Doing so will result in undefined behavior and/or crashes because OpenGL cannot function properly without a window.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Restore settings in conf.lua

Post by grump »

I must haved missed that bit of information. Thank you!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Restore settings in conf.lua

Post by bartbes »

grump wrote: Sat Jul 22, 2017 7:56 pm love.filesystem is not available yet, so I can't call getSaveDirectory() to figure out the location of my save file.
MrFariator's solution is probably the right one. I'd just like to point out love.filesystem is loaded by that point, since that's how conf.lua is loaded. (And you shouldn't need getSaveDirectory...)
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Restore settings in conf.lua

Post by grump »

bartbes wrote: Sun Jul 23, 2017 9:35 am MrFariator's solution is probably the right one. I'd just like to point out love.filesystem is loaded by that point, since that's how conf.lua is loaded. (And you shouldn't need getSaveDirectory...)
Oh, okay. I ran into some quirks while figuring out how to get file loading and saving to work consistently between multiple OS and fused and non-fused mode. For instance, love.filesystem.write always fails with a nil error for me. love.filesystem.lines never finishes when loading a large file in fused mode (but works fine in non-fused mode). I could not get file loading to work at all when trying to load in love.config, but I cant remember the details. I supposed it was because love.filesystem may not be initialized at that point, so I used the io library instead, hence the question about getSaveDirectory.

I solved all those problems by not loading in love.config, and using the File functions instead of love.filesystem.write and love.filesystem.lines.

Still using love 0.9 though, since that is what is being shipped with Debian Stretch.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Restore settings in conf.lua

Post by bartbes »

grump wrote: Sun Jul 23, 2017 12:08 pm I supposed it was because love.filesystem may not be initialized at that point, so I used the io library instead, hence the question about getSaveDirectory.
I did remember setIdentity gets called after love.conf, so the save directory may not be available in love.conf.
grump wrote: Sun Jul 23, 2017 12:08 pm For instance, love.filesystem.write always fails with a nil error for me.
That's weird, do you mean love.filesystem.write is nil?
grump wrote: Sun Jul 23, 2017 12:08 pm love.filesystem.lines never finishes when loading a large file in fused mode (but works fine in non-fused mode)
It's the same code, I'm not sure how it can act differently here.
grump wrote: Sun Jul 23, 2017 12:08 pm Still using love 0.9 though, since that is what is being shipped with Debian Stretch.
0.9.1 is old, but I haven't heard of either of these bugs before.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Restore settings in conf.lua

Post by grump »

bartbes wrote: Sun Jul 23, 2017 1:22 pm
grump wrote: Sun Jul 23, 2017 12:08 pm For instance, love.filesystem.write always fails with a nil error for me.
That's weird, do you mean love.filesystem.write is nil?

Code: Select all

success, msg = love.filesystem.write(...)
success is false and msg is nil after calling this. (0.9 Linux)
It's the same code, I'm not sure how it can act differently here.
IIRC, it works with 0.9 in Linux but fails with 0.10.1 in Windows. I'm trying to load a file with about 25000 lines. But I just remembered it's not different in fused vs. non-fused, it's different when running from a directory vs. running from a .love package. It works from directory, fails from .love. Sorry for the confusion.
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 194 guests