Accessing Data from the conf.lua file

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
The_A_Drain
Prole
Posts: 6
Joined: Wed Oct 10, 2012 2:53 pm

Accessing Data from the conf.lua file

Post 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 :)
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Accessing Data from the conf.lua file

Post by Kadoba »

The_A_Drain
Prole
Posts: 6
Joined: Wed Oct 10, 2012 2:53 pm

Re: Accessing Data from the conf.lua file

Post by The_A_Drain »

Ahh, can't believe I didn't see that.

Thanks so much.
Anickyan
Prole
Posts: 27
Joined: Sun Aug 05, 2012 8:42 am

Re: Accessing Data from the conf.lua file

Post 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
The_A_Drain
Prole
Posts: 6
Joined: Wed Oct 10, 2012 2:53 pm

Re: Accessing Data from the conf.lua file

Post 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.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Accessing Data from the conf.lua file

Post 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
...
Anickyan
Prole
Posts: 27
Joined: Sun Aug 05, 2012 8:42 am

Re: Accessing Data from the conf.lua file

Post 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
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Accessing Data from the conf.lua file

Post by Roland_Yonaba »

Anickyan wrote:Actually, this would be the easiest, I think
That basically has the same spirit as Ref's snippet, though. :awesome:
Anickyan
Prole
Posts: 27
Joined: Sun Aug 05, 2012 8:42 am

Re: Accessing Data from the conf.lua file

Post by Anickyan »

Roland_Yonaba wrote: That basically has the same spirit as Ref's snippet, though. :awesome:
Yeah... But for a Lua beginner, t might be easier to understand ó_ó
Post Reply

Who is online

Users browsing this forum: Google [Bot], Nikki and 4 guests