Docs / Plugins / Plugin API reference
Storage and files
omsi.storage.* is a key/value store, omsi.files.* reads and writes files. Both live only in the plugin's data folder. Paths are relative to that folder; .. and absolute paths are refused.
omsi.files.append#
omsi.files.append(path, data) → true, or false and the reason
Adds to the end of a file of the data folder (a log, a CSV of trips).
Parameters: path string; data string.
Since 0.2.22. Permission: storage.
omsi.files.append("trips.csv", "136,3,+30\n")omsi.files.delete#
omsi.files.delete(path) → boolean
Removes a file or an empty folder of the data folder.
Parameters: path string.
Since 0.2.22. Permission: storage.
omsi.files.dir#
omsi.files.dir() → string
Where the data folder is on this computer (to tell the player; the plugin reaches it with relative paths only).
Since 0.2.22. Permission: storage.
omsi.files.exists#
omsi.files.exists(path) → boolean
Whether the data folder has this file or folder.
Parameters: path string.
Since 0.2.22. Permission: storage.
omsi.files.list#
omsi.files.list([dir]) → list of tables, or nil and the reason
The entries of the data folder (or a folder in it): {name, dir, size}.
Parameters: dir string, optional.
Since 0.2.22. Permission: storage.
omsi.files.mkdir#
omsi.files.mkdir(path) → boolean
Makes a folder (and those above it) in the data folder.
Parameters: path string.
Since 0.2.22. Permission: storage.
omsi.files.read#
omsi.files.read(path) → text, or nil and the reason
A file of the plugin's data folder (path relative to it; .. and absolute paths are refused).
Parameters: path string.
Since 0.2.22. Permission: storage.
local text, why = omsi.files.read("notes.txt")omsi.files.write#
omsi.files.write(path, data) → true, or false and the reason
Writes a file of the data folder (its folders are made); at most 16 MB at once and 256 MB in all.
Parameters: path string; data string.
Since 0.2.22. Permission: storage.
omsi.storage.all#
omsi.storage.all() → table
Everything stored, as one table.
Since 0.2.22. Permission: storage.
omsi.storage.clear#
omsi.storage.clear() → nil
Removes every key.
Since 0.2.22. Permission: storage.
omsi.storage.delete#
omsi.storage.delete(key) → boolean
Removes a key; true when it was there.
Parameters: key string.
Since 0.2.22. Permission: storage.
omsi.storage.get#
omsi.storage.get(key) → any
A value the plugin stored, or nil. The storage is the plugin's own and survives the session (kept as storage.json in its data folder).
Parameters: key string.
Since 0.2.22. Permission: storage.
omsi.storage.keys#
omsi.storage.keys() → list of strings
The keys stored, in the order they were first set.
Since 0.2.22. Permission: storage.
omsi.storage.save#
omsi.storage.save() → nil
Writes the storage now (it is written by itself when the game ends).
Since 0.2.22. Permission: storage.
omsi.storage.set#
omsi.storage.set(key, value) → nil
Stores a value under a key: a number, text, boolean or a table of them (nil removes it). It is written when the game ends, the plugin is loaded again, or storage.save() is called.
Parameters: key string; value any.
Since 0.2.22. Permission: storage.
omsi.storage.set("best_trip", 812)
local best = omsi.storage.get("best_trip") or 0Something wrong or missing? Fix it on GitHub or open an issue.