Page 1 of 1

[SOLVED] Multiple conf.lua files?

Posted: Wed Dec 26, 2012 11:27 am
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.

Re: Multiple conf.lua files?

Posted: Wed Dec 26, 2012 1:06 pm
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

Re: [SOLVED] Multiple conf.lua files?

Posted: Wed Dec 26, 2012 1:43 pm
by Germanunkol
Perfect. Thank you!

I did not know that arg was a global variable.
It's working just as I wanted it.