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.

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.

We also provide a function to retrieve the Public bin for other content by providing the content type and its ID. This bin will be limited to read only functions.

The bin files are stored on %UserProfile%\AppData\LocalLow\ChilloutVR\ChilloutVR\Persistence\<user_id>\<content_type>\<content_id>\

NameSizeSize (Bytes)
Avatar100 KiB102400 bytes
Prop (Spawnable)100 KiB102400 bytes
World4 MiB4194304 bytes
NameDescription
Public (Returns Public Bin)Access to the Public Bin.
Private (Returns Private Bin)Access to the Private Bin.
NameDescription
GetPublicStorage(contentType, assetGuid)
(Returns Public Bin Readonly)
Access to other content’s Public Bins locked to read only mode.

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.

This bin is also accessible to other content. So if you want to share data across content, this would be the place to store it.

NameTypeNotes
HasDatabool

Whether this bin has Data or not. It will be true a file was found and loaded successfully.

SizeAllowedint

How many bytes are allowed for this storage bin, in total.

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

CurrentSizeint

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.

PathstringPath of the file on disk.
NameNotes
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) : boolDetermine if the given named key is present in the underlying table.
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.

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.

NameTypeNotes
HasDatabool

Whether this bin has Data or not. It will be true a file was found and loaded successfully.

SizeAllowedint

How many bytes are allowed for this storage bin, in total.

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

CurrentSizeint

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.

PathstringPath of the file on disk.
NameNotes
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) : boolDetermine if the given named key is present in the underlying table.
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.

The Public Bin Readonly is accessible via Storage.GetPublicStorage(contentType, assetGuid). This bin only provides functions that read data. It’s intended to allow content to react to data stored from other content. If the file is not found, this function will return nil

The contentType is an enum to indicate the content type. To use its values you need to import the CVR module via: CVR = require("CVR")

The possible values are:

  • CVR.CVRContentType.Avatar - For Avatars
  • CVR.CVRContentType.Spawnable - For Props
  • CVR.CVRContentType.World - For Worlds

As for the assetGuid is a simple string with the guid of the content, for example "f566d0c9-155a-4280-9eb6-7792f66b5597"

NameTypeNotes
HasDatabool

Whether this bin has Data or not. It will be true a file was found and loaded successfully.

NameNotes
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) : boolDetermine if the given named key is present in the underlying table.