Docs

UserSettings

C++ type: UserSettings (static)

Description

A cross-platform key-value store for persistent user preferences. Values survive app restarts and are stored in a platform-appropriate location (e.g. SharedPreferences on Android, NSUserDefaults on iOS, a settings file on desktop platforms).

Supported value types: bool, int, long, float, double, std::string, and Data.

Methods

Type Name Langs
static bool getBoolForKey C++ | Lua
static int getIntegerForKey C++ | Lua
static long getLongForKey C++ | Lua
static float getFloatForKey C++ | Lua
static double getDoubleForKey C++ | Lua
static std::string getStringForKey C++ | Lua
static Data getDataForKey C++ | Lua
static void setBoolForKey C++ | Lua
static void setIntegerForKey C++ | Lua
static void setLongForKey C++ | Lua
static void setFloatForKey C++ | Lua
static void setDoubleForKey C++ | Lua
static void setStringForKey C++ | Lua
static void setDataForKey C++ | Lua
static void removeKey C++ | Lua

Method details

get methods

  • static T get\<Type>ForKey(const char* key)
  • static T get\<Type>ForKey(const char* key, T defaultValue)

Retrieve a stored value by key. If the key does not exist and no defaultValue is given, the zero/empty value for the type is returned.

int volume = UserSettings::getIntegerForKey("volume", 80);
bool musicEnabled = UserSettings::getBoolForKey("music", true);
std::string playerName = UserSettings::getStringForKey("name", "Player1");
local volume = UserSettings.getIntegerForKey("volume", 80)
local musicEnabled = UserSettings.getBoolForKey("music", true)
local playerName = UserSettings.getStringForKey("name", "Player1")

set methods

  • static void set\<Type>ForKey(const char* key, T value)

Store a value. Creates the key if it does not exist, or overwrites the previous value.

UserSettings::setIntegerForKey("highScore", 9999);
UserSettings::setBoolForKey("tutorialDone", true);
UserSettings.setIntegerForKey("highScore", 9999)
UserSettings.setBoolForKey("tutorialDone", true)

removeKey

  • static void removeKey(const char* key)

Deletes a key and its associated value from persistent storage.