Storage
The storage system will use Expression 2's file system. It can only load/save one file per 200ms, it should account for this to load all top scores and saved settings. Also prevent override of files when the file was not loaded or could not be found.
Reading Files
Read a file upon spawning the Expression 2:
if (first() || duped()) {
runOnFile(1)
if (fileCanLoad()) {
fileLoad("data.txt")
}
}
To prevent load fails, this might be the solution:
function void loadData() {
if (fileCanLoad()) {
fileLoad("data.txt")
}
else {
timer("loadData", 200)
}
}
if (clk("loadData")) {
loadData()
stoptimer("loadData")
}
if (first() || dupefinished()) {
runOnFile(1)
loadData()
}
Then check if the file is loaded correctly and set the table data:
// fileClk(filename) only fires when the specific file has been loaded
if (fileClk("data.txt")) {
if (fileStatus() == _FILE_OK) {
DataTable = vonDecodeTable(fileRead())
}
}
Saving Files
Insert a new table on the loaded table and then save it:
function void saveData(Description:string) {
local Table = table()
Table["Description", string] = Description
DataTable:pushTable(Table)
if (fileCanWrite()) {
fileWrite("data.txt", vonEncode(DataTable))
// Prevent override! Check if file was saved, load it and then compare with the current table.
}
}
Storage
The storage system will use Expression 2's file system. It can only load/save one file per 200ms, it should account for this to load all top scores and saved settings. Also prevent override of files when the file was not loaded or could not be found.
Reading Files
Read a file upon spawning the Expression 2:
To prevent load fails, this might be the solution:
Then check if the file is loaded correctly and set the table data:
Saving Files
Insert a new table on the loaded table and then save it: