Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Latest commit

 

History

History
196 lines (161 loc) · 4.36 KB

File metadata and controls

196 lines (161 loc) · 4.36 KB

Config Manager Documentation

Last Updated March 12, 2022

Table of Contents

Loading Config Manager

local cfg = loadstring(game:HttpGet("https://raw.githubusercontent.com/zzerexx/scripts/main/ConfigManager.lua"))()

Supported Data Types

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

Additional Notes

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)

Init

<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.

Example

-- 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)

Load

<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.

Example

-- 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)

Save

<void> cfg.Save(<string> Config, <table> Data)

Creates a new config with Data.

Example

local MySettings = {bruh = true, ok = "hey"}
function CreateNewConfig(Name)
    cfg.Save(Name, MySettings)
end
CreateNewConfig("wowow")

Get

<table> cfg.Get(<void>)

Returns an array of all of your configs.

Example

function GetConfigs()
    return cfg.Get()
end
table.foreach(GetConfigs(), print) -- prints all your configs

Set Default

<void> cfg.SetDefault(<string> Config)

Sets the specified Config to the default config.

Example

cfg.SetDefault("MyOtherConfig")

Delete

<void> cfg.Delete(<string> Config)

Deletes the specified Config.

Example

cfg.Delete("MyUselessConfig")

Valid

<bool> cfg.Valid(<string> Config)

Returns true if the specified Config exists.
Note that all other functions automatically check if a config exists beforehand.

Example

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")

Encode

<string> cfg.Encode(<table> Data)

Encodes Data and returns it.
This is a copy of the function that is used to write configs.

Example

local Data = {
  hey = "hey",
  ok = true
}
local Encoded = cfg.Encode(Data)

writefile("my cool data.json", Encoded)

Decode

<table> cfg.Decode(<string> Data)

Decodes Data and returns it.
This is a copy of the function that is used to read configs.

Example

local Data = readfile("my cool data.json")
local Decoded = cfg.Decode(Data)

table.foreach(Decoded, print)