-
Notifications
You must be signed in to change notification settings - Fork 3
Config
lnx00 edited this page Mar 14, 2023
·
3 revisions
Allows you to save and load options into a JSON file.
-
.new(name)Creates a config instance with the given name. The name should be unique and represent your script.
-
.AutoSaveSet this totrueto automatically save the config after changing a value. -
.AutoLoadSet this totrueto automatically load the config before retrieving a value.
Call these methods on a config object you've created using .new(...)!
-
:GetPath()Returns the path of your config file. -
:Load()(Re-)Loads the settings from the config file. -
:Delete()Deletes the config file. -
:Save()Saves the current setting to the config file. -
:SetValue(key, value)Sets the key to the value (and saves the config). -
:GetValue(key, default)Returns the value of the key (or the given default value if the key doesn't exist).
...
local myConfig = Config.new("MyScript")
myConfig.AutoSave = true
local userName = myConfig:GetValue("userName", "Unknown")
local function OnCreateMove()
local me = WPlayer.GetLocal()
myConfig:SetValue("userName", me:GetName())
end
...