Events

Lykos contains an events system, which allows for hooking code into existing methods easily and without making messy-looking functions. This system is modeled after javascript events, and uses much of the same nomenclature. This page gives an overview of the events API, and afterwards an alphabetical listing of all currently-defined events in lykos. For examples on how to use events and the wide amount of flexibility given to the system, see src/gamemodes.py, much of the complexity of modes that add extra stuff (such as sleepy and maelstrom) is implemented via events.

The events API may be found in the  module, the recommended import line is   followed by   for a convenient shortcut. The examples below will assume that these two lines are used.

The  method will register   to fire off whenever an event of name   is dispatched. The  function will always be given at least one parameters: the   object (as defined below) that was constructed for the current event. The  parameter may be used to order event listeners -- lower numbers are run before higher numbers. The default is usually fine unless you know you need to execute first or last. This function is a no-op if passed in an,  , and   that it has previously registered.

The opposite of, this will remove the listener with the given  ,  , and. This function does not return a value, and will not throw an error if it cannot find a matching listener (it will no-op in that case).

(class)
Creates a new  instance with the given   and. The  parameter is meant to be any mutable data you wish to pass to event callbacks. Typically this is a dict, but it doesn't have to be. The events list below will describe what data is passed to callbacks (if any) for any particular event.

(instance method)
Dispatches a previously constructed event, which calls all currently-registered event listeners on it. The listener callback functions will be passed in the  instance followed by. What these are vary by event, see below for more information for any particular event. When dispatching an event, it is typically good to include enough state information as to be useful as part of the args.

(instance variable)
An event listener can set this to  to prevent the rest of the registered listeners from firing on this event.

(instance variable)
An event listener can set this to  to prevent the &quot;default&quot; action of the event from occurring. This is not always used by every event, see the documentation below to see what this does for any particular event.