Page 1 of 1
Accessing Data from the conf.lua file
Posted: Wed Oct 10, 2012 2:56 pm
by The_A_Drain
Hi guys, just started having a fiddle around with LUA and I'm putting together a quick template project for use in game jams and the like, I've figured out how to get the screen size from graphics but I'd like the default menu page to display the games title, is there a way of simply pulling the title that has been set in conf.lua?
I had a search on the forums but turned up a lot of information about other things to do with conf.lua.
cheers

Re: Accessing Data from the conf.lua file
Posted: Wed Oct 10, 2012 4:13 pm
by Kadoba
Re: Accessing Data from the conf.lua file
Posted: Wed Oct 10, 2012 4:25 pm
by The_A_Drain
Ahh, can't believe I didn't see that.
Thanks so much.
Re: Accessing Data from the conf.lua file
Posted: Thu Oct 11, 2012 6:23 pm
by Anickyan
You could also just declare global variables in the conf.lua files, I think. It is possible, though, that LÖVE does not run the two files with the same Lua_state.
Anyways, this is how you'd do it:
Code: Select all
-- conf.lua
S_WIDTH, S_HEIGHT = 800, 600
S_TITLE = "Test Window"
function love.conf(ct)
ct.screen.width, ct.screen.height = S_WIDTH, S_HEIGHT
ct.title = S_TITLE
end
Code: Select all
-- main.lua
local w, h, title
function love.load()
w, h, title = S_WIDTH, S_HEIGHT, S_TITLE
end
Re: Accessing Data from the conf.lua file
Posted: Thu Oct 11, 2012 6:50 pm
by The_A_Drain
Thanks for the info Anickyan, I might give that a try later. I'm very new to LUA coming from C#/C++ it's very different.
Re: Accessing Data from the conf.lua file
Posted: Fri Oct 12, 2012 3:14 am
by Ref
Another alternative would be:
If your conf.lua file is:
Code: Select all
function love.conf(t)
t.title = "mouse drag image" -- The title of game window (string)
t.author = "Ref" -- The author of the game (string)
t.screen.fullscreen = false -- Enable fullscreen (boolean)
t.screen.vsync = true -- Enable vertical sync (boolean)
t.screen.fsaa = 0 -- The number of FSAA-buffers (number)
t.screen.height = 512 -- The window height (number)
t.screen.width = 512 -- The window width (number)
t.version = "0.8.0" -- The LOVE version (string)
t.console = false -- Enable console (boolean)
end
You can access the values in con.lua in your main.lua via:
Code: Select all
local temp = {}
temp.screen = {}
love.conf( temp)
title = temp.title
width = temp.screen.width
height = temp.screen.height
...
Re: Accessing Data from the conf.lua file
Posted: Fri Oct 12, 2012 2:14 pm
by Anickyan
Actually, this would be the easiest, I think:
conf.lua
Code: Select all
configTable = {} -- use any variable name
function love.conf(t)
t.screen.width = 800
t.screen.height = 600
t.title = "Test Window"
configTable = t
end
main.lua
Code: Select all
function love.load()
local screenWidth = configTable.screen.width -- access all of the values inside the table
end
Re: Accessing Data from the conf.lua file
Posted: Fri Oct 12, 2012 2:22 pm
by Roland_Yonaba
Anickyan wrote:Actually, this would be the easiest, I think
That basically has the same spirit as Ref's snippet, though.

Re: Accessing Data from the conf.lua file
Posted: Fri Oct 12, 2012 2:28 pm
by Anickyan
Roland_Yonaba wrote:
That basically has the same spirit as Ref's snippet, though.

Yeah... But for a Lua beginner, t might be easier to understand ó_ó