# Saving/Loading Data

# The save callback

Besides the automatic variable saving mechanism introduced in ScriptReference its also possible to save data that is not stored in a variable. You may register one save callback per script! This can be achieved with the following code:

SetDataSaver(function()
    -- run your logic here
    return {
        some = "data",
        someOther = {"data1", "data2"}
    }
end)

Data Save Function Docs

# The load callback

The loadcallback is called in order of script execution AFTER all scripts have been executed! This allows to ensure that everything has been registered! You may register one load callback per script! Do not that the data value will be nil when no data has been saved previously!

SetDataLoader(function(data)
    if(data == nil) then
        -- set default data here
        return
    end
    -- run your logic here. Data is whatever you saved
end)

Data Load Function Docs