The store API holds up to 64 variables shared by all script slots. Changes are saved to flash by the persistence subsystem, not immediately by these calls.
Keys can be string names or 32-bit integer identifiers.
Values can be integers, floating-point numbers, or booleans.
store.read(key)
Returns the stored value, or nil if the variable does not exist.
Example: local count = store.read("start_count")
store.write(key, value)
Creates or updates a variable. Returns true on success. Invalid arguments raise an error. If all 64 entries are used, adding a new variable replaces the oldest variable and prints a warning. Updating an existing variable does not change its age.
Example: store.write("start_count", 12)
store.clear(key)
Removes one variable. Returns true if it was removed, or false if it did not exist.
Example: store.clear("start_count")
store.reset()
Removes all variables for all script slots. Returns no values. The empty store is saved by the persistence subsystem; this call does not directly erase flash.
Example: store.reset()
Example script:
local startcount = store.read("start_count")
-- Set to zero first time
if (startcount == nil) then
startcount = 0
end
startcount = startcount + 1
store.write("start_count", startcount)
print(startcount)
while true do
yield()
end
For more information about the MaxxECU user scripts, see User Scripts (LUA), or directly reference the LUA api reference and LUA examples. For more all available LUA settings and options, see Script Code, Script Input Control, Output Functions and Script RT values.