Last Updated March 12, 2022
- Loading Config Manager
- Supported Data Types
- Initialize
- Load Config
- Save Config
- Get Configs
- Set Default Config
- Delete Config
- Valid Config
- Encode
- Decode
local cfg = loadstring(game:HttpGet("https://raw.githubusercontent.com/zzerexx/scripts/main/ConfigManager.lua"))()The following data types are automatically converted to table form before saving a config:
| Category | Data Type |
|---|---|
| Colors | Color3, BrickColor |
| Positions | Vector2, Vector3, CFrame |
| Interface | UDim, UDim2 |
more may be added in the future
After loading a config, the data can be accessed via the Data table.
You can also access a date that specifies when the config was created.
local Settings = {bruh = true}
cfg.Load("MyConfig", function(data)
Settings = data.Data -- the actual data that you save is kept in the Data table.
print(data.Saved) -- you can get the date the config was created with this
end)<table> cfg.Init(<string> Config, <table> Default, <function?> Callback)Initializes Config Manager. This must be called before using Config Manager.
Loads and returns the default config.
If a Callback is specified, it calls the function with the default config as a parameter.
-- Two methods to load the default config
local MySettings = {bruh = true, ok = "hey"}
local Default = cfg.Init("my script hub or whatever", MySettings).Data -- 1: storing it in a variable
cfg.Init("my script hub or whatever", MySettings, function(data) -- 2: using a function
MySettings = data.Data
ConfigLoaded() -- using functions allow for a more extensive use such as calling a function after retrieving a config
end)<table> cfg.Load(<string> Config, <function?> Callback)Loads and returns the specified Config.
If a Callback is specified, it calls that function with the specified Config as a parameter.
-- Two methods to retrieve a config
local Config = cfg.Load("MyConfig").Data -- 1: storing it in a variable
cfg.Load("MyConfig", function(data) -- 2: using a function
Config = data.Data
ConfigLoaded() -- using functions allow for a more extensive use such as calling a function after retrieving a config
end)<void> cfg.Save(<string> Config, <table> Data)Creates a new config with Data.
local MySettings = {bruh = true, ok = "hey"}
function CreateNewConfig(Name)
cfg.Save(Name, MySettings)
end
CreateNewConfig("wowow")<table> cfg.Get(<void>)Returns an array of all of your configs.
function GetConfigs()
return cfg.Get()
end
table.foreach(GetConfigs(), print) -- prints all your configs<void> cfg.SetDefault(<string> Config)Sets the specified Config to the default config.
cfg.SetDefault("MyOtherConfig")<void> cfg.Delete(<string> Config)Deletes the specified Config.
cfg.Delete("MyUselessConfig")<bool> cfg.Valid(<string> Config)Returns true if the specified Config exists.
Note that all other functions automatically check if a config exists beforehand.
function LoadConfig(Name)
if cfg.Valid(Name) then
return cfg.Load(Name) -- this already checks if it exists, but whatever thats how u use it
end
end
LoadConfig("MyConfig")<string> cfg.Encode(<table> Data)Encodes Data and returns it.
This is a copy of the function that is used to write configs.
local Data = {
hey = "hey",
ok = true
}
local Encoded = cfg.Encode(Data)
writefile("my cool data.json", Encoded)<table> cfg.Decode(<string> Data)Decodes Data and returns it.
This is a copy of the function that is used to read configs.
local Data = readfile("my cool data.json")
local Decoded = cfg.Decode(Data)
table.foreach(Decoded, print)