<spanid="evennia-contrib-base-systems-ingame-python-scripts"></span><h1>evennia.contrib.base_systems.ingame_python.scripts<aclass="headerlink"href="#module-evennia.contrib.base_systems.ingame_python.scripts"title="Permalink to this headline">¶</a></h1>
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.contrib.base_systems.ingame_python.scripts.</code><codeclass="sig-name descname">EventHandler</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#EventHandler"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">at_script_creation</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#EventHandler.at_script_creation"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.at_script_creation"title="Permalink to this definition">¶</a></dt>
<dd><p>Hook called when the script is created.</p>
<codeclass="sig-name descname">at_server_start</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#EventHandler.at_server_start"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.at_server_start"title="Permalink to this definition">¶</a></dt>
<dd><p>Set up the event system when starting.</p>
<p>Note that this hook is called every time the server restarts
(including when it’s reloaded). This hook performs the following
<codeclass="sig-name descname">get_events</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#EventHandler.get_events"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.get_events"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a dictionary of events on this object.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>obj</strong> (<em>Object</em><em> or </em><em>typeclass</em>) – the connected object or a general typeclass.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>A dictionary of the object’s events.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Events would define what the object can have as
callbacks. Note, however, that chained callbacks will not
appear in events and are handled separately.</p>
<p>You can also request the events of a typeclass, not a
connected object. This is useful to get the global list
of events for a typeclass that has no object yet.</p>
<codeclass="sig-name descname">get_variable</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">variable_name</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#EventHandler.get_variable"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.get_variable"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the variable defined in the locals.</p>
<p>This can be very useful to check the value of a variable that can be modified in an event, and whose value will be used in code. This system allows additional customization.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>variable_name</strong> (<em>str</em>) – the name of the variable to return.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>The variable if found in the locals.
None if not found in the locals.</p>
</dd>
</dl>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>This will return the variable from the current locals.
Keep in mind that locals are shared between events. As
every event is called one by one, this doesn’t pose
additional problems if you get the variable right after
an event has been executed. If, however, you differ,
there’s no guarantee the variable will be here or will
<codeclass="sig-name descname">get_callbacks</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#EventHandler.get_callbacks"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.get_callbacks"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a dictionary of the object’s callbacks.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>obj</strong> (<em>Object</em>) – the connected objects.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>A dictionary of the object’s callbacks.</p>
</dd>
</dl>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>This method can be useful to override in some contexts,
<codeclass="sig-name descname">del_callback</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em>, <emclass="sig-param"><spanclass="n">callback_name</span></em>, <emclass="sig-param"><spanclass="n">number</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#EventHandler.del_callback"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.del_callback"title="Permalink to this definition">¶</a></dt>
<dd><p>Delete the specified callback.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>obj</strong> (<em>Object</em>) – the typeclassed object containing the callback.</p></li>
<li><p><strong>callback_name</strong> (<em>str</em>) – the name of the callback to delete.</p></li>
<li><p><strong>number</strong> (<em>int</em>) – the number of the callback to delete.</p></li>
</ul>
</dd>
<dtclass="field-even">Raises</dt>
<ddclass="field-even"><p><strong>RuntimeError if the callback is locked.</strong>–</p>
<codeclass="sig-name descname">accept_callback</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em>, <emclass="sig-param"><spanclass="n">callback_name</span></em>, <emclass="sig-param"><spanclass="n">number</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#EventHandler.accept_callback"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.accept_callback"title="Permalink to this definition">¶</a></dt>
<dd><p>Valid a callback.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>obj</strong> (<em>Object</em>) – the object containing the callback.</p></li>
<li><p><strong>callback_name</strong> (<em>str</em>) – the name of the callback.</p></li>
<li><p><strong>number</strong> (<em>int</em>) – the number of the callback.</p></li>
<codeclass="sig-name descname">call</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em>, <emclass="sig-param"><spanclass="n">callback_name</span></em>, <emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#EventHandler.call"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.call"title="Permalink to this definition">¶</a></dt>
<dd><p>Call the connected callbacks.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>obj</strong> (<em>Object</em>) – the Evennia typeclassed object.</p></li>
<li><p><strong>callback_name</strong> (<em>str</em>) – the callback name to call.</p></li>
<li><p><strong>*args</strong>– additional variables for this callback.</p></li>
</ul>
</dd>
<dtclass="field-even">Keyword Arguments</dt>
<ddclass="field-even"><ulclass="simple">
<li><p><strong>number</strong> (<em>int</em><em>, </em><em>optional</em>) – call just a specific callback.</p></li>
<li><p><strong>parameters</strong> (<em>str</em><em>, </em><em>optional</em>) – call a callback with parameters.</p></li>
<li><p><strong>locals</strong> (<em>dict</em><em>, </em><em>optional</em>) – a locals replacement.</p></li>
</ul>
</dd>
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p>True to report the callback was called without interruption,
<codeclass="sig-name descname">handle_error</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">callback</span></em>, <emclass="sig-param"><spanclass="n">trace</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#EventHandler.handle_error"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.handle_error"title="Permalink to this definition">¶</a></dt>
<dd><p>Handle an error in a callback.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>callback</strong> (<em>dict</em>) – the callback representation.</p></li>
<li><p><strong>trace</strong> (<em>list</em>) – the traceback containing the exception.</p></li>
</ul>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>This method can be useful to override to change the default
handling of errors. By default, the error message is sent to
the character who last updated the callback, if connected.
<codeclass="sig-name descname">set_task</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">seconds</span></em>, <emclass="sig-param"><spanclass="n">obj</span></em>, <emclass="sig-param"><spanclass="n">callback_name</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#EventHandler.set_task"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.set_task"title="Permalink to this definition">¶</a></dt>
<dd><p>Set and schedule a task to run.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>seconds</strong> (<em>int</em><em>, </em><em>float</em>) – the delay in seconds from now.</p></li>
<li><p><strong>obj</strong> (<em>Object</em>) – the typecalssed object connected to the event.</p></li>
<li><p><strong>callback_name</strong> (<em>str</em>) – the callback’s name.</p></li>
</ul>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>This method allows to schedule a “persistent” task.
‘utils.delay’ is called, but a copy of the task is kept in
the event handler, and when the script restarts (after reload),
the differed delay is called again.
The dictionary of locals is frozen and will be available
again when the task runs. This feature, however, is limited
by the database: all data cannot be saved. Lambda functions,
class methods, objects inside an instance and so on will
<emclass="property">exception </em><codeclass="sig-name descname">DoesNotExist</code><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.DoesNotExist"title="Permalink to this definition">¶</a></dt>
<emclass="property">exception </em><codeclass="sig-name descname">MultipleObjectsReturned</code><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.MultipleObjectsReturned"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">path</code><emclass="property"> = 'evennia.contrib.base_systems.ingame_python.scripts.EventHandler'</em><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.path"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">typename</code><emclass="property"> = 'EventHandler'</em><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.EventHandler.typename"title="Permalink to this definition">¶</a></dt>
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.contrib.base_systems.ingame_python.scripts.</code><codeclass="sig-name descname">TimeEventScript</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#TimeEventScript"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.TimeEventScript"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">at_script_creation</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#TimeEventScript.at_script_creation"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.TimeEventScript.at_script_creation"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">at_repeat</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#TimeEventScript.at_repeat"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.TimeEventScript.at_repeat"title="Permalink to this definition">¶</a></dt>
<dd><p>Call the event and reset interval.</p>
<p>It is necessary to restart the script to reset its interval
only twice after a reload. When the script has undergone
down time, there’s usually a slight shift in game time. Once
the script restarts once, it will set the average time it
needs for all its future intervals and should not need to be
restarted. In short, a script that is created shouldn’t need
to restart more than once, and a script that is reloaded should
<emclass="property">exception </em><codeclass="sig-name descname">DoesNotExist</code><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.TimeEventScript.DoesNotExist"title="Permalink to this definition">¶</a></dt>
<emclass="property">exception </em><codeclass="sig-name descname">MultipleObjectsReturned</code><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.TimeEventScript.MultipleObjectsReturned"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">path</code><emclass="property"> = 'evennia.contrib.base_systems.ingame_python.scripts.TimeEventScript'</em><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.TimeEventScript.path"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">typename</code><emclass="property"> = 'TimeEventScript'</em><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.TimeEventScript.typename"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-prename descclassname">evennia.contrib.base_systems.ingame_python.scripts.</code><codeclass="sig-name descname">complete_task</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">task_id</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/ingame_python/scripts.html#complete_task"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.ingame_python.scripts.complete_task"title="Permalink to this definition">¶</a></dt>
<dd><p>Mark the task in the event handler as complete.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>task_id</strong> (<em>int</em>) – the task ID.</p>
</dd>
</dl>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>This function should be called automatically for individual tasks.</p>