system.setPreferences()

Type Function
Library system.*
Return value Boolean
Revision Current Public Release (2017.3068)
Keywords system preference, setPreferences
See also system.getPreference()
system.deletePreferences()

Overview

Writes a table of preference values to storage. If any of the given preferences do not exist in storage, they will be inserted. If any of the given preferences already exist in storage, they will be overwritten.

Returns true if all of the given preferences were written to storage successfully. Returns false if at least one of the given preferences failed to be written to storage.

Gotchas

Syntax

system.setPreferences( category, preferences )
category (required)

String. Indicates which set of preferences should be accessed on the system. Currently, only the "app" category is supported — this is the application's custom preferences defined by the Corona app developer.

preferences (required)

Table. Table of preferences to be written to storage. This table should contain key-value pairs where the key is the unique name of the preference and its value is either a boolean, number, or string.

Example

-- Write this app's custom preferences to storage
local appPreferences =
{
    myBoolean = true,
    myNumber = 123.45,
    myString = "Hello World"
}
system.setPreferences( "app", appPreferences )

-- Read the preferences that were written to storage above
local myBoolean = system.getPreference( "app", "myBoolean", "boolean" )
local myNumber = system.getPreference( "app", "myNumber", "number" )
local myString = system.getPreference( "app", "myString", "string" )