Skip to content

Storage

The Storage global provides access to the script's associated Persistence object. The Persistence object is where your script can store simple forms of data on a user's computer.

Bins

We provide two "storage bins:" The Public bin and the Private bin. Each bin is a property of the Storage global and are almost identical in terms of API. Each bin has a set amount of data that they can store, as well, to prevent malicious scripts from filling up the user's hard drive.

Public

The Public bin is accessible as Storage.Public. This bin's corresponding file on disk is user-editable, as it is stored as clear-text JSON. This file is intended to be used for things the user may need to edit, such as configuration or tuning values.

Properties

Name Type Notes
BytesAllowed int

How many bytes are allowed for this storage bin, in total. Currently set to 4194304, which corresponds to 4MiB.

Does not include data outside of your control that we add during the serialization process, such as encryption stuff, headers, section data, etc.

CurrentSize int

Current reported size of this storage bin, in bytes.

Does not include data outside of your control that we add during the serialization process, such as encryption stuff, headers, section data, etc.

IsEncrypted bool Whether this storage bin is encrypted on disk. Always false for Public bins.
Path string Path of the file on disk.

Methods

Name Notes
GetBoolean(string key) : bool? Get the value of a key as a boolean, or nil if the key is nil or not present.
GetNumber(string key) : number? Get the value of a key as a number, or nil if the key is nil or missing.
GetString(string key) : string? Get the value of a key as a string, or nil if the key is nil or missing.
GetTable(string key) : table? Get the value of a key as a table, or nil if the key is nil or missing.
HasValue(string key) : bool Determine if the given named key is present in the underlying table.
Load() : void Loads data from disk, if present.
Save() : void

If anything has changed (if the storage is marked dirty), save to disk.

A successful save will clear dirtiness.

SetBoolean(string key, bool? value) : void

Set the value of a key to a boolean or nil.

You will need to call Save() to commit this change to disk.

SetNumber(string key, number? value) : void

Set the value of a key to a number or nil.

You will need to call Save() to commit this change to disk.

SetString(string key, string? value) : void

Set the value of a key to a string or nil.

You will need to call Save() to commit this change to disk.

SetTable(string key, table? value) : void

Set the value of a key to a table or nil.

IMPORTANT: Any values in the provided table or subtables that are not nil, number, boolean, table, or string will be silently stripped during serialization!

You will need to call Save() to commit this change to disk.

Private

The Private bin is accessible as Storage.Private. This bin's corresponding file on disk is encrypted and stored as a binary format, as it is intended to be used for storing deliberately opaque data, such as a user's score in a game, character levels, et cetera.

Properties

Name Type Notes
BytesAllowed int

How many bytes are allowed for this storage bin, in total. Currently set to 4194304, which corresponds to 4MiB.

Does not include data outside of your control that we add during the serialization process, such as encryption stuff, headers, section data, etc.

CurrentSize int

Current reported size of this storage bin, in bytes.

Does not include data outside of your control that we add during the serialization process, such as encryption stuff, headers, section data, etc.

IsEncrypted bool Whether this storage bin is encrypted on disk. Always false for Private bins.
Path string Path of the file on disk.

Methods

Name Notes
GetBoolean(string key) : bool? Get the value of a key as a boolean, or nil if the key is nil or not present.
GetNumber(string key) : number? Get the value of a key as a number, or nil if the key is nil or missing.
GetString(string key) : string? Get the value of a key as a string, or nil if the key is nil or missing.
GetTable(string key) : table? Get the value of a key as a table, or nil if the key is nil or missing.
HasValue(string key) : bool Determine if the given named key is present in the underlying table.
Load() : void Loads data from disk, if present.
Save() : void

If anything has changed (if the storage is marked dirty), save to disk.

A successful save will clear dirtiness.

SetBoolean(string key, bool? value) : void

Set the value of a key to a boolean or nil.

You will need to call Save() to commit this change to disk.

SetNumber(string key, number? value) : void

Set the value of a key to a number or nil.

You will need to call Save() to commit this change to disk.

SetString(string key, string? value) : void

Set the value of a key to a string or nil.

You will need to call Save() to commit this change to disk.

SetTable(string key, table? value) : void

Set the value of a key to a table or nil.

IMPORTANT: Any values in the provided table or subtables that are not nil, number, boolean, table, or string will be silently stripped during serialization!

You will need to call Save() to commit this change to disk.