evennia.utils.containers

Containers

Containers are storage classes usually initialized from a setting. They represent Singletons and acts as a convenient place to find resources ( available as properties on the singleton)

evennia.GLOBAL_SCRIPTS evennia.OPTION_CLASSES

class evennia.utils.containers.Container[source]

Bases: object

Base container class. A container is simply a storage object whose properties can be acquired as a property on it. This is generally considered a read-only affair.

The container is initialized by a list of modules containing callables.

storage_modules = []
__init__()[source]

Read data from module.

load_data()[source]

Delayed import to avoid eventual circular imports from inside the storage modules.

get(key, default=None)[source]

Retrive data by key (in case of not knowing it beforehand).

Parameters
  • key (str) – The name of the script.

  • default (any, optional) – Value to return if key is not found.

Returns

any (any) – The data loaded on this container.

all()[source]

Get all stored data

Returns

scripts (list) – All global script objects stored on the container.

class evennia.utils.containers.OptionContainer[source]

Bases: evennia.utils.containers.Container

Loads and stores the final list of OPTION CLASSES.

Can access these as properties or dictionary-contents.

storage_modules = ['evennia.utils.optionclasses']
class evennia.utils.containers.GlobalScriptContainer[source]

Bases: evennia.utils.containers.Container

Simple Handler object loaded by the Evennia API to contain and manage a game’s Global Scripts. This will list global Scripts created on their own but will also auto-(re)create scripts defined in settings.GLOBAL_SCRIPTS.

Example

import evennia evennia.GLOBAL_SCRIPTS.scriptname

Note

This does not use much of the BaseContainer since it’s not loading callables from settings but a custom dict of tuples.

__init__()[source]

Note: We must delay loading of typeclasses since this module may get initialized before Scripts are actually initialized.

start()[source]

Called last in evennia.__init__ to initialize the container late (after script typeclasses have finished loading).

We include all global scripts in the handler and make sure to auto-load time-based scripts.

load_data()[source]

This delayed import avoids trying to load Scripts before they are initialized.

get(key, default=None)[source]

Retrive data by key (in case of not knowing it beforehand). Any scripts that are in settings.GLOBAL_SCRIPTS that are not found will be recreated on-demand.

Parameters
  • key (str) – The name of the script.

  • default (any, optional) – Value to return if key is not found at all on this container (i.e it cannot be loaded at all).

Returns

any (any) – The data loaded on this container.

all()[source]

Get all global scripts. Note that this will not auto-start scripts defined in settings.

Returns

list

All global script objects in game (both managed and unmanaged),

sorted alphabetically.