Persistent data
By default, Piecewise will not save any data when your bot stops, leaving it up to you to manage data you want to keep. There are a few ways to save and load data into Piecewise:
- Using the save list to file and load list from file blocks
- Using the save table to file and load table from file blocks
- Using the [append to|write] file with text and contents of file as text blocks.
Where Piecewise looks for and/or saves data from these blocks depends on your operating system and how you run your bot:
- Windows:
%appdata%\Piecewise\.lazurite
- macOS:
~/Library/Application Support/Piecewise/.lazurite
- Linux:
~/.lazurite
Saving and loading lists
To save and load data stored as a list, use the save list to file and load list from file blocks. When loading, if the requested file does not exist or does not contain a JSON-encoded table, an empty table will be returned.
Saving and loading tables
To save and load data stored as a table, use the save table to file and load table from file blocks. When loading, if the requested file does not exist or does not contain a JSON-encoded table, an empty table will be returned.
Saving and loading arbitrary text
To save and load arbitrary text, use the [append to|write] file with text and contents of file as text blocks.
When loading, if the file does not exist, an error will be thrown. Use the if file exists block to check if a file exists before loading it.
Appending to a file will add the supplied text to the end of it. Overwriting the file will clear its contents and replace it with the supplied text.