Skip to content

Get Sansar

Script API

DataStore

Where: Client
More page actions

For the complete documentation index, see llms.txt. This page is also available as Markdown.

Class Namespace Sansar.Simulation Added in 37.1.0

The DataStore class provides access to a persistent data store that can be accessed by scripts from any experience.

public class DataStore

Remarks

All DataStore objects with a given DataStore.Id share the same database.

Members at a glance

KindMembers
PropertiesId
MethodsDelete · Restore · Store

Properties

Id

Added in 37.1.0
public Guid Id { get; }

The Id of this DataStore.

Remarks

All DataStore objects with a given DataStore.Id share the same database.

Methods

Delete

Added in 37.1.0
public void Delete(     string key,     Action<Sansar.Script.OperationCompleteEvent> done )

Deletes the value associated with the given key

ParameterTypeDescription
keystringThey key the data is stored under.
doneAction<Sansar.Script.OperationCompleteEvent>The action to call when the delete is complete.
Remarks

Unconditionally deletes the value associated with the given key. For a conditional delete, use DataStore.Delete.

Added in 37.1.0
public void Delete<T>(     string key,     DataStore.Options options,     Action<DataStore.Result<T>> done )

Deletes the value associated with the given key

ParameterTypeDescription
keystringThey key the data is stored under.
optionsDataStore.OptionsControls how the operation proceeds.
doneAction<DataStore.Result<T>>The action to call when the delete is complete.

Type parameters: T: The type of the data stored.

Remarks

Options.Version can be specified to conditionally delete only if the version matches. If the version number does not match, DataStore.Result<T> will have Success == false and the current value in the Version and Object fields.

Restore

Added in 37.1.0
public void Restore<T>(string key, Action<DataStore.Result<T>> done)

Retrieves the value associated with the given key.

ParameterTypeDescription
keystringThey key the data is stored under.
doneAction<DataStore.Result<T>>The action to call when the restore is complete.

Type parameters: T: The type of the data stored.

Remarks

If the done action is null, this method will fail without making a call to the data store.

Store

Added in 37.1.0
public void Store<T>(     string key,     T value,     Action<DataStore.Result<T>> done )

Serializes the given object to the data store

ParameterTypeDescription
keystringThe key to store the data under.
valueTThe object to be converted
doneAction<DataStore.Result<T>>The action to call when the store is complete.
Remarks

The specified key and value will always overwrite any existing data in the store. For a conditional store, use DataStore.Store with Options.Version set to a value from a previous operation.

Added in 37.1.0
public void Store<T>(     string key,     T value,     DataStore.Options options,     Action<DataStore.Result<T>> done )

Serializes the given object to the data store

ParameterTypeDescription
keystringThe key to save the data under.
valueTThe object to be converted.
optionsDataStore.OptionsControls how the operation proceeds.
doneAction<DataStore.Result<T>>The action to call when the conversion is complete.
Remarks

Options.Version can be specified to conditionally store only if the version matches. If the version number does not match, DataStore.Result<T> will have Success == false and the current value in the Version and Object fields. If Options.RetrieveData false and the write is successful, the response will not include the value written to the store and will simply pass back the value parameter.

Used in examples

Generated from the Sansar 47.10.0 client ScriptApi snapshot.