Config system
Yes, you can do that too
Basic config system
This type of config system is NOT present in the gamesense version of pui. See packages if you are working on a gamesense script.
To use pui config system, you must keep all your elements in a table or tables, not in local variables.
The table(s) passed to pui.setup(t)
can have any level of elevation. pui will interpret the table to a config system
You need to set up your elements after the creation of all elements. You can't update the config system.
Simple solution: pui.setup()
in the end of the script.
This is probably the easiest way to set up a config system.
local menu = {
enable = pui.switch("General", "Master")
rage = {
switch = pui.switch("Rage", "Enable"),
},
visuals = {
color = pui.color_picker("Group", "Color"),
},
misc = {
combo = pui.combo("Group", "Combo", {"A", "B", "C"}),
}
}
pui.setup(menu)
Everything's ready. Now you can save and load your configs.
Keep in mind that any changes to your table may affect the config system and, therefore, old configs will lose some of the information (or even lose it all)
pui ignores non-existing regions of configs.
Saving and loading
When you have set the config system up, you can use it easily.
pui.save(...)
: table
pui.save(...)
: table
As you can see, this function will return a table of values. This table is identical to the original table of elements.
local config = pui.save()
Done.
You may also want to serialize and encrypt it:
local encrypted = base64.encode( json.stringify(config) )
pui.load(config, ...)
pui.load(config, ...)
There is nothing complicated as well.
Don't forget to decrypt and parse the data. pui.load()
only accepts a table created with pui.save()
.
local config = pui.save()
pui.load(config)
local encrypted = base64.encode( json.stringify(config) )
local decrypted = json.parse( base64.decode(encrypted) )
pui.load(decrypted)
Packages - Isolated config system
Creating
local package = pui.setup(menu, true)
local package = pui.setup(menu)
Saving and loading
config:save(...)
: table
config:save(...)
: table
As you can see, this method will return a table of values. This table is identical to the original table of elements.
local config = pui.setup(menu)
local data = config:save()
Done.
You may also want to serialize and encrypt it:
local encrypted = base64.encode( json.stringify(data) )
config:load(data, ...)
config:load(data, ...)
There is nothing complicated as well.
Don't forget to decrypt and parse the data. :load()
only accepts a table created with :save()
.
local config = pui.setup(menu)
local data = config:save()
config:load(data)
local encrypted = base64.encode( json.stringify(data) )
local decrypted = json.parse( base64.decode(encrypted) )
config:load(decrypted)
Last updated