Anything not inside a function will be run as soon as you require the file... If they are in functions, you must call the functions for anything to happen. So say you had a config file that sets globals for your game:
gameConfig.lua
Code: Select all
ScreenW = 800
ScreenH = 600
bgColor = {50,200,180}
-- Note there is no return at the end, and nothing is local...
-- This will insert these varibles into the global spectrum for your game to use.
Then just require it without declaring a variable(because it doesn't return a table):
Code: Select all
require 'gameConfig'
function love.load()
-- Using the globals we set
love.window.setMode(ScreenW, ScreenH)
love.graphics.setBackgroundColor(bgColor)
end
However, for the sake of organization, I prefer to use tables:
Code: Select all
local cfg = {
ScreenW = 800,
ScreenH = 600,
bgColor = {50,200,180}
}
return cfg
Then call upon the table for the values:
Code: Select all
CONFIG = require 'gameConfig'
function love.load()
love.window.setMode(CONFIG.ScreenW, CONFIG.ScreenH)
love.graphics.setBackgroundColor(CONFIG.bgColor)
end