mirror of
https://github.com/evennia/evennia.git
synced 2026-03-30 20:47:17 +02:00
Updated HTML docs.
This commit is contained in:
parent
370a11cf2f
commit
88477386fe
64 changed files with 2209 additions and 2458 deletions
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Command Duration — Evennia 1.0-dev documentation</title>
|
||||
<title>Commands that take time to finish — Evennia 1.0-dev documentation</title>
|
||||
<link rel="stylesheet" href="../_static/nature.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
||||
|
|
@ -17,8 +17,8 @@
|
|||
<link rel="shortcut icon" href="../_static/favicon.ico"/>
|
||||
<link rel="index" title="Index" href="../genindex.html" />
|
||||
<link rel="search" title="Search" href="../search.html" />
|
||||
<link rel="next" title="Default Exit Errors" href="Howto-Default-Exit-Errors.html" />
|
||||
<link rel="prev" title="Command Cooldown" href="Howto-Command-Cooldown.html" />
|
||||
<link rel="next" title="Return custom errors on missing Exits" href="Howto-Default-Exit-Errors.html" />
|
||||
<link rel="prev" title="Adding Command Cooldowns" href="Howto-Command-Cooldown.html" />
|
||||
</head><body>
|
||||
<div class="related" role="navigation" aria-label="related navigation">
|
||||
<h3>Navigation</h3>
|
||||
|
|
@ -30,14 +30,14 @@
|
|||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="Howto-Default-Exit-Errors.html" title="Default Exit Errors"
|
||||
<a href="Howto-Default-Exit-Errors.html" title="Return custom errors on missing Exits"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="Howto-Command-Cooldown.html" title="Command Cooldown"
|
||||
<a href="Howto-Command-Cooldown.html" title="Adding Command Cooldowns"
|
||||
accesskey="P">previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 1.0-dev</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="Howtos-Overview.html" accesskey="U">Tutorials and Howto’s</a> »</li>
|
||||
<li class="nav-item nav-item-this"><a href="">Command Duration</a></li>
|
||||
<li class="nav-item nav-item-this"><a href="">Commands that take time to finish</a></li>
|
||||
</ul>
|
||||
<div class="develop">develop branch</div>
|
||||
</div>
|
||||
|
|
@ -62,25 +62,21 @@
|
|||
<script>$('#searchbox').show(0);</script>
|
||||
<h3><a href="../index.html">Table of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">Command Duration</a><ul>
|
||||
<li><a class="reference internal" href="#the-simple-way-to-pause-commands-with-yield">The simple way to pause commands with yield</a></li>
|
||||
<li><a class="reference internal" href="#the-more-advanced-way-with-utils-delay">The more advanced way with utils.delay</a><ul>
|
||||
<li><a class="reference internal" href="#about-utils-delay">About utils.delay()</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference internal" href="#blocking-commands">Blocking commands</a></li>
|
||||
<li><a class="reference internal" href="#abortable-commands">Abortable commands</a></li>
|
||||
<li><a class="reference internal" href="#persistent-delays">Persistent delays</a></li>
|
||||
<li><a class="reference internal" href="#">Commands that take time to finish</a><ul>
|
||||
<li><a class="reference internal" href="#pause-commands-with-yield">Pause commands with <code class="docutils literal notranslate"><span class="pre">yield</span></code></a></li>
|
||||
<li><a class="reference internal" href="#pause-commands-with-utils-delay">Pause commands with <code class="docutils literal notranslate"><span class="pre">utils.delay</span></code></a></li>
|
||||
<li><a class="reference internal" href="#making-a-blocking-command">Making a blocking command</a></li>
|
||||
<li><a class="reference internal" href="#make-a-command-possible-to-abort">Make a Command possible to Abort</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="Howto-Command-Cooldown.html"
|
||||
title="previous chapter">Command Cooldown</a></p>
|
||||
title="previous chapter">Adding Command Cooldowns</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="Howto-Default-Exit-Errors.html"
|
||||
title="next chapter">Default Exit Errors</a></p>
|
||||
title="next chapter">Return custom errors on missing Exits</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<!--h3>This Page</h3-->
|
||||
<ul class="this-page-menu">
|
||||
|
|
@ -111,23 +107,52 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<section class="tex2jax_ignore mathjax_ignore" id="command-duration">
|
||||
<h1>Command Duration<a class="headerlink" href="#command-duration" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Before reading this tutorial, if you haven’t done so already, you might want to
|
||||
read <a class="reference internal" href="../Components/Commands.html"><span class="doc std std-doc">the documentation on commands</span></a> to get a basic understanding of
|
||||
how commands work in Evennia.</p>
|
||||
<p>In some types of games a command should not start and finish immediately.
|
||||
Loading a crossbow might take a bit of time to do - time you don’t have when
|
||||
<section class="tex2jax_ignore mathjax_ignore" id="commands-that-take-time-to-finish">
|
||||
<h1>Commands that take time to finish<a class="headerlink" href="#commands-that-take-time-to-finish" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>> craft fine sword
|
||||
You start crafting a fine sword.
|
||||
> north
|
||||
You are too focused on your crafting, and can't move!
|
||||
You create the blade of the sword.
|
||||
You create the pommel of the sword.
|
||||
You finish crafting a Fine Sword.
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>In some types of games a command should not start and finish immediately.</p>
|
||||
<p>Loading a crossbow might take a bit of time to do - time you don’t have when
|
||||
the enemy comes rushing at you. Crafting that armour will not be immediate
|
||||
either. For some types of games the very act of moving or changing pose all
|
||||
comes with a certain time associated with it.</p>
|
||||
<section id="the-simple-way-to-pause-commands-with-yield">
|
||||
<h2>The simple way to pause commands with yield<a class="headerlink" href="#the-simple-way-to-pause-commands-with-yield" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Evennia allows a shortcut in syntax to create simple pauses in commands. This
|
||||
syntax uses the <code class="docutils literal notranslate"><span class="pre">yield</span></code> keyword. The <code class="docutils literal notranslate"><span class="pre">yield</span></code> keyword is used in Python to
|
||||
create generators, although you don’t need to know what generators are to use
|
||||
this syntax. A short example will probably make it clear:</p>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CmdTest</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<p>There are two main suitable ways to introduce a ‘delay’ in a <a class="reference internal" href="../Components/Commands.html"><span class="doc std std-doc">Command</span></a>’s execution:</p>
|
||||
<ul class="simple">
|
||||
<li><p>Using <code class="docutils literal notranslate"><span class="pre">yield</span></code> in the Command’s <code class="docutils literal notranslate"><span class="pre">func</span></code> method.</p></li>
|
||||
<li><p>Using the <code class="docutils literal notranslate"><span class="pre">evennia.utils.delay</span></code> utility function.</p></li>
|
||||
</ul>
|
||||
<p>We’ll simplify both below.</p>
|
||||
<section id="pause-commands-with-yield">
|
||||
<h2>Pause commands with <code class="docutils literal notranslate"><span class="pre">yield</span></code><a class="headerlink" href="#pause-commands-with-yield" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">yield</span></code> keyword is a reserved word in Python. It’s used to create <a class="reference external" href="https://realpython.com/introduction-to-python-generators/">generators</a>, which are interesting in their own right. For the purpose of this howto though, we just need to know that Evennia will use it to ‘pause’ the execution of the command for a certain time.</p>
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">This only works in Command.func!</p>
|
||||
<p>This <code class="docutils literal notranslate"><span class="pre">yield</span></code> functionality will <em>only</em> work in the <code class="docutils literal notranslate"><span class="pre">func</span></code> method of
|
||||
Commands. It works because Evennia has especially catered for it as a convenient shortcut. Trying to use it elsewhere will not work. If you want the same functionality elsewhere you should look up the <a class="reference internal" href="../Concepts/Async-Process.html#the-interactive-decorator"><span class="std std-doc">interactive decorator</span></a>.</p>
|
||||
</aside>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
|
||||
<span class="normal"> 2</span>
|
||||
<span class="normal"> 3</span>
|
||||
<span class="normal"> 4</span>
|
||||
<span class="normal"> 5</span>
|
||||
<span class="normal"> 6</span>
|
||||
<span class="normal"> 7</span>
|
||||
<span class="normal"> 8</span>
|
||||
<span class="normal"> 9</span>
|
||||
<span class="normal">10</span>
|
||||
<span class="normal">11</span>
|
||||
<span class="normal">12</span>
|
||||
<span class="normal">13</span>
|
||||
<span class="normal">14</span>
|
||||
<span class="normal">15</span>
|
||||
<span class="normal">16</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">class</span> <span class="nc">CmdTest</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> A test command just to test waiting.</span>
|
||||
|
|
@ -138,51 +163,81 @@ this syntax. A short example will probably make it clear:</p>
|
|||
<span class="sd"> """</span>
|
||||
|
||||
<span class="n">key</span> <span class="o">=</span> <span class="s2">"test"</span>
|
||||
<span class="n">locks</span> <span class="o">=</span> <span class="s2">"cmd:all()"</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"Before ten seconds..."</span><span class="p">)</span>
|
||||
<span class="k">yield</span> <span class="mi">10</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"Afterwards."</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
<span class="hll"> <span class="k">yield</span> <span class="mi">10</span>
|
||||
</span> <span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"Afterwards."</span><span class="p">)</span>
|
||||
</pre></div></td></tr></table></div>
|
||||
</div>
|
||||
<blockquote>
|
||||
<div><p>Important: The <code class="docutils literal notranslate"><span class="pre">yield</span></code> functionality will <em>only</em> work in the <code class="docutils literal notranslate"><span class="pre">func</span></code> method of
|
||||
Commands. It only works because Evennia has especially
|
||||
catered for it in Commands. If you want the same functionality elsewhere you
|
||||
must use the <a class="reference internal" href="../Concepts/Async-Process.html#the-interactive-decorator"><span class="std std-doc">interactive decorator</span></a>.</p>
|
||||
</div></blockquote>
|
||||
<p>The important line is the <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">10</span></code>. It tells Evennia to “pause” the command
|
||||
<ul class="simple">
|
||||
<li><p><strong>Line 15</strong> : This is the important line. The <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">10</span></code> tells Evennia to “pause” the command
|
||||
and to wait for 10 seconds to execute the rest. If you add this command and
|
||||
run it, you’ll see the first message, then, after a pause of ten seconds, the
|
||||
next message. You can use <code class="docutils literal notranslate"><span class="pre">yield</span></code> several times in your command.</p>
|
||||
<p>This syntax will not “freeze” all commands. While the command is “pausing”,
|
||||
you can execute other commands (or even call the same command again). And
|
||||
other players aren’t frozen either.</p>
|
||||
next message. You can use <code class="docutils literal notranslate"><span class="pre">yield</span></code> several times in your command.</p></li>
|
||||
</ul>
|
||||
<p>This syntax will not “freeze” all commands. While the command is “pausing”, you can execute other commands (or even call the same command again). And other players aren’t frozen either.</p>
|
||||
<blockquote>
|
||||
<div><p>Note: this will not save anything in the database. If you reload the game
|
||||
while a command is “paused”, it will not resume after the server has
|
||||
reloaded.</p>
|
||||
<div><p>Using <code class="docutils literal notranslate"><span class="pre">yield</span></code> is non-persistent. If you <code class="docutils literal notranslate"><span class="pre">reload</span></code> the game while a command is “paused”, that pause state is lost and it will <em>not</em> resume after the server has reloaded.</p>
|
||||
</div></blockquote>
|
||||
</section>
|
||||
<section id="the-more-advanced-way-with-utils-delay">
|
||||
<h2>The more advanced way with utils.delay<a class="headerlink" href="#the-more-advanced-way-with-utils-delay" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">yield</span></code> syntax is easy to read, easy to understand, easy to use. But it’s not that flexible if
|
||||
you want more advanced options. Learning to use alternatives might be much worth it in the end.</p>
|
||||
<p>Below is a simple command example for adding a duration for a command to finish.</p>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span><span class="p">,</span> <span class="n">utils</span>
|
||||
<section id="pause-commands-with-utils-delay">
|
||||
<h2>Pause commands with <code class="docutils literal notranslate"><span class="pre">utils.delay</span></code><a class="headerlink" href="#pause-commands-with-utils-delay" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">yield</span></code> syntax is easy to read, easy to understand, easy to use. But it’s non-persistent and not that flexible if you want more advanced options.</p>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">evennia.utils.delay</span></code> represents is a more powerful way to introduce delays. Unlike <code class="docutils literal notranslate"><span class="pre">yield</span></code>, it<br />
|
||||
can be made persistent and also works outside of <code class="docutils literal notranslate"><span class="pre">Command.func</span></code>. It’s however a little more cumbersome to write since unlike <code class="docutils literal notranslate"><span class="pre">yield</span></code> it will not actually stop at the line it’s called.</p>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
|
||||
<span class="normal"> 2</span>
|
||||
<span class="normal"> 3</span>
|
||||
<span class="normal"> 4</span>
|
||||
<span class="normal"> 5</span>
|
||||
<span class="normal"> 6</span>
|
||||
<span class="normal"> 7</span>
|
||||
<span class="normal"> 8</span>
|
||||
<span class="normal"> 9</span>
|
||||
<span class="normal">10</span>
|
||||
<span class="normal">11</span>
|
||||
<span class="normal">12</span>
|
||||
<span class="normal">13</span>
|
||||
<span class="normal">14</span>
|
||||
<span class="normal">15</span>
|
||||
<span class="normal">16</span>
|
||||
<span class="normal">17</span>
|
||||
<span class="normal">18</span>
|
||||
<span class="normal">19</span>
|
||||
<span class="normal">20</span>
|
||||
<span class="normal">21</span>
|
||||
<span class="normal">22</span>
|
||||
<span class="normal">23</span>
|
||||
<span class="normal">24</span>
|
||||
<span class="normal">25</span>
|
||||
<span class="normal">26</span>
|
||||
<span class="normal">27</span>
|
||||
<span class="normal">28</span>
|
||||
<span class="normal">29</span>
|
||||
<span class="normal">30</span>
|
||||
<span class="normal">31</span></pre></div></td><td class="code"><div><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span><span class="p">,</span> <span class="n">utils</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdEcho</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">MuxCommand</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> wait for an echo</span>
|
||||
<span class="sd"> Wait for an echo</span>
|
||||
<span class="sd"> </span>
|
||||
<span class="sd"> Usage: </span>
|
||||
<span class="sd"> echo <string></span>
|
||||
<span class="sd"> </span>
|
||||
<span class="sd"> Calls and waits for an echo</span>
|
||||
<span class="sd"> Calls and waits for an echo.</span>
|
||||
<span class="sd"> """</span>
|
||||
<span class="n">key</span> <span class="o">=</span> <span class="s2">"echo"</span>
|
||||
<span class="n">locks</span> <span class="o">=</span> <span class="s2">"cmd:all()"</span>
|
||||
|
||||
<span class="hll"> <span class="k">def</span> <span class="nf">echo</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
</span> <span class="s2">"Called after 10 seconds."</span>
|
||||
<span class="n">shout</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span>
|
||||
<span class="s2">"You hear an echo: "</span>
|
||||
<span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">shout</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span><span class="si">}</span><span class="s2"> ... "</span>
|
||||
<span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">shout</span><span class="o">.</span><span class="n">capitalize</span><span class="p">()</span><span class="si">}</span><span class="s2"> ... "</span>
|
||||
<span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">shout</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="si">}</span><span class="s2">"</span>
|
||||
<span class="p">)</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -190,50 +245,67 @@ you want more advanced options. Learning to use alternatives might be much wort
|
|||
<span class="sd"> """</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">"You shout '</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="si">}</span><span class="s2">' and wait for an echo ..."</span><span class="p">)</span>
|
||||
<span class="c1"># this waits non-blocking for 10 seconds, then calls self.echo</span>
|
||||
<span class="n">utils</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">echo</span><span class="p">)</span> <span class="c1"># call echo after 10 seconds</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">echo</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="s2">"Called after 10 seconds."</span>
|
||||
<span class="n">shout</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span>
|
||||
<span class="sa">f</span><span class="s2">"You hear an echo: </span><span class="si">{</span><span class="n">shout</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span><span class="si">}</span><span class="s2"> ... </span><span class="si">{</span><span class="n">shout</span><span class="o">.</span><span class="n">capitalize</span><span class="p">()</span><span class="si">}</span><span class="s2"> ... </span><span class="si">{</span><span class="n">shout</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="si">}</span><span class="s2">"</span>
|
||||
<span class="p">)</span>
|
||||
<span class="hll"> <span class="n">utils</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">echo</span><span class="p">)</span> <span class="c1"># call echo after 10 seconds</span>
|
||||
</span>
|
||||
</pre></div></td></tr></table></div>
|
||||
</div>
|
||||
<p>Import this new echo command into the default command set and reload the server. You will find that it will take 10 seconds before you see your shout coming back.</p>
|
||||
<ul class="simple">
|
||||
<li><p><strong>Line 14</strong>: We add a new method <code class="docutils literal notranslate"><span class="pre">echo</span></code>. This is a <em>callback</em> - a method/function we will call after a certain time.</p></li>
|
||||
<li><p><strong>Line 30</strong>: Here we use <code class="docutils literal notranslate"><span class="pre">utils.delay</span></code> to tell Evennia “Please wait for 10 seconds, then call “<code class="docutils literal notranslate"><span class="pre">self.echo</span></code>”. Note how we pass <code class="docutils literal notranslate"><span class="pre">self.echo</span></code> and <em>not</em> <code class="docutils literal notranslate"><span class="pre">self.echo()</span></code>! If we did the latter, <code class="docutils literal notranslate"><span class="pre">echo</span></code> would fire <em>immediately</em>. Instead we let Evennia do this call for us ten seconds later.</p></li>
|
||||
</ul>
|
||||
<p>You will also find that this is a <em>non-blocking</em> effect; you can issue other commands in the interim and the game will go on as usual. The echo will come back to you in its own time.</p>
|
||||
<p>The call signature for <code class="docutils literal notranslate"><span class="pre">utils.delay</span></code> is:</p>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">utils</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="n">timedelay</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">persistent</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Import this new echo command into the default command set and reload the server. You will find that
|
||||
it will take 10 seconds before you see your shout coming back. You will also find that this is a
|
||||
<em>non-blocking</em> effect; you can issue other commands in the interim and the game will go on as usual.
|
||||
The echo will come back to you in its own time.</p>
|
||||
<section id="about-utils-delay">
|
||||
<h3>About utils.delay()<a class="headerlink" href="#about-utils-delay" title="Permalink to this headline">¶</a></h3>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">utils.delay(timedelay,</span> <span class="pre">callback,</span> <span class="pre">persistent=False,</span> <span class="pre">*args,</span> <span class="pre">**kwargs)</span></code> is a useful function. It will
|
||||
wait <code class="docutils literal notranslate"><span class="pre">timedelay</span></code> seconds, then call the <code class="docutils literal notranslate"><span class="pre">callback</span></code> function, optionally passing to it the arguments
|
||||
provided to utils.delay by way of *args and/or **kwargs`.</p>
|
||||
<blockquote>
|
||||
<div><p>Note: The callback argument should be provided with a python path to the desired function, for
|
||||
instance <code class="docutils literal notranslate"><span class="pre">my_object.my_function</span></code> instead of <code class="docutils literal notranslate"><span class="pre">my_object.my_function()</span></code>. Otherwise my_function would
|
||||
get called and run immediately upon attempting to pass it to the delay function.
|
||||
If you want to provide arguments for utils.delay to use, when calling your callback function, you
|
||||
have to do it separatly, for instance using the utils.delay *args and/or **kwargs, as mentioned
|
||||
above.</p>
|
||||
</div></blockquote>
|
||||
<blockquote>
|
||||
<div><p>If you are not familiar with the syntax <code class="docutils literal notranslate"><span class="pre">*args</span></code> and <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code>, <a class="reference external" href="https://docs.python.org/2/tutorial/controlflow.html#arbitrary-argument-lists">see the Python documentation
|
||||
here</a>.</p>
|
||||
</div></blockquote>
|
||||
<p>Looking at it you might think that <code class="docutils literal notranslate"><span class="pre">utils.delay(10,</span> <span class="pre">callback)</span></code> in the code above is just an
|
||||
alternative to some more familiar thing like <code class="docutils literal notranslate"><span class="pre">time.sleep(10)</span></code>. This is <em>not</em> the case. If you do
|
||||
<code class="docutils literal notranslate"><span class="pre">time.sleep(10)</span></code> you will in fact freeze the <em>entire server</em> for ten seconds! The <code class="docutils literal notranslate"><span class="pre">utils.delay()</span></code>is
|
||||
a thin wrapper around a Twisted
|
||||
<a class="reference external" href="https://twistedmatrix.com/documents/11.0.0/core/howto/defer.html">Deferred</a> that will delay
|
||||
execution until 10 seconds have passed, but will do so asynchronously, without bothering anyone else
|
||||
(not even you - you can continue to do stuff normally while it waits to continue).</p>
|
||||
<p>The point to remember here is that the <code class="docutils literal notranslate"><span class="pre">delay()</span></code> call will not “pause” at that point when it is
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">*args and **kwargs </p>
|
||||
<p>These are used to indicate any number of arguments or keyword-arguments should be picked up here. In code they are treated as a <code class="docutils literal notranslate"><span class="pre">tuple</span></code> and a <code class="docutils literal notranslate"><span class="pre">dict</span></code> respectively.</p>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">*args</span></code> and <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> are used in many places in Evennia. <a class="reference external" href="https://realpython.com/python-kwargs-and-args">See an online tutorial here</a>.</p>
|
||||
</aside>
|
||||
<p>If you set <code class="docutils literal notranslate"><span class="pre">persistent=True</span></code>, this delay will survive a <code class="docutils literal notranslate"><span class="pre">reload</span></code>. If you pass <code class="docutils literal notranslate"><span class="pre">*args</span></code> and/or <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code>, they will be passed on into the <code class="docutils literal notranslate"><span class="pre">callback</span></code>. So this way you can pass more complex arguments to the delayed function.</p>
|
||||
<p>It’s important to remember that the <code class="docutils literal notranslate"><span class="pre">delay()</span></code> call will not “pause” at that point when it is
|
||||
called (the way <code class="docutils literal notranslate"><span class="pre">yield</span></code> does in the previous section). The lines after the <code class="docutils literal notranslate"><span class="pre">delay()</span></code> call will
|
||||
actually execute <em>right away</em>. What you must do is to tell it which function to call <em>after the time
|
||||
has passed</em> (its “callback”). This may sound strange at first, but it is normal practice in
|
||||
asynchronous systems. You can also link such calls together as seen below:</p>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span><span class="p">,</span> <span class="n">utils</span>
|
||||
asynchronous systems. You can also link such calls together:</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
|
||||
<span class="normal"> 2</span>
|
||||
<span class="normal"> 3</span>
|
||||
<span class="normal"> 4</span>
|
||||
<span class="normal"> 5</span>
|
||||
<span class="normal"> 6</span>
|
||||
<span class="normal"> 7</span>
|
||||
<span class="normal"> 8</span>
|
||||
<span class="normal"> 9</span>
|
||||
<span class="normal">10</span>
|
||||
<span class="normal">11</span>
|
||||
<span class="normal">12</span>
|
||||
<span class="normal">13</span>
|
||||
<span class="normal">14</span>
|
||||
<span class="normal">15</span>
|
||||
<span class="normal">16</span>
|
||||
<span class="normal">17</span>
|
||||
<span class="normal">18</span>
|
||||
<span class="normal">19</span>
|
||||
<span class="normal">20</span>
|
||||
<span class="normal">21</span>
|
||||
<span class="normal">22</span>
|
||||
<span class="normal">23</span>
|
||||
<span class="normal">24</span>
|
||||
<span class="normal">25</span>
|
||||
<span class="normal">26</span>
|
||||
<span class="normal">27</span>
|
||||
<span class="normal">28</span>
|
||||
<span class="normal">29</span>
|
||||
<span class="normal">30</span>
|
||||
<span class="normal">31</span>
|
||||
<span class="normal">32</span>
|
||||
<span class="normal">33</span>
|
||||
<span class="normal">34</span>
|
||||
<span class="normal">35</span>
|
||||
<span class="normal">36</span></pre></div></td><td class="code"><div><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span><span class="p">,</span> <span class="n">utils</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdEcho</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">MuxCommand</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -245,56 +317,61 @@ asynchronous systems. You can also link such calls together as seen below:</p>
|
|||
<span class="sd"> Calls and waits for an echo</span>
|
||||
<span class="sd"> """</span>
|
||||
<span class="n">key</span> <span class="o">=</span> <span class="s2">"echo"</span>
|
||||
<span class="n">locks</span> <span class="o">=</span> <span class="s2">"cmd:all()"</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="s2">"This sets off a chain of delayed calls"</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">"You shout '</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="si">}</span><span class="s2">', waiting for an echo ..."</span><span class="p">)</span>
|
||||
|
||||
<span class="c1"># wait 2 seconds before calling self.echo1</span>
|
||||
<span class="n">utils</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">echo1</span><span class="p">)</span>
|
||||
|
||||
<span class="hll"> <span class="n">utils</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">echo1</span><span class="p">)</span>
|
||||
</span>
|
||||
<span class="c1"># callback chain, started above</span>
|
||||
<span class="k">def</span> <span class="nf">echo1</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="s2">"First echo"</span>
|
||||
<span class="hll"> <span class="k">def</span> <span class="nf">echo1</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
</span> <span class="s2">"First echo"</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">"... </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
|
||||
<span class="c1"># wait 2 seconds for the next one</span>
|
||||
<span class="n">utils</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">echo2</span><span class="p">)</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">echo2</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="s2">"Second echo"</span>
|
||||
<span class="hll"> <span class="k">def</span> <span class="nf">echo2</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
</span> <span class="s2">"Second echo"</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">"... </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">capitalize</span><span class="p">()</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
|
||||
<span class="c1"># wait another 2 seconds</span>
|
||||
<span class="n">utils</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">echo3</span><span class="p">)</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">echo3</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="s2">"Last echo"</span>
|
||||
<span class="hll"> <span class="k">def</span> <span class="nf">echo3</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
</span> <span class="s2">"Last echo"</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">"... </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="si">}</span><span class="s2"> ..."</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</pre></div></td></tr></table></div>
|
||||
</div>
|
||||
<p>The above version will have the echoes arrive one after another, each separated by a two second
|
||||
delay.</p>
|
||||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>> echo Hello!
|
||||
<ul class="simple">
|
||||
<li><p><strong>Line 19</strong>: This sets off the chain, telling Evennia to wait 2 seconds before calling <code class="docutils literal notranslate"><span class="pre">self.echo1</span></code>.</p></li>
|
||||
<li><p><strong>Line 22</strong>: This is called after 2 seconds. It tells Evennia to wait another 2 seconds before calling <code class="docutils literal notranslate"><span class="pre">self.echo2</span></code>.</p></li>
|
||||
<li><p><strong>Line 28</strong>: This is called after yet another 2 seonds (4s total). It tells Evennia to wait another 2 seconds before calling, <code class="docutils literal notranslate"><span class="pre">self.echo3</span></code>.</p></li>
|
||||
<li><p><strong>Line34</strong> Called after another 2 seconds (6s total). This ends the delay-chain.</p></li>
|
||||
</ul>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>> echo Hello!
|
||||
... HELLO!
|
||||
... Hello!
|
||||
... hello! ...
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="admonition warning">
|
||||
<p class="admonition-title">Warning</p>
|
||||
<p>What about time.sleep?</p>
|
||||
<p>You may be aware of the <code class="docutils literal notranslate"><span class="pre">time.sleep</span></code> function coming with Python. Doing `time.sleep(10) pauses Python for 10 seconds. <strong>Do not use this</strong>, it will not work with Evennia. If you use it, you will block the <em>entire server</em> (everyone!) for ten seconds!</p>
|
||||
<p>If you want specifics, <code class="docutils literal notranslate"><span class="pre">utils.delay</span></code> is a thin wrapper around a <a class="reference external" href="https://docs.twisted.org/en/twisted-22.1.0/core/howto/defer.html">Twisted Deferred</a>. This is an <a class="reference internal" href="../Concepts/Async-Process.html"><span class="doc std std-doc">asynchronous concept</span></a>.</p>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
<section id="blocking-commands">
|
||||
<h2>Blocking commands<a class="headerlink" href="#blocking-commands" title="Permalink to this headline">¶</a></h2>
|
||||
<p>As mentioned, a great thing about the delay introduced by <code class="docutils literal notranslate"><span class="pre">yield</span></code> or <code class="docutils literal notranslate"><span class="pre">utils.delay()</span></code> is that it does
|
||||
not block. It just goes on in the background and you are free to play normally in the interim. In
|
||||
some cases this is not what you want however. Some commands should simply “block” other commands
|
||||
while they are running. If you are in the process of crafting a helmet you shouldn’t be able to also
|
||||
start crafting a shield at the same time, or if you just did a huge power-swing with your weapon you
|
||||
should not be able to do it again immediately.</p>
|
||||
<p>The simplest way of implementing blocking is to use the technique covered in the <a class="reference internal" href="Howto-Command-Cooldown.html"><span class="doc std std-doc">Command Cooldown</span></a> tutorial. In that tutorial we implemented cooldowns by having the
|
||||
Command store the current time. Next time the Command was called, we compared the current time to
|
||||
the stored time to determine if enough time had passed for a renewed use. This is a <em>very</em>
|
||||
efficient, reliable and passive solution. The drawback is that there is nothing to tell the Player
|
||||
when enough time has passed unless they keep trying.</p>
|
||||
<section id="making-a-blocking-command">
|
||||
<h2>Making a blocking command<a class="headerlink" href="#making-a-blocking-command" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Both <code class="docutils literal notranslate"><span class="pre">yield</span></code> or <code class="docutils literal notranslate"><span class="pre">utils.delay()</span></code> pauses the command but allows the user to use other commands while the first one waits to finish.</p>
|
||||
<p>In some cases you want to instead have that command ‘block’ other commands from running. An example is crafting a helmet: most likely you should not be able to start crafting a shield at the same time. Or even walk out of the smithy.</p>
|
||||
<p>The simplest way of implementing blocking is to use the technique covered in the <a class="reference internal" href="Howto-Command-Cooldown.html"><span class="doc std std-doc">How to implement a Command Cooldown</span></a> tutorial. In that tutorial we cooldowns are implemented by comparing the current time with the last time the command was used. This is the best approach if you can get away with it. It could work well for our crafting example … <em>if</em> you don’t want to automatically update the player on their progress.</p>
|
||||
<p>In short:
|
||||
- If you are fine with the player making an active input to check their status, compare timestamps as done in the Command-cooldown tutorial. On-demand is by far the most efficent.
|
||||
- If you want Evennia to tell the user their status without them taking a further action, you need to use <code class="docutils literal notranslate"><span class="pre">yield</span></code> , <code class="docutils literal notranslate"><span class="pre">delay</span></code> (or some other active time-keeping method).</p>
|
||||
<p>Here is an example where we will use <code class="docutils literal notranslate"><span class="pre">utils.delay</span></code> to tell the player when the cooldown has passed:</p>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">utils</span><span class="p">,</span> <span class="n">default_cmds</span>
|
||||
|
||||
|
|
@ -338,12 +415,10 @@ when enough time has passed unless they keep trying.</p>
|
|||
<p>Note how, after the cooldown, the user will get a message telling them they are now ready for
|
||||
another swing.</p>
|
||||
<p>By storing the <code class="docutils literal notranslate"><span class="pre">off_balance</span></code> flag on the character (rather than on, say, the Command instance
|
||||
itself) it can be accessed by other Commands too. Other attacks may also not work when you are off
|
||||
balance. You could also have an enemy Command check your <code class="docutils literal notranslate"><span class="pre">off_balance</span></code> status to gain bonuses, to
|
||||
take another example.</p>
|
||||
itself) it can be accessed by other Commands too. Other attacks may also not work when you are off balance. You could also have an enemy Command check your <code class="docutils literal notranslate"><span class="pre">off_balance</span></code> status to gain bonuses, to take another example.</p>
|
||||
</section>
|
||||
<section id="abortable-commands">
|
||||
<h2>Abortable commands<a class="headerlink" href="#abortable-commands" title="Permalink to this headline">¶</a></h2>
|
||||
<section id="make-a-command-possible-to-abort">
|
||||
<h2>Make a Command possible to Abort<a class="headerlink" href="#make-a-command-possible-to-abort" title="Permalink to this headline">¶</a></h2>
|
||||
<p>One can imagine that you will want to abort a long-running command before it has a time to finish.
|
||||
If you are in the middle of crafting your armor you will probably want to stop doing that when a
|
||||
monster enters your smithy.</p>
|
||||
|
|
@ -443,60 +518,6 @@ Below is an example of a crafting command that can be aborted by starting a figh
|
|||
<code class="docutils literal notranslate"><span class="pre">attack</span></code> command is issued during this process it will set a flag that causes the crafting to be
|
||||
quietly canceled next time it tries to update.</p>
|
||||
</section>
|
||||
<section id="persistent-delays">
|
||||
<h2>Persistent delays<a class="headerlink" href="#persistent-delays" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In the latter examples above we used <code class="docutils literal notranslate"><span class="pre">.ndb</span></code> storage. This is fast and easy but it will reset all
|
||||
cooldowns/blocks/crafting etc if you reload the server. If you don’t want that you can replace
|
||||
<code class="docutils literal notranslate"><span class="pre">.ndb</span></code> with <code class="docutils literal notranslate"><span class="pre">.db</span></code>. But even this won’t help because the <code class="docutils literal notranslate"><span class="pre">yield</span></code> keyword is not persisent and nor is
|
||||
the use of <code class="docutils literal notranslate"><span class="pre">delay</span></code> shown above. To resolve this you can use <code class="docutils literal notranslate"><span class="pre">delay</span></code> with the <code class="docutils literal notranslate"><span class="pre">persistent=True</span></code>
|
||||
keyword. But wait! Making something persistent will add some extra complications, because now you
|
||||
must make sure Evennia can properly store things to the database.</p>
|
||||
<p>Here is the original echo-command reworked to function with persistence:</p>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span><span class="p">,</span> <span class="n">utils</span>
|
||||
|
||||
<span class="c1"># this is now in the outermost scope and takes two args! </span>
|
||||
<span class="k">def</span> <span class="nf">echo</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
|
||||
<span class="s2">"Called after 10 seconds."</span>
|
||||
<span class="n">shout</span> <span class="o">=</span> <span class="n">args</span>
|
||||
<span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span>
|
||||
<span class="sa">f</span><span class="s2">"You hear an echo: </span><span class="si">{</span><span class="n">shout</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span><span class="si">}</span><span class="s2"> ... </span><span class="si">{</span><span class="n">shout</span><span class="o">.</span><span class="n">capitalize</span><span class="p">()</span><span class="si">}</span><span class="s2"> ... </span><span class="si">{</span><span class="n">shout</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="si">}</span><span class="s2">"</span>
|
||||
<span class="p">)</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdEcho</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">MuxCommand</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> wait for an echo</span>
|
||||
<span class="sd"> </span>
|
||||
<span class="sd"> Usage: </span>
|
||||
<span class="sd"> echo <string></span>
|
||||
<span class="sd"> </span>
|
||||
<span class="sd"> Calls and waits for an echo</span>
|
||||
<span class="sd"> """</span>
|
||||
<span class="n">key</span> <span class="o">=</span> <span class="s2">"echo"</span>
|
||||
<span class="n">locks</span> <span class="o">=</span> <span class="s2">"cmd:all()"</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> This is called at the initial shout. </span>
|
||||
<span class="sd"> """</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">"You shout '</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="si">}</span><span class="s2">' and wait for an echo ..."</span><span class="p">)</span>
|
||||
<span class="c1"># this waits non-blocking for 10 seconds, then calls echo(self.caller, self.args)</span>
|
||||
<span class="n">utils</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="n">echo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">,</span> <span class="n">persistent</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="c1"># changes! </span>
|
||||
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Above you notice two changes:</p>
|
||||
<ul class="simple">
|
||||
<li><p>The callback (<code class="docutils literal notranslate"><span class="pre">echo</span></code>) was moved out of the class and became its own stand-alone function in the
|
||||
outermost scope of the module. It also now takes <code class="docutils literal notranslate"><span class="pre">caller</span></code> and <code class="docutils literal notranslate"><span class="pre">args</span></code> as arguments (it doesn’t have
|
||||
access to them directly since this is now a stand-alone function).</p></li>
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">utils.delay</span></code> specifies the <code class="docutils literal notranslate"><span class="pre">echo</span></code> function (not <code class="docutils literal notranslate"><span class="pre">self.echo</span></code> - it’s no longer a method!) and sends
|
||||
<code class="docutils literal notranslate"><span class="pre">self.caller</span></code> and <code class="docutils literal notranslate"><span class="pre">self.args</span></code> as arguments for it to use. We also set <code class="docutils literal notranslate"><span class="pre">persistent=True</span></code>.</p></li>
|
||||
</ul>
|
||||
<p>The reason for this change is because Evennia needs to <code class="docutils literal notranslate"><span class="pre">pickle</span></code> the callback into storage and it
|
||||
cannot do this correctly when the method sits on the command class. Now this behave the same as the
|
||||
first version except if you reload (or even shut down) the server mid-delay it will still fire the
|
||||
callback when the server comes back up (it will resume the countdown and ignore the downtime).</p>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
|
|
@ -515,14 +536,14 @@ callback when the server comes back up (it will resume the countdown and ignore
|
|||
<a href="../py-modindex.html" title="Python Module Index"
|
||||
>modules</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="Howto-Default-Exit-Errors.html" title="Default Exit Errors"
|
||||
<a href="Howto-Default-Exit-Errors.html" title="Return custom errors on missing Exits"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="Howto-Command-Cooldown.html" title="Command Cooldown"
|
||||
<a href="Howto-Command-Cooldown.html" title="Adding Command Cooldowns"
|
||||
>previous</a> |</li>
|
||||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 1.0-dev</a> »</li>
|
||||
<li class="nav-item nav-item-1"><a href="Howtos-Overview.html" >Tutorials and Howto’s</a> »</li>
|
||||
<li class="nav-item nav-item-this"><a href="">Command Duration</a></li>
|
||||
<li class="nav-item nav-item-this"><a href="">Commands that take time to finish</a></li>
|
||||
</ul>
|
||||
<div class="develop">develop branch</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue