Storing data and accessing files

From ESOUI Wiki

Jump to: navigation, search

ESO lua is a stripped lua 5.1 version. ZOs has backported fixes and features from 5.2 and 5.3, changed to using 64-bit, added in date function and traceback().
All file input and output methods were removed!
You are not able to access local/web/other files.
The only way to store and read data are the "SavedVariables", a .lua file named the same like your addon's foldername, using the <globalTableName> from your addon's manifest file tag

## SavedVariables: <globalTableName>

It will be stored in the folder


If your addon's manifest txt and folder is name "MyAddon1" it's located in the folder live/AddOns/MyAddon1, and the SavedVariablse file will be located in live/SavedVariables/MyAddon1.lua
Writing to this file only happens as you logout/reload the UI/a loading screen appears (at zone change e.g.).
This means: there is no "direct access" possible to this file! The data is stored in a global lua table within the memory, updated from/to this table and written to the disk as the reloadui/logout/zone change happens.
Changing that file as the ESO client is running and you are logged in to the world will not have any effect as the data is overwritten on next reloadui/loading screen from this internal lua memory!

Here are a few tutorials about SavedVariables used in your addon:

Important information A single entry in the saved vars can have a maximum of 1999 byte + the binary 0 at the end of the string.
When you try to store more, the game will instead replace it with nil and add a comment to that line:

["variableName"] = nil, -- invalid string value (was your string larger than 2000 characters?)

Comments cannot be added via addons. The only comments that will appear in the SV file are generated by ZOs internally!

Here are some example functions to split and merge the SV lines dynamically, if they are longer than possible:

local MAX_SAVE_DATA_LENGTH = 1999 -- buffer length used by ZOS
local function WriteToSavedVariable(t, key, value)
    local output = value
    local byteLength = #value
    if(byteLength > MAX_SAVE_DATA_LENGTH) then
        output = {}
        local startPos = 1
        local endPos = startPos + MAX_SAVE_DATA_LENGTH - 1
        while startPos <= byteLength do
            output[#output + 1] = string.sub(value, startPos, endPos)
            startPos = endPos + 1
            endPos = startPos + MAX_SAVE_DATA_LENGTH - 1
    t[key] = output

local function ReadFromSavedVariable(t, key, defaultValue)
    local value = t[key] or defaultValue
    if(type(value) == "table") then
        return table.concat(value, "")
    return value

Including other files or libraries (require)
ESO lua does not allow to include files like normal lua allows via the command


You are only able to load addon files from the folder live/AddOns, by adding the path and name to your addon's manifest txt file.
Read this for more information:

Personal tools