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.
Restore settings in conf.lua
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Party member
- Posts: 512
- Joined: Wed Oct 05, 2016 11:53 am
Re: Restore settings in conf.lua
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:
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.
Re: Restore settings in conf.lua
I must haved missed that bit of information. Thank you!
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Restore settings in conf.lua
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...)
Re: Restore settings in conf.lua
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.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Restore settings in conf.lua
I did remember setIdentity gets called after love.conf, so the save directory may not be available in love.conf.
That's weird, do you mean love.filesystem.write is nil?
It's the same code, I'm not sure how it can act differently here.
0.9.1 is old, but I haven't heard of either of these bugs before.
Re: Restore settings in conf.lua
Code: Select all
success, msg = love.filesystem.write(...)
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.It's the same code, I'm not sure how it can act differently here.
Who is online
Users browsing this forum: No registered users and 212 guests