<spanid="evennia-scripts-ondemandhandler"></span><h1>evennia.scripts.ondemandhandler<aclass="headerlink"href="#module-evennia.scripts.ondemandhandler"title="Permalink to this headline">¶</a></h1>
<p>Helper to handle on-demand requests, allowing a system to change state only when a player or system
actually needs the information. This is a very efficient way to handle gradual changes, requiring
not computer resources until the state is actually needed.</p>
<p>For example, consider a flowering system, where a seed sprouts, grows and blooms over a certain time.
One _could_ implement this with e.g. a Script or a ticker that gradually moves the flower along
its stages of growth. But what if that flower is in a remote location, and no one is around to see it?
You are then wasting computational resources on something that no one is looking at.</p>
<p>The truth is that most of the time, players are not looking at most of the things in the game. They
_only_ need to know about which state the flower is in when they are actually looking at it, or
when they are in the same room as it (so it can be incorporated in the room description). This is
where on-demand handling comes in.</p>
<p>This is the basic principle, using the flowering system as an example.</p>
<olclass="arabic simple">
<li><dlclass="simple">
<dt>Someone plants a seed in a room (could also be automated). The seed is in a “seedling” state.</dt><dd><p>We store the time it was planted (this is the important bit).</p>
</dd>
</dl>
</li>
<li><p>A player enters the room or looks at the plant. We check the time it was planted, and calculate</p></li>
</ol>
<blockquote>
<div><p>how much time has passed since it was planted. If enough time has passed, we change the state to
“sprouting” and probably change its description to reflect this.</p>
</div></blockquote>
<olclass="arabic simple"start="3">
<li><p>If a player looks at the plant and not enough time has passed, it keeps the last updated state.</p></li>
<li><p>Eventually, it will be bloom time, and the plant will change to a “blooming” state when the
player looks.</p></li>
<li><p>If no player ever comes around to look at the plant, it will never change state, and if they show
up after a long time, it may not show as a “wilted” state or be outright deleted when observed,
since too long time has passed and the plant has died.</p></li>
</ol>
<p>With a system like this you could have growing plants all over your world and computing usage would
only scale by how many players you have exploring your world. The players will not know the difference
between this and a system that is always running, but your server will thank you.</p>
<p>There is only one situation where this system is not ideal, and that is when a player should be
informed of the state change _even if they perform no <ahref="#id1"><spanclass="problematic"id="id2">action_</span></a>. That is, even if they are just idling
in the room, they should get a message like ‘the plant suddenly blooms’ (or, more commonly, for
messages like ‘you are feeling hungry’). For this you still probably need to use one of Evennia’s
built-in timers or tickers instead. But most of the time you should really consider using on-demand
handling instead.</p>
<sectionid="usage">
<h2>Usage<aclass="headerlink"href="#usage"title="Permalink to this headline">¶</a></h2>
<emclass="property">static </em><codeclass="sig-name descname">runtime</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandTask.runtime"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandTask.runtime"title="Permalink to this definition">¶</a></dt>
<dd><p>Wraps the gametime.runtime() function.</p>
<p>Need to import here to avoid circular imports during server reboot.
<emclass="property">static </em><codeclass="sig-name descname">stagefunc_loop</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">task</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandTask.stagefunc_loop"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandTask.stagefunc_loop"title="Permalink to this definition">¶</a></dt>
<dd><p>Attach this to the last stage to have the task start over from
<emclass="property">static </em><codeclass="sig-name descname">stagefunc_bounce</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">task</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandTask.stagefunc_bounce"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandTask.stagefunc_bounce"title="Permalink to this definition">¶</a></dt>
<dd><p>This endfunc will have the task reverse direction and go through the stages in
reverse order. This stage-function must be placed at both ‘ends’ of the stage sequence
<codeclass="sig-name descname">default_stage_function</code><emclass="property"> = None</em><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandTask.default_stage_function"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">__init__</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">key</span></em>, <emclass="sig-param"><spanclass="n">category</span></em>, <emclass="sig-param"><spanclass="n">stages</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">autostart</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandTask.__init__"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandTask.__init__"title="Permalink to this definition">¶</a></dt>
<dd><dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>key</strong> (<em>str</em>) – A unique identifier for the task.</p></li>
<li><p><strong>stages</strong> (<em>dict</em><em>, </em><em>optional</em>) – A dictionary <strong>{dt: str}</strong> or <strong>{int or float: (str, callable)}</strong>
of time-deltas (in seconds) and the stage name they represent. If the value is a
tuple, the first element is the name of the stage and the second is a callable
that will be called when that stage is <em>first</em> reached. Warning: This callable
is <em>only</em> triggered if the stage is actually checked/retrieved while the task is
in that stage checks - it’s _not_ guaranteed to be called, even if the task
time-wise goes through all its stages. Each callable must be picklable (so normally
it should be a stand-alone function), and takes one argument - this OnDemandTask,
which it can be modified in-place as needed. This can be used to loop a task or do
other changes to the task.</p></li>
<li><p><strong>autostart</strong> (<em>bool</em><em>, </em><em>optional</em>) – If <strong>last_checked</strong> is <strong>None</strong>, and this is <strong>False</strong>, then the
time will not start counting until the first call of <strong>get_dt</strong> or <strong>get_stage</strong>. If
<strong>True</strong>, creating the task will immediately make a hidden check and start the timer.</p></li>
<codeclass="sig-name descname">check</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">autostart</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandTask.check"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandTask.check"title="Permalink to this definition">¶</a></dt>
<dd><p>Check the current stage of the task and return the time-delta to the next stage.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>autostart</strong> (<em>bool</em><em>, </em><em>optional</em>) – If this is set, and the task has not been started yet,
it will be started by this check. This is mainly used internally.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>tuple</em>– A tuple (dt, stage) where <strong>dt</strong> is the time-delta (in seconds) since the test
started (or since it started its latest iteration). and <strong>stage</strong> is the name of the
current stage. If no stages are defined, <strong>stage</strong> will always be <strong>None</strong>. Use <strong>get_dt</strong> and
<strong>get_stage</strong> to get only one of these values.</p>
<codeclass="sig-name descname">get_dt</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandTask.get_dt"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandTask.get_dt"title="Permalink to this definition">¶</a></dt>
<dd><p>Get the time-delta since last check.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>int</em>– The time since the last check, or 0 if this is the first time the task is checked.</p>
<codeclass="sig-name descname">set_dt</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">dt</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandTask.set_dt"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandTask.set_dt"title="Permalink to this definition">¶</a></dt>
<dd><p>Set the time-delta since the task started manually. This allows you to ‘cheat’ the system
and set the time manually. This is useful for testing or when a system manipulates the state
somehow (like using a potion that speeds up the growth of a plant).</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>dt</strong> (<em>int</em>) – The time-delta to set. This is an absolute value in seconds, same as returned
by <strong>get_dt</strong>.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Setting this will not on its own trigger any stage functions - this will only happen
as normal, next time the state is checked and the stage is found to have changed.</p>
<codeclass="sig-name descname">get_stage</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandTask.get_stage"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandTask.get_stage"title="Permalink to this definition">¶</a></dt>
<dd><p>Get the current stage of the task. If no stage was given, this will return <strong>None</strong> but
still update the last_checked time.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>str or None</em>– The current stage of the task, or <strong>None</strong> if no stages are set.</p>
<codeclass="sig-name descname">set_stage</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">stage</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandTask.set_stage"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandTask.set_stage"title="Permalink to this definition">¶</a></dt>
<dd><p>Set the stage of the task manually. This allows you to ‘cheat’ the system and set the stage
manually. This is useful for testing or when a system manipulates the state somehow (like
using a potion that speeds up the growth of a plant). The given stage must be previously
created for the given task. If task has no stages, this will do nothing.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>stage</strong> (<em>str</em><em>, </em><em>optional</em>) – The stage to set. If <strong>None</strong>, the task will be reset to its
initial (first) state.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Setting this will not on its own trigger any stage functions - this will only happen
as normal, next time the state is checked and the stage is found to have changed.</p>
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.scripts.ondemandhandler.</code><codeclass="sig-name descname">OnDemandHandler</code><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">__init__</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.__init__"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.__init__"title="Permalink to this definition">¶</a></dt>
<dd><p>Initialize self. See help(type(self)) for accurate signature.</p>
<codeclass="sig-name descname">load</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.load"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.load"title="Permalink to this definition">¶</a></dt>
<dd><p>Load the on-demand timers from ServerConfig storage.</p>
<p>This should be automatically called when Evennia starts.</p>
<codeclass="sig-name descname">save</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.save"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.save"title="Permalink to this definition">¶</a></dt>
<dd><p>Save the on-demand timers to ServerConfig storage. Should be called when Evennia shuts down.</p>
<codeclass="sig-name descname">add</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">key</span></em>, <emclass="sig-param"><spanclass="n">category</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">stages</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">autostart</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.add"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.add"title="Permalink to this definition">¶</a></dt>
<dd><p>Add a new on-demand task.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>key</strong> (<em>str</em><em>, </em><em>callable</em><em>, </em><aclass="reference internal"href="#evennia.scripts.ondemandhandler.OnDemandTask"title="evennia.scripts.ondemandhandler.OnDemandTask"><em>OnDemandTask</em></a><em> or </em><em>Object</em>) – A unique identifier for the task. If this
is a callable, it will be called without arguments. If a db-Object, it will be
converted to a string representation (which will include its (#dbref). If an
<strong>OnDemandTask</strong>, then all other arguments are ignored and the task is simply added
as-is.</p></li>
<li><p><strong>category</strong> (<em>str</em><em> or </em><em>callable</em><em>, </em><em>optional</em>) – A category to group the task under. If given, it
must also be given when checking the task.</p></li>
<li><p><strong>stages</strong> (<em>dict</em><em>, </em><em>optional</em>) – A dictionary {dt: str}, of time-deltas (in seconds) and the
stage which should be entered after that much time has passed. autostart (bool,</p></li>
<li><p><strong>optional</strong><strong>)</strong>– If <strong>True</strong>, creating the task will immediately make a hidden
<dt>The created task (or the same that was added, if given an <strong>OnDemandTask</strong></dt><dd><p>as a <strong>key</strong>). Use <strong>task.get_dt()</strong> and <strong>task.get_stage()</strong> to get data from it manually.</p>
<codeclass="sig-name descname">batch_add</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">tasks</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.batch_add"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.batch_add"title="Permalink to this definition">¶</a></dt>
<dd><p>Add multiple on-demand tasks at once.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>*tasks</strong> (<aclass="reference internal"href="#evennia.scripts.ondemandhandler.OnDemandTask"title="evennia.scripts.ondemandhandler.OnDemandTask"><em>OnDemandTask</em></a>) – A set of OnDemandTasks to add.</p>
<codeclass="sig-name descname">remove</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">key</span></em>, <emclass="sig-param"><spanclass="n">category</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.remove"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.remove"title="Permalink to this definition">¶</a></dt>
<dd><p>Remove an on-demand task.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>key</strong> (<em>str</em><em>, </em><em>callable</em><em>, </em><aclass="reference internal"href="#evennia.scripts.ondemandhandler.OnDemandTask"title="evennia.scripts.ondemandhandler.OnDemandTask"><em>OnDemandTask</em></a><em> or </em><em>Object</em>) – The unique identifier for the task. If a callable, will
be called without arguments. If an Object, will be converted to a string. If an <strong>OnDemandTask</strong>,
then all other arguments are ignored and the task will be used to identify the task to remove.</p></li>
<li><p><strong>category</strong> (<em>str</em><em> or </em><em>callable</em><em>, </em><em>optional</em>) – The category of the task.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>OnDemandTask or None</em>– The removed task, or <strong>None</strong> if no task was found.</p>
<codeclass="sig-name descname">batch_remove</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">keys</span></em>, <emclass="sig-param"><spanclass="n">category</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.batch_remove"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.batch_remove"title="Permalink to this definition">¶</a></dt>
<dd><p>Remove multiple on-demand tasks at once, potentially within a given category.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>*keys</strong> (<em>str</em><em>, </em><em>callable</em><em>, </em><aclass="reference internal"href="#evennia.scripts.ondemandhandler.OnDemandTask"title="evennia.scripts.ondemandhandler.OnDemandTask"><em>OnDemandTask</em></a><em> or </em><em>Object</em>) – The unique identifiers for the tasks. If
a callable, will be called without arguments. If an Object, will be converted to a
string. If an <strong>OnDemandTask</strong>, then all other arguments are ignored and the task will
be used to identify the task to remove.</p></li>
<li><p><strong>category</strong> (<em>str</em><em> or </em><em>callable</em><em>, </em><em>optional</em>) – The category of the tasks.</p></li>
<codeclass="sig-name descname">all</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">category</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">all_on_none</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.all"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.all"title="Permalink to this definition">¶</a></dt>
<dd><p>Get all on-demand tasks.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>category</strong> (<em>str</em><em>, </em><em>optional</em>) – The category of the tasks.</p></li>
<li><p><strong>all_on_none</strong> (<em>bool</em><em>, </em><em>optional</em>) – Determines what to return if <strong>category</strong> is <strong>None</strong>.
If <strong>True</strong>, all tasks will be returned. If <strong>False</strong>, only tasks without a category
will be returned.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>dict</em>– A dictionary of all on-demand task, on the form <strong>{(key, category): task), …}</strong>.
Use <strong>task.get_dt()</strong> or <strong>task.get_stage()</strong> to get the time-delta or stage of each task
<codeclass="sig-name descname">clear</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">category</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">all_on_none</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.clear"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.clear"title="Permalink to this definition">¶</a></dt>
<dd><p>Clear all on-demand tasks.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>category</strong> (<em>str</em><em>, </em><em>optional</em>) – The category of the tasks to clear. What <strong>None</strong> means is determined
by the <strong>all_on_none</strong> kwarg.</p></li>
<li><p><strong>all_on_none</strong> (<em>bool</em><em>, </em><em>optional</em>) – Determines what to clear if <strong>category</strong> is <strong>None</strong>. If <strong>True</strong>,
clear all tasks, if <strong>False</strong>, only clear tasks with no category.</p></li>
<codeclass="sig-name descname">get</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">key</span></em>, <emclass="sig-param"><spanclass="n">category</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.get"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.get"title="Permalink to this definition">¶</a></dt>
<dd><p>Get an on-demand task. This will _not_ check it.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>key</strong> (<em>str</em><em>, </em><em>callable</em><em>, </em><aclass="reference internal"href="#evennia.scripts.ondemandhandler.OnDemandTask"title="evennia.scripts.ondemandhandler.OnDemandTask"><em>OnDemandTask</em></a><em> or </em><em>Object</em>) – The unique identifier for the task. If a
callable, will be called without arguments. If an Object, will be converted to a string.
If an <strong>OnDemandTask</strong>, then all other arguments are ignored and the task will be used
(only useful to check the task is the same).</p></li>
<li><p><strong>category</strong> (<em>str</em><em>, </em><em>optional</em>) – The category of the task. If unset, this will only return
tasks with no category.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>OnDemandTask or None</em>– The task, or <strong>None</strong> if no task was found.</p>
<codeclass="sig-name descname">get_dt</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">key</span></em>, <emclass="sig-param"><spanclass="n">category</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.get_dt"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.get_dt"title="Permalink to this definition">¶</a></dt>
<dd><p>Get the time-delta since the task started.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>key</strong> (<em>str</em><em>, </em><em>callable</em><em>, </em><aclass="reference internal"href="#evennia.scripts.ondemandhandler.OnDemandTask"title="evennia.scripts.ondemandhandler.OnDemandTask"><em>OnDemandTask</em></a><em> or </em><em>Object</em>) – The unique identifier for the task. If a
callable, will be called without arguments. If an Object, will be converted to a string.
If an <strong>OnDemandTask</strong>, then all other arguments are ignored and the task will be used
to identify the task to get the time-delta from.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>int or None</em>– The time since the last check, or <strong>None</strong> if no task was found.</p>
<codeclass="sig-name descname">set_dt</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">key</span></em>, <emclass="sig-param"><spanclass="n">category</span></em>, <emclass="sig-param"><spanclass="n">dt</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.set_dt"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.set_dt"title="Permalink to this definition">¶</a></dt>
<dd><p>Set the time-delta since the task started manually. This allows you to ‘cheat’ the system
and set the time manually. This is useful for testing or when a system manipulates the state
somehow (like using a potion that speeds up the growth of a plant).</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>key</strong> (<em>str</em><em>, </em><em>callable</em><em>, </em><aclass="reference internal"href="#evennia.scripts.ondemandhandler.OnDemandTask"title="evennia.scripts.ondemandhandler.OnDemandTask"><em>OnDemandTask</em></a><em> or </em><em>Object</em>) – The unique identifier for the task. If a
callable, will be called without arguments. If an Object, will be converted to a string.
If an <strong>OnDemandTask</strong>, then all other arguments are ignored and the task will be used
to identify the task to set the time-delta for.</p></li>
<li><p><strong>category</strong> (<em>str</em><em>, </em><em>optional</em>) – The category of the task.</p></li>
<li><p><strong>dt</strong> (<em>int</em>) – The time-delta to set. This is an absolute value in seconds, same as returned
by <strong>get_dt</strong>.</p></li>
</ul>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Setting this will not on its own trigger any stage functions - this will only happen
as normal, next time the state is checked and the stage is found to have changed.</p>
<codeclass="sig-name descname">get_stage</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">key</span></em>, <emclass="sig-param"><spanclass="n">category</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.get_stage"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.get_stage"title="Permalink to this definition">¶</a></dt>
<dd><p>Get the current stage of an on-demand task.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>key</strong> (<em>str</em><em>, </em><em>callable</em><em>, </em><aclass="reference internal"href="#evennia.scripts.ondemandhandler.OnDemandTask"title="evennia.scripts.ondemandhandler.OnDemandTask"><em>OnDemandTask</em></a><em> or </em><em>Object</em>) – The unique identifier for the task. If a
callable, will be called without arguments. If an Object, will be converted to a string.
If an <strong>OnDemandTask</strong>, then all other arguments are ignored and the task will be used
to identify the task to get the stage from.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>str or None</em>– The current stage of the task, or <strong>None</strong> if no task was found.</p>
<codeclass="sig-name descname">set_stage</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">key</span></em>, <emclass="sig-param"><spanclass="n">category</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">stage</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/ondemandhandler.html#OnDemandHandler.set_stage"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.ondemandhandler.OnDemandHandler.set_stage"title="Permalink to this definition">¶</a></dt>
<dd><p>Set the stage of an on-demand task manually. This allows you to ‘cheat’ the system and set
the stage manually. This is useful for testing or when a system manipulates the state
somehow (like using a potion that speeds up the growth of a plant). The given stage must
be previously created for the given task. If task has no stages, this will do nothing.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>key</strong> (<em>str</em><em>, </em><em>callable</em><em>, </em><aclass="reference internal"href="#evennia.scripts.ondemandhandler.OnDemandTask"title="evennia.scripts.ondemandhandler.OnDemandTask"><em>OnDemandTask</em></a><em> or </em><em>Object</em>) – The unique identifier for the task. If a
callable, will be called without arguments. If an Object, will be converted to a
string. If an <strong>OnDemandTask</strong>, then all other arguments are ignored and the task
will be used to identify the task to set the stage for.</p></li>
<li><p><strong>category</strong> (<em>str</em><em>, </em><em>optional</em>) – The category of the task.</p></li>
<li><p><strong>stage</strong> (<em>str</em><em>, </em><em>optional</em>) – The stage to set. If <strong>None</strong>, the task will be reset to its
initial (first) state.</p></li>
</ul>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Setting this will not on its own trigger any stage functions - this will only happen
as normal, next time the state is checked and the stage is found to have changed.</p>