sm.storage
Associated object type: Storage
Storage is used for saving and loading any Lua data into the world's database. This allows for data to be retrieved after closing and reloading the world.
Storage can only be used on the server.
Warning:
Storage allows for data to be saved immediately into the world's database. This is a very slow process and should be done as sparsely as possible.
If you have data that is shared globally and updated often, consider using global variables instead. Ideally, storage should only be used to save data upon closing the world, or when saving a creation on the Lift.
Functions:
sm.storage.load(key)
Loads Lua data stored with a given key. The key can be any lua object.
If no data is stored with the given key, this returns nil.
Parameters:
Type | Name | Description |
---|---|---|
any | key | The key. |
Returns:
Type | Description |
---|---|
any | The data stored. |
sm.storage.save(key, data)
Saves any Lua object with a given key. The key can be any lua object.
The data will remain stored after closing the world, and is retrieved using load, provided the same key.
Note:
The data is stored globally within the current mod. As of such, keys will not collide with external mods and scripts.
Parameters:
Type | Name | Description |
---|---|---|
any | key | The key that will be used to get the data. |
any | data | The data to be stored. |
sm.storage.saveAndSync(key, data)
Saves any Lua object with a given key. The key can be any lua object.
The data will remain stored after closing the world and synchronized to other clients, and is retrieved using load, provided the same key.
Note:
The data is stored globally within the current mod. As of such, keys will not collide with external mods and scripts.
Parameters:
Type | Name | Description |
---|---|---|
any | key | The key that will be used to get the data. |
any | data | The data to be stored. |