Scrappy Settings is a simple settings management library for Solar2D that simplifies customisable settings.
All settings are stored in plain text in a settings.ini file in the project’s root directory, and modified ones are stored in the app’s documents directory.
As with all my libraries it is free to use however if you find it useful, and are able to, I’d appreciate a coffee, or if you like you could purchase the plugin.
Image Credit: Settings by ProSymbols from the Noun Project.
In order to use the library you will need to include it in your project, to do so please see this guide.
Initiates the library.
separator ( string ) – The character to use as the separator between key/value pairs in the settings.ini file. Optional, defaults to ‘:’.
Gets the value of a setting.
name ( string ) – The name of the setting to retrieve.
returns – The value, or nil if not found.
Sets the value of a setting.
name ( string ) – The name of the setting to set.
value ( string, number, boolean, table ) – The value to set.
dontSave ( boolean ) – Should the auto-save be disabled for this set. Optional, defaults to false so it will save.
Checks if the value of a setting matches another value.
name ( string ) – The name of the setting to check.
value ( string, number, boolean, table ) – The value to compare.
returns – True if the setting matches the value, false if not.
Resets a setting.
name ( string, table of strings ) – The name of the setting to reset. Optional, if not included then the whole settings database will be reset to defaults.
dontSave ( boolean ) – Should the auto-save be disabled for this reset. Optional, defaults to false so it will save.
A basic settings.ini file to include in your project’s root directory.
easyModeEnabled:true, defaultVolumeLevel:0.75, defaultLanguage:en
Accessing some settings, changing them, and resetting back to defaults.
-- Initiate the settings library Scrappy.Settings:init() -- Print out the default volume print( "Default Volume:", Scrappy.Settings:get( "defaultVolumeLevel" ) ) -- And the current volume - will be nil on first run as it's not set print( "Current Volume:", Scrappy.Settings:get( "currentVolumeLevel" ) ) -- Set the current level to something Scrappy.Settings:set( "currentVolumeLevel", 0.5 ) -- And print it out again print( "Current Volume:", Scrappy.Settings:get( "currentVolumeLevel" ) ) -- Settings can also be strings print( "Default Language: ", Scrappy.Settings:get( "defaultLanguage" ) ) -- As well as booleans print( "Easy Mode Enabled: ", Scrappy.Settings:get( "easyModeEnabled" ) ) -- And you can check if a settings is set to something specific like this print( "Current volume set to 0.5?", Scrappy.Settings:is( "currentVolumeLevel", 0.5 ) ) -- The settings will get automatically saved, but you can reset them individually like this Scrappy.Settings:reset( "currentVolumeLevel" ) -- And print it out again print( "Current Volume:", Scrappy.Settings:get( "currentVolumeLevel" ) ) -- Or reset them all like this Scrappy.Settings:reset()