Storage and Data
Storing persistent data and information can be handy for multiple tasks, especially because it's simpler than ever with the mod framework which handles everything for you.
Persistent or Temporary data
This page provides information about how to use Persist
Persistent Data: Can store data for an indefinite period of time, and data values can be accessed even after the game is reloaded, as the data is stored on the disk.
Temporary Data: Can store temporary data which is deleted after the game is reloaded, but is kept in the memory and can be accessed during the game session, only if it located in the same file.
This guide
Storing Temporary data byes
If you want to create temporary data which can be accessed across the code easily, you can use the built in LUA provided methods.
However, this method might not be useful for storing information like name, money, or other data that you might want to access even after the user rejoins the game.
Storing Persistent Data Bytes
Any type of data can be stored, as below.
String: Stores text data, for example player name, location name and more.
Number: Stores numeric values, for example the number of items the player owns.
Float Number: Stores float numeric values, for example money, exact time, or distance traveled.
True or False: Stores true or false values, useful for checking if a player owns an item for example.
Single Character:Stores a single character, for example storing the initial of the player's name. Deprecated
To store any type of data, simply use the Storage API and the Storage.Create
function.
Accessing data values
After creating a new data byte, it can be accessed in the code by using the Storage API and the Storage.GetData
function.
Making changes to data values
It is possible to dynamically modify the value of a data byte using the Storage.Modify
function.
Clearing the value of a data byte
To clear the value of a data byte, you can use the Storage.ClearData
function. After clearing the data byte, its value will be nill
.
Once the value of a data byte has been cleared, it cannot be recovered anymore.
Deleting a data byte
To permanently delete a data byte from the mod's storage, you can use the Storage API and the function Storage.DeleteData
.
Once the data byte has been deleted, the value cannot be recovered anymore.
Getting the type of a data byte
You can get the type of a data byte by using the Storage API and the Storage.GetDataType
function.
Last updated