Data - guiled/LRE GitHub Wiki

LRE implements a way for components to holds all type of data, and to keep it between loads. It is available for LRE sheets and LRE components with the method data

Available methods

LREObject.data(name, value, persist) Attach data to the object

LREObject.deleteData(name) Remove the data from the object (volatile or persistent)

LREObject.hasData(name) Return true if the object has the given named data (volatile or persistent)

Operating description

There is two kind of data storage : volatile and persistent

Volatile data

This data are saved for each component, but are always blank at the game start (sheet initialisation). They are useful for saving script state of components (like boolean editing, saved, etc)

Usage

cmp.data('saving', true);    // create or overwrite the 'saving' data to 'true'
log(cmp.data('saving'));     // log "true"
cmp.deleteData('saving');    // remove this data

Important

If there was a persistent data with the given name, it won't be persistent anymore.

Persistence data

This data are saved for each component and stored to be reusable event after a new game start.

Usage

if (!cmp.hasData('initiated')) {
    cmp.data('initiated', false, true);   // Third argument is for persistence
}
initiateComponent(cmp);
cmp.data('initiated', true, true);    // create or overwrite the 'saving' data to 'true'

Important

If there was a volatile data with the given name, it will now be persistent and not volatile any more.