evennia.contrib.base_systems.ingame_python.callbackhandler¶
Module containing the CallbackHandler for individual objects.
- class evennia.contrib.base_systems.ingame_python.callbackhandler.CallbackHandler(obj)[source]¶
Bases:
objectThe callback handler for a specific object.
The script that contains all callbacks will be reached through this handler. This handler is therefore a shortcut to be used by developers. This handler (accessible through obj.callbacks) is a shortcut to manipulating callbacks within this object, getting, adding, editing, deleting and calling them.
- script = None¶
- all()[source]¶
Return all callbacks linked to this object.
- Returns:
All callbacks in a dictionary callback_name – callback}. The callback is returned as a namedtuple to simplify manipulation.
- get(callback_name)[source]¶
Return the callbacks associated with this name.
- Parameters:
callback_name (str) – the name of the callback.
- Returns:
A list of callbacks associated with this object and of this name.
Note
This method returns a list of callback objects (namedtuple representations). If the callback name cannot be found in the object’s callbacks, return an empty list.
- get_variable(variable_name)[source]¶
Return the variable value or None.
- Parameters:
variable_name (str) – the name of the variable.
- Returns:
Either the variable’s value or None.
- add(callback_name, code, author=None, valid=False, parameters='')[source]¶
Add a new callback for this object.
- Parameters:
callback_name (str) – the name of the callback to add.
code (str) – the Python code associated with this callback.
author (Character or Account, optional) – the author of the callback.
valid (bool, optional) – should the callback be connected?
parameters (str, optional) – optional parameters.
- Returns:
The callback definition that was added or None.
- edit(callback_name, number, code, author=None, valid=False)[source]¶
Edit an existing callback bound to this object.
- Parameters:
callback_name (str) – the name of the callback to edit.
number (int) – the callback number to be changed.
code (str) – the Python code associated with this callback.
author (Character or Account, optional) – the author of the callback.
valid (bool, optional) – should the callback be connected?
- Returns:
The callback definition that was edited or None.
- Raises:
RuntimeError if the callback is locked. –
- remove(callback_name, number)[source]¶
Delete the specified callback bound to this object.
- Parameters:
callback_name (str) – the name of the callback to delete.
number (int) – the number of the callback to delete.
- Raises:
RuntimeError if the callback is locked. –
- call(callback_name, *args, **kwargs)[source]¶
Call the specified callback(s) bound to this object.
- Parameters:
callback_name (str) – the callback name to call.
*args – additional variables for this callback.
- Keyword Arguments:
number (int, optional) – call just a specific callback.
parameters (str, optional) – call a callback with parameters.
locals (dict, optional) – a locals replacement.
- Returns:
True to report the callback was called without interruption, False otherwise. If the callbackHandler isn’t found, return None.
- class evennia.contrib.base_systems.ingame_python.callbackhandler.Callback(obj, name, number, code, author, valid, parameters, created_on, updated_by, updated_on)¶
Bases:
tuple- author¶
Alias for field number 4
- code¶
Alias for field number 3
- created_on¶
Alias for field number 7
- name¶
Alias for field number 1
- number¶
Alias for field number 2
- obj¶
Alias for field number 0
- parameters¶
Alias for field number 6
- updated_by¶
Alias for field number 8
- updated_on¶
Alias for field number 9
- valid¶
Alias for field number 5