Best practice to manage game config options

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
vitto
Prole
Posts: 10
Joined: Wed Nov 19, 2014 5:50 pm
Location: Italy
Contact:

Best practice to manage game config options

Post by vitto »

As I've read on [wiki]Config_Files[/wiki] wiki page that I can define all game settings inside conf.lua file.

If I'm not wrong, all the config i set in conf.lua doesn't affect directly the game, because config is loaded before main.lua starts, so I suppose, the config set before is visibile to the rest of the game code, or I didn't got how config should be used.

If I'm true, how can I read the config i defined in conf.lua into main.lua?

Let's suppose I've prepared in config.lua some data like fullscreen width and height taken from my machine, should I store the data inside some text/json file and then load it into main.lua?

Which is a best practice?
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Best practice to manage game config options

Post by Positive07 »

If you are using full screen, try to use desktop fullscreen (which is a maximized window that covers everything) because normal fullscreen can break and no one likes it... really.
  • If your game uses normal fullscreen and it crashes then the resolution wont go back to the original resolution.
  • If your game uses normal fullscreen and the width and height is not a supported width or height then it will not go fullscreen at all.
So desktop fullscreen is better, but it's worst for your code, since desktop fullscreen uses the width and height of the screen, you cant use the width and height you want, you are tied to the resolution of the screen.

If you want to get info from the conf file you could do something like:

Code: Select all

require "conf"
local t = {modules = {},window = {}}
love.conf(t)
And now the t table will have all the info defined in love.conf, but this is not recommended. You can get all the information set in the config with other function.

For example to get the size of the display you can use [wiki]love.graphics.getHeight[/wiki] and [wiki]love.graphics.getWidth[/wiki] (You'll need this functions a lot if you use desktop fullscreen).

Also you could use [wiki]love.window.getMode[/wiki], [wiki]love.window.getTitle[/wiki] and so (take a look at [wiki]love.window[/wiki] in general)
The modules info is trickier but rather simple too

Code: Select all

if love.joystick then
    --The joystick module is enabled
end
and if you need a module you can always do

Code: Select all

require "love.joystick"
Do you need more information than this? I hope this answer was useful for you
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests