[SOLVED] Multiple conf.lua files?

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
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

[SOLVED] Multiple conf.lua files?

Post by Germanunkol »

Hi,

I am still working on my game which has a (headless) server and a client side application. Currently, I have the Server and the client in two different folders using different sets scripts. However, lots of functions on the server and on the client are the same and I don't want to keep on changing them for both, each time I make an update to one of them. That's one of the reasons why I want to merge the two.
My Problem is that the server needs to run headless and thus needs to be called with a different conf.lua file, so its main file needs to be in a different folder than the main file of the client.
I tried to make two folders called Server and Client and put the main.lua files and corresponding conf.lua files in there.
Here's the setup:

Code: Select all

- Client
	- main.lua
	- conf.lua
- Server
	- main.lua
	- conf.lua
- Scripts			(these should be shared by server and client)
	- script1.lua
	- script2.lua
	...
- Images			(also shared by server and client)
	- Image1.lua
	- Image2.lua
	...
This gives me multiple problems:
I CAN include the scripts using
package.path = "../Scripts/?.lua;" .. package.path

However, I CANNOT add the images in the same way. love.graphics.newImage just won't find them
package.path = "../Images/?.png;" .. package.path

Also, when I distribute my game, this won't work as a .love file.

What I'd rather have is a way to change the conf.lua file depending on the command line arguments. But I cannot find a way to do this, since conf.lua runs _before_ I ever get to the arguments in love.load.
Any ideas?
love.graphics module must be disabled on the server at startup... otherwise I'll get errors and it won't run on my webserver.
Last edited by Germanunkol on Wed Dec 26, 2012 1:42 pm, edited 1 time in total.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
teomat
Prole
Posts: 5
Joined: Thu Mar 08, 2012 3:31 pm
Location: Italy

Re: Multiple conf.lua files?

Post by teomat »

You can check command line arguments inside conf.lua and then set different parameters based on that.

Example conf.lua:

Code: Select all

local server = arg[1] == '-server'

if server then
    function love.conf(t)
        -- server config
        ...
    end
else
    function love.conf(t)
        -- client config
        ...
    end
end
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: [SOLVED] Multiple conf.lua files?

Post by Germanunkol »

Perfect. Thank you!

I did not know that arg was a global variable.
It's working just as I wanted it.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Post Reply

Who is online

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