Skip to content

[3.0] Storage System #6

Description

@NickMBR

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.
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions