Storage script interface
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. It is typically accessed by the IRuntime storage
property.
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.
Examples
See the Local storage - script example for a demonstration of using these storage APIs to track a high score.
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.
Construct 3 Manual
Construct.net
2019-06-17
2022-12-01
You are here:
Search this manual:
This manual entry was last updated on 1 Dec, 2022 at 16:20