storage
Provides a way to persist data to the user’s storage drive, for use across Assetto Corsa sessions.
Usage Patterns
Section titled “Usage Patterns”Define a layout of keys and default values. Accessing the returned table automatically manages disk input and output.
local settings = ac.storage({ uiVisible = true, opacity = 0.8})Manage a specific key directly.
local storedValue = ac.storage("my_key", "default_value")Direct global access within the script’s namespace.
ac.storage.lastActive = os.date()Description
Section titled “Description”ac.storage handles the heavy lifting of reading from and writing to the storage drive.
Writes are debounced, meaning disk access is deferred for a few seconds and skipped entirely if no value change is detected.
The storage system supports the following data types:
stringnumberbooleanvec2,vec3, andvec4rgb, andrgbm
Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
layout | table or string | Yes | Either a table of default values or a specific string key. |
keyPrefix | string | No | Optional prefix added to all keys in the storage table. |
Examples
Section titled “Examples”Using storage to remember the state of a UI checkbox.
-- define our persistent settingslocal settings = ac.storage({ showMap = true})
function script.windowMain() -- checkbox updates the 'settings' table, -- which triggers a disk save automatically ui.checkbox("Show Minimap", settings.showMap)
if settings.showMap then drawMyMap() endendCounting how many times the user has run this script.
local stats = ac.storage({ runCount = 0})
-- increment and savestats.runCount = stats.runCount + 1ac.log("This script has been run " .. stats.runCount .. " times.")