Configuration Management
Best practices for managing resource configuration.
Configuration File Structure​
Create a dedicated config file:
-- config.lua
Config = {
Debug = false,
JobSettings = {
Name = "Taxi Driver",
Salary = 500,
PayInterval = 300000, -- 5 minutes
},
Locations = {
{
Name = "Downtown",
Coords = vector3(100.5, 200.3, 50.2),
Heading = 180.0,
},
{
Name = "Airport",
Coords = vector3(500.5, 600.3, 150.2),
Heading = 90.0,
},
},
}
return Config
Loading Configuration​
-- Load in any script
local Config = require 'config'
print(Config.JobSettings.Name)
print(Config.Locations[1].Coords)
Environment-Specific Configuration​
Support different configurations for development and production:
-- config.lua
local Config = {}
if GetConvar('environment', 'production') == 'development' then
Config.Debug = true
Config.DatabaseHost = 'localhost'
else
Config.Debug = false
Config.DatabaseHost = 'prod.example.com'
end
return Config
Using ConVars​
Server convars for dynamic configuration:
-- server.lua
local maxPlayers = GetConvarInt('sv_maxclients', 32)
local debugMode = GetConvar('debug_mode', 'false') == 'true'
print('Max Players: ' .. maxPlayers)
Best Practices​
- Keep sensitive data (API keys) out of config files
- Use environment variables for secrets
- Document all configuration options
- Provide sensible defaults
- Validate configuration on resource start