Construct 3 icon

Construct 3

Documentation

Storage script interface

Ashley's avatar
Medal
Construct Team Founder
Published 17 Jun, 2019
291 words
~1-2 mins

The IStorage interface provides access to storage for the project. It essentially wraps a simple key-value storage engine based on IndexedDB. This means any data that can be stored in IndexedDB can be stored with these methods, such as numbers, strings, Blobs, etc.

This interface accesses the same storage as the Local Storage plugin. Therefore an item stored from the event sheet can also be read from script, and vice versa. Note however that Construct expressions can only be strings or numbers, so if a script stores a different type it cannot be used in the event sheet.

As with the Local Storage plugin, the storage is unique to the specific project. It is not shared with any other projects or other website storage, even on the same origin.

Storage APIs

async getItem(key)

Read an item from storage. Returns a promise that resolves to the value of the item if it exists in storage, else null if the item does not exist in storage.

async setItem(key, value)

Write an item to storage. Returns a promise that resolves when the write has completed.

async removeItem(key)

Delete an item from storage. Returns a promise that resolves when the removal has completed.

async clear()

Delete all items from storage. Returns a promise that resolves when the clear has completed.

async keys()

Retrieve a list of all keys in storage. Returns a promise that resolves to an array of key names.