# Package openmw.storage¶

openmw.storage contains functions to work with permanent Lua storage.

## Usage:

local storage = require('openmw.storage')
local myModData = storage.globalSection('MyModExample')
myModData:set("someVariable", 1.0)
myModData:set("anotherVariable", { exampleStr='abc', exampleBool=true })
local async = require('openmw.async')
myModData:subscribe(async:callback(function(section, key)
if key then
print('Value is changed:', key, '=', myModData:get(key))
else
print('All values are changed')
end
end))

## Type storage

 storage.allGlobalSections() Get all global sections as a table; can be used by global scripts only. storage.allPlayerSections() Get all global sections as a table; can be used by player scripts only. storage.globalSection(sectionName) Get a section of the global storage; can be used by any script, but only global scripts can change values. storage.playerSection(sectionName) Get a section of the player storage; can be used by player scripts only.

## Type StorageSection

 StorageSection:asTable() Copy all values and return them as a table. StorageSection:get(key) Get value by a string key; if value is a table makes it readonly. StorageSection:getCopy(key) Get value by a string key; if value is a table returns a copy. StorageSection:removeOnExit() Make the whole section temporary: will be removed on exit or when load a save. StorageSection:reset(values) Remove all existing values and assign values from given (the arg is optional) table. StorageSection:set(key, value) Set value by a string key; can not be used for global storage from a local script. StorageSection:subscribe(callback) Subscribe to changes in this section.

## Type storage

### Field(s)

storage.allGlobalSections()

Get all global sections as a table; can be used by global scripts only.

Note that adding/removing items to the returned table doesn't create or remove sections.

### Return value

#table:

storage.allPlayerSections()

Get all global sections as a table; can be used by player scripts only.

Note that adding/removing items to the returned table doesn't create or remove sections.

### Return value

#table:

storage.globalSection(sectionName)

Get a section of the global storage; can be used by any script, but only global scripts can change values.

Creates the section if it doesn't exist.

### Parameter

• #string sectionName :

### Return value

#StorageSection:

storage.playerSection(sectionName)

Get a section of the player storage; can be used by player scripts only.

Creates the section if it doesn't exist.

### Parameter

• #string sectionName :

#StorageSection:

## Type StorageSection

A map key -> value that represents a storage section.

### Field(s)

StorageSection:asTable()

Copy all values and return them as a table.

### Return value

#table:

StorageSection:get(key)

Get value by a string key; if value is a table makes it readonly.

### Parameter

• #string key :

StorageSection:getCopy(key)

Get value by a string key; if value is a table returns a copy.

### Parameter

• #string key :

StorageSection:removeOnExit()

Make the whole section temporary: will be removed on exit or when load a save.

Temporary sections have the same interface to get/set values, the only difference is they will not be saved to the permanent storage on exit. This function can not be used for a global storage section from a local script.

StorageSection:reset(values)

Remove all existing values and assign values from given (the arg is optional) table.

This function can not be used for a global storage section from a local script. Note: section:reset() removes the section.

### Parameter

• #table values : (optional) New values

StorageSection:set(key, value)

Set value by a string key; can not be used for global storage from a local script.

### Parameters

• #string key :

• #any value :

StorageSection:subscribe(callback)

Subscribe to changes in this section.

First argument of the callback is the name of the section (so one callback can be used for different sections). The second argument is the changed key (or nil if reset was used and all values were changed at the same time)

### Parameter

• openmw.async#Callback callback :