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
Accessing Data from the conf.lua file
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 6
- Joined: Wed Oct 10, 2012 2:53 pm
-
- Prole
- Posts: 6
- Joined: Wed Oct 10, 2012 2:53 pm
Re: Accessing Data from the conf.lua file
Ahh, can't believe I didn't see that.
Thanks so much.
Thanks so much.
Re: Accessing Data from the conf.lua file
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:
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
-
- Prole
- Posts: 6
- Joined: Wed Oct 10, 2012 2:53 pm
Re: Accessing Data from the conf.lua file
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
Another alternative would be:
If your conf.lua file is:
You can access the values in con.lua in your main.lua via:
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
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
Actually, this would be the easiest, I think:
conf.lua
main.lua
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
Code: Select all
function love.load()
local screenWidth = configTable.screen.width -- access all of the values inside the table
end
- 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
That basically has the same spirit as Ref's snippet, though.Anickyan wrote:Actually, this would be the easiest, I think
Re: Accessing Data from the conf.lua file
Yeah... But for a Lua beginner, t might be easier to understand ó_óRoland_Yonaba wrote: That basically has the same spirit as Ref's snippet, though.
Who is online
Users browsing this forum: Bing [Bot] and 1 guest