Configuration
The relationship between Behaviors (.luau
) and Config files (.json
) can be compared to the relationship between a class and an instance in object-oriented programming. The .luau
file defines the behavior of the camera, while the .json
file defines the instance of the camera. There can be multiple configuration files for each camera behavior, allowing you to have multiple instances of the same camera behavior with different settings.
Scripts
└───Cameras
├───Behaviors
│ ├───anotheraxiom.autocam.luau
│ └───anotheraxiom.freecam.luau
└───Configs
├───anotheraxiom.autocam.json
├───anotheraxiom.autocam.customized.json
├───anotheraxiom.autocam.comp.json
└───anotheraxiom.freecam.json
Using config files in scripts
Any data stored in the customData
field of the config file is available to the camera script in the config
global variable. By default, when someone else imports your camera script, their config file will be empty, meaning their config
global variable will be empty as well. This is why it's important to initialize the config with default values in the camera script. An example pattern for initializing the config is shown below:
-- This is a helper function to initialize the config with default values
local function initializeConfig(defaultConfig)
for i, v in pairs(defaultConfig) do
if config[i] == nil then
config[i] = v
end
end
end
-- Main is called at the start of the script
function main()
-- Add default values to any keys that don't exist in the config file
initializeConfig({
speed = 5,
sensitivity = 1
})
end
function tick(dt)
print(config.speed) -- 10
print(config.sensitivity) -- 1
end
Saving config
By default, any changes to the global config
variable are not saved to the config file and will be lost when the camera reloads. To persist your config changes across game restarts, you must call saveConfig()
. This function will write the current state of the config
variable to the config file. An example for saving the config is shown below: