mirror of
https://github.com/evennia/evennia.git
synced 2026-04-07 00:45:22 +02:00
Updated HTML docs
This commit is contained in:
parent
58f5ece91b
commit
1bbc93507a
1000 changed files with 39106 additions and 33861 deletions
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Add a wiki on your website — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="add-a-wiki-on-your-website">
|
||||
<section id="add-a-wiki-on-your-website">
|
||||
<h1>Add a wiki on your website<a class="headerlink" href="#add-a-wiki-on-your-website" title="Permalink to this headline">¶</a></h1>
|
||||
<p><strong>Before doing this tutorial you will probably want to read the intro in
|
||||
<a class="reference internal" href="Starting/Part5/Web-Tutorial.html"><span class="doc">Basic Web tutorial</span></a>.</strong> Reading the three first parts of the
|
||||
|
|
@ -55,7 +56,7 @@ has passed.)</p>
|
|||
wikis, is
|
||||
actively maintained (at this time, anyway), and isn’t too difficult to install in Evennia. You can
|
||||
see a <a class="reference external" href="https://demo.django.wiki">demonstration of Django-wiki here</a>.</p>
|
||||
<div class="section" id="basic-installation">
|
||||
<section id="basic-installation">
|
||||
<h2>Basic installation<a class="headerlink" href="#basic-installation" title="Permalink to this headline">¶</a></h2>
|
||||
<p>You should begin by shutting down the Evennia server if it is running. We will run migrations and
|
||||
alter the virtual environment just a bit. Open a terminal and activate your Python environment, the
|
||||
|
|
@ -72,7 +73,7 @@ one you use to run the <code class="docutils literal notranslate"><span class="p
|
|||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="section" id="installing-with-pip">
|
||||
<section id="installing-with-pip">
|
||||
<h3>Installing with pip<a class="headerlink" href="#installing-with-pip" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Install the wiki using pip:</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">pip</span> <span class="n">install</span> <span class="n">wiki</span>
|
||||
|
|
@ -83,56 +84,56 @@ one you use to run the <code class="docutils literal notranslate"><span class="p
|
|||
install wiki 0.3 if you haven’t updated to Python 3 yet.</p>
|
||||
</div></blockquote>
|
||||
<p>It might take some time, the Django-wiki having some dependencies.</p>
|
||||
</div>
|
||||
<div class="section" id="adding-the-wiki-in-the-settings">
|
||||
</section>
|
||||
<section id="adding-the-wiki-in-the-settings">
|
||||
<h3>Adding the wiki in the settings<a class="headerlink" href="#adding-the-wiki-in-the-settings" title="Permalink to this headline">¶</a></h3>
|
||||
<p>You will need to add a few settings to have the wiki app on your website. Open your
|
||||
<code class="docutils literal notranslate"><span class="pre">server/conf/settings.py</span></code> file and add the following at the bottom (but before importing
|
||||
<code class="docutils literal notranslate"><span class="pre">secret_settings</span></code>). Here’s what you’ll find in my own setting file (add the whole Django-wiki
|
||||
section):</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sa">r</span><span class="sd">"""</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sa">r</span><span class="sd">"""</span>
|
||||
<span class="sd">Evennia settings file.</span>
|
||||
|
||||
<span class="sd">...</span>
|
||||
|
|
@ -177,26 +178,26 @@ section):</p>
|
|||
<span class="nb">print</span><span class="p">(</span><span class="s2">"secret_settings.py file not found or failed to import."</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="adding-the-new-urls">
|
||||
</section>
|
||||
<section id="adding-the-new-urls">
|
||||
<h3>Adding the new URLs<a class="headerlink" href="#adding-the-new-urls" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Next we need to add two URLs in our <code class="docutils literal notranslate"><span class="pre">web/urls.py</span></code> file. Open it and compare the following output:
|
||||
you will need to add two URLs in <code class="docutils literal notranslate"><span class="pre">custom_patterns</span></code> and add one import line:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">url</span><span class="p">,</span> <span class="n">include</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">url</span><span class="p">,</span> <span class="n">include</span>
|
||||
<span class="kn">from</span> <span class="nn">django.urls</span> <span class="kn">import</span> <span class="n">path</span> <span class="c1"># NEW!</span>
|
||||
|
||||
<span class="c1"># default evenni a patterns</span>
|
||||
|
|
@ -215,8 +216,8 @@ you will need to add two URLs in <code class="docutils literal notranslate"><spa
|
|||
</td></tr></table></div>
|
||||
<p>You will probably need to copy line 2, 10, and 11. Be sure to place them correctly, as shown in
|
||||
the example above.</p>
|
||||
</div>
|
||||
<div class="section" id="running-migrations">
|
||||
</section>
|
||||
<section id="running-migrations">
|
||||
<h3>Running migrations<a class="headerlink" href="#running-migrations" title="Permalink to this headline">¶</a></h3>
|
||||
<p>It’s time to run the new migrations. The wiki app adds a few tables in our database. We’ll need to
|
||||
run:</p>
|
||||
|
|
@ -225,9 +226,9 @@ run:</p>
|
|||
</div>
|
||||
<p>And that’s it, you can start the server. If you go to http://localhost:4001/wiki , you should see
|
||||
the wiki. Use your account’s username and password to connect to it. That’s how simple it is.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="customizing-privileges">
|
||||
</section>
|
||||
</section>
|
||||
<section id="customizing-privileges">
|
||||
<h2>Customizing privileges<a class="headerlink" href="#customizing-privileges" title="Permalink to this headline">¶</a></h2>
|
||||
<p>A wiki can be a great collaborative tool, but who can see it? Who can modify it? Django-wiki comes
|
||||
with a privilege system centered around four values per wiki page. The owner of an article can
|
||||
|
|
@ -244,37 +245,37 @@ function as argument, said function (or callback) will be called with the articl
|
|||
Remember, a Django user, for us, is an account. So we could check lockstrings on them if needed.
|
||||
Here is a default setting to restrict the wiki: only builders can write in it, but anyone (including
|
||||
non-logged in users) can read it. The superuser has some additional privileges.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># In server/conf/settings.py</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span><span class="c1"># In server/conf/settings.py</span>
|
||||
<span class="c1"># ...</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">is_superuser</span><span class="p">(</span><span class="n">article</span><span class="p">,</span> <span class="n">user</span><span class="p">):</span>
|
||||
|
|
@ -316,7 +317,7 @@ adapting them to your need. This is just a demonstration.</p>
|
|||
<p>Providing the <code class="docutils literal notranslate"><span class="pre">WIKI_CAN*...</span></code> settings will bypass the original permission system. The superuser
|
||||
could change permissions of an article, but still, only builders would be able to write it. If you
|
||||
need something more custom, you will have to expand on the functions you use.</p>
|
||||
<div class="section" id="managing-wiki-pages-from-evennia">
|
||||
<section id="managing-wiki-pages-from-evennia">
|
||||
<h3>Managing wiki pages from Evennia<a class="headerlink" href="#managing-wiki-pages-from-evennia" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Unfortunately, Django wiki doesn’t provide a clear and clean entry point to read and write articles
|
||||
from Evennia and it doesn’t seem to be a very high priority. If you really need to keep Django wiki
|
||||
|
|
@ -347,9 +348,9 @@ contributing to this new project.</p></li>
|
|||
However, these features may be the most important and useful. Additional ones might not be that
|
||||
necessary. If you’re interested in supporting this little project, you are more than welcome to
|
||||
<a class="reference external" href="https://github.com/vincent-lg/evennia-wiki">contribute to it</a>. Thanks!</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Building a mech tutorial — 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" />
|
||||
|
|
@ -37,14 +38,14 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="building-a-mech-tutorial">
|
||||
<section id="building-a-mech-tutorial">
|
||||
<h1>Building a mech tutorial<a class="headerlink" href="#building-a-mech-tutorial" title="Permalink to this headline">¶</a></h1>
|
||||
<blockquote>
|
||||
<div><p>This page was adapted from the article “Building a Giant Mech in Evennia” by Griatch, published in
|
||||
Imaginary Realities Volume 6, issue 1, 2014. The original article is no longer available online,
|
||||
this is a version adopted to be compatible with the latest Evennia.</p>
|
||||
</div></blockquote>
|
||||
<div class="section" id="creating-the-mech">
|
||||
<section id="creating-the-mech">
|
||||
<h2>Creating the Mech<a class="headerlink" href="#creating-the-mech" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Let us create a functioning giant mech using the Python MUD-creation system Evennia. Everyone likes
|
||||
a giant mech, right? Start in-game as a character with build privileges (or the superuser).</p>
|
||||
|
|
@ -102,48 +103,48 @@ moment the mech is not quite as cool as it could be.</p>
|
|||
answer is that it came from the Account’s command set. This is important. Without the Account being
|
||||
the one with the <code class="docutils literal notranslate"><span class="pre">@ic</span></code> command, we would not have been able to get back out of our mech again.)</p>
|
||||
</div></blockquote>
|
||||
<div class="section" id="arming-the-mech">
|
||||
<section id="arming-the-mech">
|
||||
<h3>Arming the Mech<a class="headerlink" href="#arming-the-mech" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Let us make the mech a little more interesting. In our favorite text editor, we will create some new
|
||||
mech-suitable commands. In Evennia, commands are defined as Python classes.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a new file mygame/commands/mechcommands.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a new file mygame/commands/mechcommands.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
|
||||
|
|
@ -195,21 +196,21 @@ that up to you to create as an exercise. You could have it print “WOOSH! The
|
|||
mech launches missiles against <target>!”, for example.</p>
|
||||
<p>Now we shove our commands into a command set. A <a class="reference internal" href="../Components/Command-Sets.html"><span class="doc">Command Set</span></a> (CmdSet) is a container
|
||||
holding any number of commands. The command set is what we will store on the mech.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in the same file mygame/commands/mechcommands.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in the same file mygame/commands/mechcommands.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">CmdSet</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span>
|
||||
|
|
@ -251,9 +252,9 @@ mech, what else do you need?</p>
|
|||
<div><p>Note: You’ll find that the mech’s commands are available to you by just standing in the same
|
||||
location (not just by puppeting it). We’ll solve this with a <em>lock</em> in the next section.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="making-a-mech-production-line">
|
||||
</section>
|
||||
</section>
|
||||
<section id="making-a-mech-production-line">
|
||||
<h2>Making a Mech production line<a class="headerlink" href="#making-a-mech-production-line" title="Permalink to this headline">¶</a></h2>
|
||||
<p>What we’ve done so far is just to make a normal Object, describe it and put some commands on it.
|
||||
This is great for testing. The way we added it, the MechCmdSet will even go away if we reload the
|
||||
|
|
@ -261,22 +262,22 @@ server. Now we want to make the mech an actual object “type” so we can creat
|
|||
extra steps. For this we need to create a new Typeclass.</p>
|
||||
<p>A <a class="reference internal" href="../Components/Typeclasses.html"><span class="doc">Typeclass</span></a> is a near-normal Python class that stores its existence to the database
|
||||
behind the scenes. A Typeclass is created in a normal Python source file:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in the new file mygame/typeclasses/mech.py</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span><span class="c1"># in the new file mygame/typeclasses/mech.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">typeclasses.objects</span> <span class="kn">import</span> <span class="n">Object</span>
|
||||
<span class="kn">from</span> <span class="nn">commands.mechcommands</span> <span class="kn">import</span> <span class="n">MechCmdSet</span>
|
||||
|
|
@ -314,8 +315,8 @@ the <code class="docutils literal notranslate"><span class="pre">typeclasses</sp
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>to take it on a test drive.</p>
|
||||
</div>
|
||||
<div class="section" id="future-mechs">
|
||||
</section>
|
||||
<section id="future-mechs">
|
||||
<h2>Future Mechs<a class="headerlink" href="#future-mechs" title="Permalink to this headline">¶</a></h2>
|
||||
<p>To expand on this you could add more commands to the mech and remove others. Maybe the mech
|
||||
shouldn’t work just like a Character after all. Maybe it makes loud noises every time it passes from
|
||||
|
|
@ -328,8 +329,8 @@ Character (since any Object can move inside another). In that case the “inside
|
|||
could be the “cockpit”. The cockpit would have the <code class="docutils literal notranslate"><span class="pre">MechCommandSet</span></code> stored on itself and all the
|
||||
shooting goodness would be made available to you only when you enter it.</p>
|
||||
<p>And of course you could put more guns on it. And make it fly.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Coding FAQ — 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" />
|
||||
|
|
@ -37,12 +38,12 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="coding-faq">
|
||||
<section id="coding-faq">
|
||||
<h1>Coding FAQ<a class="headerlink" href="#coding-faq" title="Permalink to this headline">¶</a></h1>
|
||||
<p><em>This FAQ page is for users to share their solutions to coding problems. Keep it brief and link to
|
||||
the docs if you can rather than too lengthy explanations. Don’t forget to check if an answer already
|
||||
exists before answering - maybe you can clarify that answer rather than to make a new Q&A section.</em></p>
|
||||
<div class="section" id="table-of-contents">
|
||||
<section id="table-of-contents">
|
||||
<h2>Table of Contents<a class="headerlink" href="#table-of-contents" title="Permalink to this headline">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference external" href="Howto/Coding-FAQ.html#removing-default-commands">Removing default commands</a></p></li>
|
||||
|
|
@ -60,8 +61,8 @@ reloading)</p></li>
|
|||
<li><p><a class="reference external" href="Howto/Coding-FAQ.html#store-last-used-session-ip-address">Store last used session IP address</a></p></li>
|
||||
<li><p><a class="reference external" href="Howto/Coding-FAQ.html#non-latin-characters-in-evtable">Use wide characters with EvTable</a></p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="removing-default-commands">
|
||||
</section>
|
||||
<section id="removing-default-commands">
|
||||
<h2>Removing default commands<a class="headerlink" href="#removing-default-commands" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> How does one <em>remove</em> (not replace) e.g. the default <code class="docutils literal notranslate"><span class="pre">get</span></code> <a class="reference internal" href="../Components/Commands.html"><span class="doc">Command</span></a> from the
|
||||
Character <a class="reference internal" href="../Components/Command-Sets.html"><span class="doc">Command Set</span></a>?</p>
|
||||
|
|
@ -69,20 +70,20 @@ Character <a class="reference internal" href="../Components/Command-Sets.html"><
|
|||
method named <code class="docutils literal notranslate"><span class="pre">at_cmdset_creation</span></code>. At the end of that method, add the following line:
|
||||
<code class="docutils literal notranslate"><span class="pre">self.remove(default_cmds.CmdGet())</span></code>. See the <a class="reference internal" href="Starting/Part1/Adding-Commands.html"><span class="doc">Adding Commands Tutorial</span></a>
|
||||
for more info.</p>
|
||||
</div>
|
||||
<div class="section" id="preventing-character-from-moving-based-on-a-condition">
|
||||
</section>
|
||||
<section id="preventing-character-from-moving-based-on-a-condition">
|
||||
<h2>Preventing character from moving based on a condition<a class="headerlink" href="#preventing-character-from-moving-based-on-a-condition" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> How does one keep a character from using any exit, if they meet a certain condition? (I.E. in
|
||||
combat, immobilized, etc.)</p>
|
||||
<p><strong>A:</strong> The <code class="docutils literal notranslate"><span class="pre">at_before_move</span></code> hook is called by Evennia just before performing any move. If it returns
|
||||
<code class="docutils literal notranslate"><span class="pre">False</span></code>, the move is aborted. Let’s say we want to check for an <a class="reference internal" href="../Components/Attributes.html"><span class="doc">Attribute</span></a> <code class="docutils literal notranslate"><span class="pre">cantmove</span></code>.
|
||||
Add the following code to the <code class="docutils literal notranslate"><span class="pre">Character</span></code> class:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">at_before_move</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">destination</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">at_before_move</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">destination</span><span class="p">):</span>
|
||||
<span class="s2">"Called just before trying to move"</span>
|
||||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">cantmove</span><span class="p">:</span> <span class="c1"># replace with condition you want to test</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"Something is preventing you from moving!"</span><span class="p">)</span>
|
||||
|
|
@ -90,8 +91,8 @@ Add the following code to the <code class="docutils literal notranslate"><span c
|
|||
<span class="k">return</span> <span class="kc">True</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="reference-initiating-object-in-an-evmenu-command">
|
||||
</section>
|
||||
<section id="reference-initiating-object-in-an-evmenu-command">
|
||||
<h2>Reference initiating object in an EvMenu command.<a class="headerlink" href="#reference-initiating-object-in-an-evmenu-command" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> An object has a Command on it starts up an EvMenu instance. How do I capture a reference to
|
||||
that object for use in the menu?</p>
|
||||
|
|
@ -99,12 +100,12 @@ that object for use in the menu?</p>
|
|||
This is a good place to store menu-specific things since it will clean itself up when the menu
|
||||
closes. When initiating the menu, any additional keywords you give will be available for you as
|
||||
properties on this menu object:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyObjectCommand</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyObjectCommand</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="c1"># A Command stored on an object (the object is always accessible from</span>
|
||||
<span class="c1"># the Command as self.obj)</span>
|
||||
<span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
|
|
@ -113,26 +114,26 @@ properties on this menu object:</p>
|
|||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>Inside the menu you can now access the object through <code class="docutils literal notranslate"><span class="pre">caller.ndb._menutree.stored_obj</span></code>.</p>
|
||||
</div>
|
||||
<div class="section" id="adding-color-to-default-evennia-channels">
|
||||
</section>
|
||||
<section id="adding-color-to-default-evennia-channels">
|
||||
<h2>Adding color to default Evennia Channels<a class="headerlink" href="#adding-color-to-default-evennia-channels" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> How do I add colors to the names of Evennia channels?</p>
|
||||
<p><strong>A:</strong> The Channel typeclass’ <code class="docutils literal notranslate"><span class="pre">channel_prefix</span></code> method decides what is shown at the beginning of a
|
||||
channel send. Edit <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/channels.py</span></code> (and then <code class="docutils literal notranslate"><span class="pre">@reload</span></code>):</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># define our custom color names</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># define our custom color names</span>
|
||||
<span class="n">CHANNEL_COLORS</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'public'</span><span class="p">:</span> <span class="s1">'|015Public|n'</span><span class="p">,</span>
|
||||
<span class="s1">'newbie'</span><span class="p">:</span> <span class="s1">'|550N|n|551e|n|552w|n|553b|n|554i|n|555e|n'</span><span class="p">,</span>
|
||||
<span class="s1">'staff'</span><span class="p">:</span> <span class="s1">'|010S|n|020t|n|030a|n|040f|n|050f|n'</span><span class="p">}</span>
|
||||
|
|
@ -150,38 +151,38 @@ channel send. Edit <code class="docutils literal notranslate"><span class="pre">
|
|||
</td></tr></table></div>
|
||||
<p>Additional hint: To make colors easier to change from one place you could instead put the
|
||||
<code class="docutils literal notranslate"><span class="pre">CHANNEL_COLORS</span></code> dict in your settings file and import it as <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">django.conf.settings</span> <span class="pre">import</span> <span class="pre">CHANNEL_COLORS</span></code>.</p>
|
||||
</div>
|
||||
<div class="section" id="selectively-turn-off-commands-in-a-room">
|
||||
</section>
|
||||
<section id="selectively-turn-off-commands-in-a-room">
|
||||
<h2>Selectively turn off commands in a room<a class="headerlink" href="#selectively-turn-off-commands-in-a-room" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> I want certain commands to turn off in a given room. They should still work normally for
|
||||
staff.</p>
|
||||
<p><strong>A:</strong> This is done using a custom cmdset on a room <a class="reference internal" href="../Components/Locks.html"><span class="doc">locked with the ‘call’ lock type</span></a>. Only
|
||||
if this lock is passed will the commands on the room be made available to an object inside it. Here
|
||||
is an example of a room where certain commands are disabled for non-staff:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/typeclasses/rooms.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/typeclasses/rooms.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_commands</span><span class="p">,</span> <span class="n">CmdSet</span>
|
||||
|
||||
|
|
@ -212,24 +213,24 @@ will now replace the given commands for anyone that does not have the <code clas
|
|||
permission. Note that the ‘call’ lock is special in that even the superuser will be affected by it
|
||||
(otherwise superusers would always see other player’s cmdsets and a game would be unplayable for
|
||||
superusers).</p>
|
||||
</div>
|
||||
<div class="section" id="select-command-based-on-a-condition">
|
||||
</section>
|
||||
<section id="select-command-based-on-a-condition">
|
||||
<h2>Select Command based on a condition<a class="headerlink" href="#select-command-based-on-a-condition" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> I want a command to be available only based on a condition. For example I want the “werewolf”
|
||||
command to only be available on a full moon, from midnight to three in-game time.</p>
|
||||
<p><strong>A:</strong> This is easiest accomplished by putting the “werewolf” command on the Character as normal,
|
||||
but to <a class="reference internal" href="../Components/Locks.html"><span class="doc">lock</span></a> it with the “cmd” type lock. Only if the “cmd” lock type is passed will the
|
||||
command be available.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/command.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/command.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
|
||||
|
|
@ -243,13 +244,13 @@ command be available.</p>
|
|||
</td></tr></table></div>
|
||||
<p>Add this to the <a class="reference internal" href="Starting/Part1/Adding-Commands.html"><span class="doc">default cmdset as usual</span></a>. The <code class="docutils literal notranslate"><span class="pre">is_full_moon</span></code> <a class="reference external" href="Howto/Locks#lock-functions">lock
|
||||
function</a> does not yet exist. We must create that:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/server/conf/lockfuncs.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/server/conf/lockfuncs.py</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">is_full_moon</span><span class="p">(</span><span class="n">accessing_obj</span><span class="p">,</span> <span class="n">accessed_obj</span><span class="p">,</span>
|
||||
<span class="n">starthour</span><span class="p">,</span> <span class="n">endhour</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>
|
||||
|
|
@ -260,8 +261,8 @@ function</a> does not yet exist. We must create that:</p>
|
|||
</td></tr></table></div>
|
||||
<p>After a <code class="docutils literal notranslate"><span class="pre">@reload</span></code>, the <code class="docutils literal notranslate"><span class="pre">werewolf</span></code> command will be available only at the right time, that is when the
|
||||
<code class="docutils literal notranslate"><span class="pre">is_full_moon</span></code> lock function returns True.</p>
|
||||
</div>
|
||||
<div class="section" id="automatically-updating-code-when-reloading">
|
||||
</section>
|
||||
<section id="automatically-updating-code-when-reloading">
|
||||
<h2>Automatically updating code when reloading<a class="headerlink" href="#automatically-updating-code-when-reloading" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> I have a development server running Evennia. Can I have the server update its code-base when
|
||||
I reload?</p>
|
||||
|
|
@ -269,16 +270,16 @@ I reload?</p>
|
|||
useful if you have limited shell access to your server, or want to have it done automatically. If
|
||||
you have your project in a configured Git environment, it’s a matter of automatically calling <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">pull</span></code> when you reload. And that’s pretty straightforward:</p>
|
||||
<p>In <code class="docutils literal notranslate"><span class="pre">/server/conf/at_server_startstop.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">subprocess</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">subprocess</span>
|
||||
|
||||
<span class="c1"># ... other hooks ...</span>
|
||||
|
||||
|
|
@ -307,8 +308,8 @@ here).</p></li>
|
|||
<p>The reloading might take one or two additional seconds, since Evennia will pull from your remote Git
|
||||
repository. But it will reload on it and you will have your modifications ready, without needing
|
||||
connecting to your server using SSH or something similar.</p>
|
||||
</div>
|
||||
<div class="section" id="changing-all-exit-messages">
|
||||
</section>
|
||||
<section id="changing-all-exit-messages">
|
||||
<h2>Changing all exit messages<a class="headerlink" href="#changing-all-exit-messages" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> How can I change the default exit messages to something like “XXX leaves east” or “XXX
|
||||
arrives from the west”?</p>
|
||||
|
|
@ -327,62 +328,62 @@ simple customization).</p></li>
|
|||
<p>It is advisable to look in the <a class="reference external" href="https://github.com/evennia/evennia/tree/master/evennia/objects/objects.py">code of both
|
||||
hooks</a>, and read the
|
||||
hooks’ documentation. The explanations on how to quickly update the message are shown below:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># In typeclasses/characters.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># In typeclasses/characters.py</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd">Characters</span>
|
||||
|
||||
|
|
@ -444,20 +445,20 @@ hooks’ documentation. The explanations on how to quickly update the message a
|
|||
provided docstrings, you will better understand why and how we use mappings (information between
|
||||
braces). You can provide additional mappings as well, if you want to set a verb to move, for
|
||||
instance, or other, extra information.</p>
|
||||
</div>
|
||||
<div class="section" id="add-parsing-with-the-to-delimiter">
|
||||
</section>
|
||||
<section id="add-parsing-with-the-to-delimiter">
|
||||
<h2>Add parsing with the “to” delimiter<a class="headerlink" href="#add-parsing-with-the-to-delimiter" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> How do I change commands to undestand say <code class="docutils literal notranslate"><span class="pre">give</span> <span class="pre">obj</span> <span class="pre">to</span> <span class="pre">target</span></code> as well as the default <code class="docutils literal notranslate"><span class="pre">give</span> <span class="pre">obj</span> <span class="pre">=</span> <span class="pre">target</span></code>?</p>
|
||||
<p><strong>A:</strong> You can make change the default <code class="docutils literal notranslate"><span class="pre">MuxCommand</span></code> parent with your own class making a small change
|
||||
in its <code class="docutils literal notranslate"><span class="pre">parse</span></code> method:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="c1"># in mygame/commands/command.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="c1"># in mygame/commands/command.py</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span>
|
||||
<span class="k">class</span> <span class="nc">MuxCommand</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="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
|
|
@ -468,21 +469,21 @@ in its <code class="docutils literal notranslate"><span class="pre">parse</span>
|
|||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>Next you change the parent of the default commands in settings:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="n">COMMAND_DEFAULT_CLASS</span> <span class="o">=</span> <span class="s2">"commands.command.MuxCommand"</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="n">COMMAND_DEFAULT_CLASS</span> <span class="o">=</span> <span class="s2">"commands.command.MuxCommand"</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>Do a <code class="docutils literal notranslate"><span class="pre">@reload</span></code> and all default commands will now use your new tweaked parent class. A copy of the
|
||||
MuxCommand class is also found commented-out in the <code class="docutils literal notranslate"><span class="pre">mygame/commands/command.py</span></code> file.</p>
|
||||
</div>
|
||||
<div class="section" id="store-last-used-session-ip-address">
|
||||
</section>
|
||||
<section id="store-last-used-session-ip-address">
|
||||
<h2>Store last used session IP address<a class="headerlink" href="#store-last-used-session-ip-address" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> If a user has already logged out of an Evennia account, their IP is no longer visible to
|
||||
staff that wants to ban-by-ip (instead of the user) with <code class="docutils literal notranslate"><span class="pre">@ban/ip</span></code>?</p>
|
||||
<p><strong>A:</strong> One approach is to write the IP from the last session onto the “account” account object.</p>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">typeclasses/accounts.py</span></code></p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">at_post_login</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">session</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">at_post_login</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">session</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||||
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">at_post_login</span><span class="p">(</span><span class="n">session</span><span class="o">=</span><span class="n">session</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">lastsite</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sessions</span><span class="o">.</span><span class="n">all</span><span class="p">()[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">address</span>
|
||||
</pre></div>
|
||||
|
|
@ -492,15 +493,15 @@ timestamps is possible, also. Additionally, if you don’t want the list to gro
|
|||
<code class="docutils literal notranslate"><span class="pre">do_not_exceed</span></code> length, conditionally pop a value after you’ve added it, if the length has grown too
|
||||
long.</p>
|
||||
<p><strong>NOTE:</strong> You’ll need to add <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">time</span></code> to generate the login timestamp.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">at_post_login</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">session</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">at_post_login</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">session</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||||
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">at_post_login</span><span class="p">(</span><span class="n">session</span><span class="o">=</span><span class="n">session</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
|
||||
<span class="n">do_not_exceed</span> <span class="o">=</span> <span class="mi">24</span> <span class="c1"># Keep the last two dozen entries</span>
|
||||
<span class="n">session</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sessions</span><span class="o">.</span><span class="n">all</span><span class="p">()[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="c1"># Most recent session</span>
|
||||
|
|
@ -513,8 +514,8 @@ long.</p>
|
|||
</td></tr></table></div>
|
||||
<p>This only stores the data. You may want to interface the <code class="docutils literal notranslate"><span class="pre">@ban</span></code> command or make a menu-driven viewer
|
||||
for staff to browse the list and display how long ago the login occurred.</p>
|
||||
</div>
|
||||
<div class="section" id="non-latin-characters-in-evtable">
|
||||
</section>
|
||||
<section id="non-latin-characters-in-evtable">
|
||||
<h2>Non-latin characters in EvTable<a class="headerlink" href="#non-latin-characters-in-evtable" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>Q:</strong> When using e.g. Chinese characters in EvTable, some lines appear to be too wide, for example</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">+------+------+</span>
|
||||
|
|
@ -529,8 +530,8 @@ their len() suggests. There is little Evennia can (reliably) do about this. If y
|
|||
characters, you need to make sure to use a suitable mono-spaced font where are width are equal. You
|
||||
can set this in your web client and need to recommend it for telnet-client users. See <a class="reference external" href="https://github.com/evennia/evennia/issues/1522">this
|
||||
discussion</a> where some suitable fonts are suggested.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<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 Cooldown — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="command-cooldown">
|
||||
<section id="command-cooldown">
|
||||
<h1>Command Cooldown<a class="headerlink" href="#command-cooldown" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Some types of games want to limit how often a command can be run. If a
|
||||
character casts the spell <em>Firestorm</em>, you might not want them to spam that
|
||||
|
|
@ -48,7 +49,7 @@ a while. Such effects are called <em>cooldowns</em>.</p>
|
|||
‘active’ way is to use asynchronous delays as in the <a class="reference external" href="Howto/Command-Duration.html#Blocking-Commands">command duration
|
||||
tutorial</a>, the two might be useful to
|
||||
combine if you want to echo some message to the user after the cooldown ends.</p>
|
||||
<div class="section" id="non-persistent-cooldown">
|
||||
<section id="non-persistent-cooldown">
|
||||
<h2>Non-persistent cooldown<a class="headerlink" href="#non-persistent-cooldown" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This little recipe will limit how often a particular command can be run. Since
|
||||
Commands are class instances, and those are cached in memory, a command
|
||||
|
|
@ -56,37 +57,37 @@ instance will remember things you store on it. So just store the current time
|
|||
of execution! Next time the command is run, it just needs to check if it has
|
||||
that time stored, and compare it with the current time to see if a desired
|
||||
delay has passed.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">time</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">time</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdSpellFirestorm</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">MuxCommand</span><span class="p">):</span>
|
||||
|
|
@ -125,29 +126,29 @@ drawback of this simple scheme is that it’s non-persistent. If you do
|
|||
<code class="docutils literal notranslate"><span class="pre">@reload</span></code>, the cache is cleaned and all such ongoing cooldowns will be
|
||||
forgotten. It is also limited only to this one command, other commands cannot
|
||||
(easily) check for this value.</p>
|
||||
</div>
|
||||
<div class="section" id="persistent-cooldown">
|
||||
</section>
|
||||
<section id="persistent-cooldown">
|
||||
<h2>Persistent cooldown<a class="headerlink" href="#persistent-cooldown" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This is essentially the same mechanism as the simple one above, except we use
|
||||
the database to store the information which means the cooldown will survive a
|
||||
server reload/reboot. Since commands themselves have no representation in the
|
||||
database, you need to use the caster for the storage.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="c1"># inside the func() of CmdSpellFirestorm as above</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span> <span class="c1"># inside the func() of CmdSpellFirestorm as above</span>
|
||||
|
||||
<span class="c1"># check cooldown (5 minute cooldown)</span>
|
||||
|
||||
|
|
@ -173,8 +174,8 @@ for example let all fire-related spells check the same cooldown to make sure
|
|||
the casting of <em>Firestorm</em> blocks all fire-related spells for a while. Or, in
|
||||
the case of taking that big swing with the sword, this could now block all
|
||||
other types of attacks for a while before the warrior can recover.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<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>
|
||||
<link rel="stylesheet" href="../_static/nature.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="command-duration">
|
||||
<section 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">the documentation on commands</span></a> to get a basic understanding of
|
||||
|
|
@ -47,29 +48,29 @@ 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>
|
||||
<div class="section" id="the-simple-way-to-pause-commands-with-yield">
|
||||
<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"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17</pre></div></td><td class="code"><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>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><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>
|
||||
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> A test command just to test waiting.</span>
|
||||
|
|
@ -106,40 +107,40 @@ other players aren’t frozen either.</p>
|
|||
while a command is “paused”, it will not resume after the server has
|
||||
reloaded.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="the-more-advanced-way-with-utils-delay">
|
||||
</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"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28</pre></div></td><td class="code"><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>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><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="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>
|
||||
|
|
@ -173,7 +174,7 @@ you want more advanced options. Learning to use alternatives might be much wort
|
|||
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>
|
||||
<div class="section" id="about-utils-delay">
|
||||
<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
|
||||
|
|
@ -202,43 +203,43 @@ called (the way <code class="docutils literal notranslate"><span class="pre">yie
|
|||
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"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37</pre></div></td><td class="code"><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>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span></pre></div></td><td class="code"><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="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>
|
||||
|
|
@ -285,9 +286,9 @@ delay.</p>
|
|||
... hello! ...
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="blocking-commands">
|
||||
</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
|
||||
|
|
@ -302,43 +303,43 @@ the stored time to determine if enough time had passed for a renewed use. This i
|
|||
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>
|
||||
<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"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37</pre></div></td><td class="code"><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>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span></pre></div></td><td class="code"><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>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdBigSwing</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>
|
||||
|
|
@ -383,102 +384,102 @@ another swing.</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>
|
||||
</div>
|
||||
<div class="section" id="abortable-commands">
|
||||
</section>
|
||||
<section id="abortable-commands">
|
||||
<h2>Abortable commands<a class="headerlink" href="#abortable-commands" 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>
|
||||
<p>You can implement this in the same way as you do the “blocking” command above, just in reverse.
|
||||
Below is an example of a crafting command that can be aborted by starting a fight:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69
|
||||
70
|
||||
71
|
||||
72
|
||||
73
|
||||
74
|
||||
75
|
||||
76
|
||||
77
|
||||
78
|
||||
79
|
||||
80
|
||||
81
|
||||
82
|
||||
83
|
||||
84
|
||||
85
|
||||
86
|
||||
87
|
||||
88</pre></div></td><td class="code"><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>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span>
|
||||
<span class="normal">60</span>
|
||||
<span class="normal">61</span>
|
||||
<span class="normal">62</span>
|
||||
<span class="normal">63</span>
|
||||
<span class="normal">64</span>
|
||||
<span class="normal">65</span>
|
||||
<span class="normal">66</span>
|
||||
<span class="normal">67</span>
|
||||
<span class="normal">68</span>
|
||||
<span class="normal">69</span>
|
||||
<span class="normal">70</span>
|
||||
<span class="normal">71</span>
|
||||
<span class="normal">72</span>
|
||||
<span class="normal">73</span>
|
||||
<span class="normal">74</span>
|
||||
<span class="normal">75</span>
|
||||
<span class="normal">76</span>
|
||||
<span class="normal">77</span>
|
||||
<span class="normal">78</span>
|
||||
<span class="normal">79</span>
|
||||
<span class="normal">80</span>
|
||||
<span class="normal">81</span>
|
||||
<span class="normal">82</span>
|
||||
<span class="normal">83</span>
|
||||
<span class="normal">84</span>
|
||||
<span class="normal">85</span>
|
||||
<span class="normal">86</span>
|
||||
<span class="normal">87</span>
|
||||
<span class="normal">88</span></pre></div></td><td class="code"><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>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdCraftArmour</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>
|
||||
|
|
@ -571,8 +572,8 @@ Below is an example of a crafting command that can be aborted by starting a figh
|
|||
<p>The above code creates a delayed crafting command that will gradually create the armour. If the
|
||||
<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>
|
||||
</div>
|
||||
<div class="section" id="persistent-delays">
|
||||
</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
|
||||
|
|
@ -581,36 +582,36 @@ the use of <code class="docutils literal notranslate"><span class="pre">delay</s
|
|||
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"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30</pre></div></td><td class="code"><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>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><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>
|
||||
|
|
@ -654,8 +655,8 @@ access to them directly since this is now a stand-alone function).</p></li>
|
|||
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>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<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 Prompt — 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" />
|
||||
|
|
@ -37,64 +38,64 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="command-prompt">
|
||||
<section id="command-prompt">
|
||||
<h1>Command Prompt<a class="headerlink" href="#command-prompt" title="Permalink to this headline">¶</a></h1>
|
||||
<p>A <em>prompt</em> is quite common in MUDs. The prompt display useful details about your character that you
|
||||
are likely to want to keep tabs on at all times, such as health, magical power etc. It might also
|
||||
show things like in-game time, weather and so on. Many modern MUD clients (including Evennia’s own
|
||||
webclient) allows for identifying the prompt and have it appear in a correct location (usually just
|
||||
above the input line). Usually it will remain like that until it is explicitly updated.</p>
|
||||
<div class="section" id="sending-a-prompt">
|
||||
<section id="sending-a-prompt">
|
||||
<h2>Sending a prompt<a class="headerlink" href="#sending-a-prompt" title="Permalink to this headline">¶</a></h2>
|
||||
<p>A prompt is sent using the <code class="docutils literal notranslate"><span class="pre">prompt</span></code> keyword to the <code class="docutils literal notranslate"><span class="pre">msg()</span></code> method on objects. The prompt will be
|
||||
sent without any line breaks.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="n">prompt</span><span class="o">=</span><span class="s2">"HP: 5, MP: 2, SP: 8"</span><span class="p">)</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="n">prompt</span><span class="o">=</span><span class="s2">"HP: 5, MP: 2, SP: 8"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>You can combine the sending of normal text with the sending (updating of the prompt):</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"This is a text"</span><span class="p">,</span> <span class="n">prompt</span><span class="o">=</span><span class="s2">"This is a prompt"</span><span class="p">)</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"This is a text"</span><span class="p">,</span> <span class="n">prompt</span><span class="o">=</span><span class="s2">"This is a prompt"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>You can update the prompt on demand, this is normally done using <a class="reference internal" href="../Concepts/OOB.html"><span class="doc">OOB</span></a>-tracking of the relevant
|
||||
Attributes (like the character’s health). You could also make sure that attacking commands update
|
||||
the prompt when they cause a change in health, for example.</p>
|
||||
<p>Here is a simple example of the prompt sent/updated from a command class:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span> <span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdDiagnose</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -132,8 +133,8 @@ the prompt when they cause a change in health, for example.</p>
|
|||
<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="n">text</span><span class="p">,</span> <span class="n">prompt</span><span class="o">=</span><span class="n">prompt</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="a-prompt-sent-with-every-command">
|
||||
</section>
|
||||
<section id="a-prompt-sent-with-every-command">
|
||||
<h2>A prompt sent with every command<a class="headerlink" href="#a-prompt-sent-with-every-command" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The prompt sent as described above uses a standard telnet instruction (the Evennia web client gets a
|
||||
special flag). Most MUD telnet clients will understand and allow users to catch this and keep the
|
||||
|
|
@ -144,17 +145,17 @@ users have. So sending a prompt with every command is a safe catch-all. You don
|
|||
go in and edit every command you have though. Instead you edit the base command class for your
|
||||
custom commands (like <code class="docutils literal notranslate"><span class="pre">MuxCommand</span></code> in your <code class="docutils literal notranslate"><span class="pre">mygame/commands/command.py</span></code> folder) and overload the
|
||||
<code class="docutils literal notranslate"><span class="pre">at_post_cmd()</span></code> hook. This hook is always called <em>after</em> the main <code class="docutils literal notranslate"><span class="pre">func()</span></code> method of the Command.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11</pre></div></td><td class="code"><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>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><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="k">class</span> <span class="nc">MuxCommand</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="c1"># ...</span>
|
||||
|
|
@ -167,19 +168,19 @@ custom commands (like <code class="docutils literal notranslate"><span class="pr
|
|||
<span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="n">prompt</span><span class="o">=</span><span class="n">prompt</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="section" id="modifying-default-commands">
|
||||
<section id="modifying-default-commands">
|
||||
<h3>Modifying default commands<a class="headerlink" href="#modifying-default-commands" title="Permalink to this headline">¶</a></h3>
|
||||
<p>If you want to add something small like this to Evennia’s default commands without modifying them
|
||||
directly the easiest way is to just wrap those with a multiple inheritance to your own base class:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in (for example) mygame/commands/mycommands.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in (for example) mygame/commands/mycommands.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span>
|
||||
<span class="c1"># our custom MuxCommand with at_post_cmd hook</span>
|
||||
|
|
@ -192,16 +193,16 @@ directly the easiest way is to just wrap those with a multiple inheritance to yo
|
|||
</td></tr></table></div>
|
||||
<p>The result of this is that the hooks from your custom <code class="docutils literal notranslate"><span class="pre">MuxCommand</span></code> will be mixed into the default
|
||||
<code class="docutils literal notranslate"><span class="pre">CmdLook</span></code> through multiple inheritance. Next you just add this to your default command set:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/default_cmdsets.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/default_cmdsets.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span>
|
||||
<span class="kn">from</span> <span class="nn">commands</span> <span class="kn">import</span> <span class="n">mycommands</span>
|
||||
|
|
@ -214,9 +215,9 @@ directly the easiest way is to just wrap those with a multiple inheritance to yo
|
|||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>This will automatically replace the default <code class="docutils literal notranslate"><span class="pre">look</span></code> command in your game with your own version.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Coordinates — 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" />
|
||||
|
|
@ -37,10 +38,10 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="coordinates">
|
||||
<section id="coordinates">
|
||||
<h1>Coordinates<a class="headerlink" href="#coordinates" title="Permalink to this headline">¶</a></h1>
|
||||
</div>
|
||||
<div class="section" id="adding-room-coordinates-in-your-game">
|
||||
</section>
|
||||
<section id="adding-room-coordinates-in-your-game">
|
||||
<h1>Adding room coordinates in your game<a class="headerlink" href="#adding-room-coordinates-in-your-game" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This tutorial is moderately difficult in content. You might want to be familiar and at ease with
|
||||
some Python concepts (like properties) and possibly Django concepts (like queries), although this
|
||||
|
|
@ -58,7 +59,7 @@ include exits, rooms, characters and so on).</p></li>
|
|||
Here, I offer you a way to add coordinates to every room in a way most compliant with Evennia
|
||||
design. This will also show you how to use coordinates, find rooms around a given point for
|
||||
instance.</p>
|
||||
<div class="section" id="coordinates-as-tags">
|
||||
<section id="coordinates-as-tags">
|
||||
<h2>Coordinates as tags<a class="headerlink" href="#coordinates-as-tags" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The first concept might be the most surprising at first glance: we will create coordinates as
|
||||
<a class="reference internal" href="../Components/Tags.html"><span class="doc">tags</span></a>.</p>
|
||||
|
|
@ -72,65 +73,65 @@ things based on coordinates.</p>
|
|||
<p>Rather than giving you a step-by-step process, I’ll show you the code. Notice that we use
|
||||
properties to easily access and update coordinates. This is a Pythonic approach. Here’s our first
|
||||
<code class="docutils literal notranslate"><span class="pre">Room</span></code> class, that you can modify in <code class="docutils literal notranslate"><span class="pre">typeclasses/rooms.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in typeclasses/rooms.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in typeclasses/rooms.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultRoom</span>
|
||||
|
||||
|
|
@ -196,11 +197,11 @@ tutorial on the subject. [This article on Python properties](https://www.progra
|
|||
programming/property)
|
||||
is well-explained and should help you understand the idea.</p>
|
||||
<p>Let’s look at our properties for <code class="docutils literal notranslate"><span class="pre">x</span></code>. First of all is the read property.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="nd">@property</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="nd">@property</span>
|
||||
<span class="k">def</span> <span class="nf">x</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="sd">"""Return the X coordinate or None."""</span>
|
||||
<span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tags</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">category</span><span class="o">=</span><span class="s2">"coordx"</span><span class="p">)</span>
|
||||
|
|
@ -221,14 +222,14 @@ so we’ll need to convert it.</p></li>
|
|||
done, we get a tag, knowing only its category. That’s the basic approach to coordinates in this
|
||||
tutorial.</p>
|
||||
<p>Now, let’s look at the method that will be called when we wish to set <code class="docutils literal notranslate"><span class="pre">x</span></code> in our room:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="nd">@x</span><span class="o">.</span><span class="n">setter</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="nd">@x</span><span class="o">.</span><span class="n">setter</span>
|
||||
<span class="k">def</span> <span class="nf">x</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
|
||||
<span class="sd">"""Change the X coordinate."""</span>
|
||||
<span class="n">old</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tags</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">category</span><span class="o">=</span><span class="s2">"coordx"</span><span class="p">)</span>
|
||||
|
|
@ -256,8 +257,8 @@ location, you can play around:</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>The code might not be that easy to read, but you have to admit it’s fairly easy to use.</p>
|
||||
</div>
|
||||
<div class="section" id="some-additional-searches">
|
||||
</section>
|
||||
<section id="some-additional-searches">
|
||||
<h2>Some additional searches<a class="headerlink" href="#some-additional-searches" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Having coordinates is useful for several reasons:</p>
|
||||
<ol class="simple">
|
||||
|
|
@ -269,34 +270,34 @@ location, you can play around:</p>
|
|||
<p>So far, our coordinate system can help with 1., but not much else. Here are some methods that we
|
||||
could add to the <code class="docutils literal notranslate"><span class="pre">Room</span></code> typeclass. These methods will just be search methods. Notice that they are
|
||||
class methods, since we want to get rooms.</p>
|
||||
<div class="section" id="finding-one-room">
|
||||
<section id="finding-one-room">
|
||||
<h3>Finding one room<a class="headerlink" href="#finding-one-room" title="Permalink to this headline">¶</a></h3>
|
||||
<p>First, a simple one: how to find a room at a given coordinate? Say, what is the room at X=0, Y=0,
|
||||
Z=0?</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Room</span><span class="p">(</span><span class="n">DefaultRoom</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Room</span><span class="p">(</span><span class="n">DefaultRoom</span><span class="p">):</span>
|
||||
<span class="c1"># ...</span>
|
||||
<span class="nd">@classmethod</span>
|
||||
<span class="k">def</span> <span class="nf">get_room_at</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">):</span>
|
||||
|
|
@ -334,68 +335,68 @@ Though you still can:</p>
|
|||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@py</span> <span class="n">here</span><span class="o">.</span><span class="n">get_room_at</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="finding-several-rooms">
|
||||
</section>
|
||||
<section id="finding-several-rooms">
|
||||
<h3>Finding several rooms<a class="headerlink" href="#finding-several-rooms" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Here’s another useful method that allows us to look for rooms around a given coordinate. This is
|
||||
more advanced search and doing some calculation, beware! Look at the following section if you’re
|
||||
lost.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">sqrt</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">sqrt</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Room</span><span class="p">(</span><span class="n">DefaultRoom</span><span class="p">):</span>
|
||||
|
||||
|
|
@ -467,8 +468,8 @@ objects, just a wider range than what would be really necessary. This method re
|
|||
coordinates around a specified point. Django looks for a square. What wouldn’t fit in the circle
|
||||
is removed at step 3, which is the only part that includes systematic calculation. This method is
|
||||
optimized to be quick and efficient.</p>
|
||||
</div>
|
||||
<div class="section" id="an-example">
|
||||
</section>
|
||||
<section id="an-example">
|
||||
<h3>An example<a class="headerlink" href="#an-example" title="Permalink to this headline">¶</a></h3>
|
||||
<p>An example might help. Consider this very simple map (a textual description follows):</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">4</span> <span class="n">A</span> <span class="n">B</span> <span class="n">C</span> <span class="n">D</span>
|
||||
|
|
@ -508,14 +509,14 @@ square (E, G, M and O) are not in this circle. So we remove them.</p></li>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>You can try with more examples if you want to see this in action.</p>
|
||||
</div>
|
||||
<div class="section" id="to-conclude">
|
||||
</section>
|
||||
<section id="to-conclude">
|
||||
<h3>To conclude<a class="headerlink" href="#to-conclude" title="Permalink to this headline">¶</a></h3>
|
||||
<p>You can definitely use this system to map other objects, not just rooms. You can easily remove the
|
||||
`Z coordinate too, if you simply need X and Y.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Default Exit Errors — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="default-exit-errors">
|
||||
<section id="default-exit-errors">
|
||||
<h1>Default Exit Errors<a class="headerlink" href="#default-exit-errors" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Evennia allows for exits to have any name. The command “kitchen” is a valid exit name as well as
|
||||
“jump out the window” or “north”. An exit actually consists of two parts: an <a class="reference internal" href="../Components/Objects.html"><span class="doc">Exit Object</span></a>
|
||||
|
|
@ -58,41 +59,41 @@ error starts to look less logical:</p>
|
|||
</div>
|
||||
<p>Since we for our particular game <em>know</em> that west is an exit direction, it would be better if the
|
||||
error message just told us that we couldn’t go there.</p>
|
||||
<div class="section" id="adding-default-error-commands">
|
||||
<section id="adding-default-error-commands">
|
||||
<h2>Adding default error commands<a class="headerlink" href="#adding-default-error-commands" title="Permalink to this headline">¶</a></h2>
|
||||
<p>To solve this you need to be aware of how to <a class="reference internal" href="Starting/Part1/Adding-Commands.html"><span class="doc">write and add new commands</span></a>.
|
||||
What you need to do is to create new commands for all directions you want to support in your game.
|
||||
In this example all we’ll do is echo an error message, but you could certainly consider more
|
||||
advanced uses. You add these commands to the default command set. Here is an example of such a set
|
||||
of commands:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># for example in a file mygame/commands/movecommands.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># for example in a file mygame/commands/movecommands.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span>
|
||||
|
||||
|
|
@ -124,19 +125,19 @@ of commands:</p>
|
|||
</td></tr></table></div>
|
||||
<p>Make sure to add the directional commands (not their parent) to the <code class="docutils literal notranslate"><span class="pre">CharacterCmdSet</span></code> class in
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/default_cmdsets.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/default_cmdsets.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">commands</span> <span class="kn">import</span> <span class="n">movecommands</span>
|
||||
|
||||
|
|
@ -162,18 +163,18 @@ commands:</p>
|
|||
</div>
|
||||
<p>Further expansions by the exit system (including manipulating the way the Exit command itself is
|
||||
created) can be done by modifying the <a class="reference internal" href="../Components/Typeclasses.html"><span class="doc">Exit typeclass</span></a> directly.</p>
|
||||
</div>
|
||||
<div class="section" id="additional-comments">
|
||||
</section>
|
||||
<section id="additional-comments">
|
||||
<h2>Additional Comments<a class="headerlink" href="#additional-comments" title="Permalink to this headline">¶</a></h2>
|
||||
<p>So why didn’t we create a single error command above? Something like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">class</span> <span class="nc">CmdExitError</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">MuxCommand</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">class</span> <span class="nc">CmdExitError</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="s2">"Handles all exit-errors."</span>
|
||||
<span class="n">key</span> <span class="o">=</span> <span class="s2">"error_cmd"</span>
|
||||
<span class="n">aliases</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"north"</span><span class="p">,</span> <span class="s2">"n"</span><span class="p">,</span>
|
||||
|
|
@ -195,8 +196,8 @@ thus overloaded by the Exit command (which also correctly defaults to a higher p
|
|||
is that you can go through the north exit normally but none of the error messages for the other
|
||||
directions are available since the single error command was completely overloaded by the single
|
||||
matching “north” exit-command.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Evennia for Diku Users — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="evennia-for-diku-users">
|
||||
<section id="evennia-for-diku-users">
|
||||
<h1>Evennia for Diku Users<a class="headerlink" href="#evennia-for-diku-users" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Evennia represents a learning curve for those who used to code on
|
||||
<a class="reference external" href="https://en.wikipedia.org/wiki/DikuMUD">Diku</a> type MUDs. While coding in Python is easy if you
|
||||
|
|
@ -50,7 +51,7 @@ handling of errors. While Python code does not run as fast as raw C code does, t
|
|||
all that important for a text-based game. The main advantage of Python is an extremely fast
|
||||
development cycle with and easy ways to create game systems that would take many times more code and
|
||||
be much harder to make stable and maintainable in C.</p>
|
||||
<div class="section" id="core-differences">
|
||||
<section id="core-differences">
|
||||
<h2>Core Differences<a class="headerlink" href="#core-differences" title="Permalink to this headline">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p>As mentioned, the main difference between Evennia and a Diku-derived codebase is that Evennia is
|
||||
|
|
@ -65,23 +66,23 @@ while writing to a flatfile it may become corrupt and the data lost. A proper da
|
|||
not susceptible to this - at no point is the data in a state where it cannot be recovered. Databases
|
||||
are also highly optimized for querying large data sets efficiently.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="some-familiar-things">
|
||||
</section>
|
||||
<section id="some-familiar-things">
|
||||
<h2>Some Familiar Things<a class="headerlink" href="#some-familiar-things" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Diku expresses the character object referenced normally by:</p>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">char</span> <span class="pre">ch*</span></code> then all character-related fields can be accessed by <code class="docutils literal notranslate"><span class="pre">ch-></span></code>. In Evennia, one must
|
||||
pay attention to what object you are using, and when you are accessing another through back-
|
||||
handling, that you are accessing the right object. In Diku C, accessing character object is normally
|
||||
done by:</p>
|
||||
<div class="highlight-c notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="cm">/* creating pointer of both character and room struct */</span>
|
||||
<div class="highlight-c notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="cm">/* creating pointer of both character and room struct */</span>
|
||||
|
||||
<span class="kt">void</span><span class="p">(</span><span class="k">struct</span> <span class="nc">char</span> <span class="n">ch</span><span class="o">*</span><span class="p">,</span> <span class="k">struct</span> <span class="nc">room</span> <span class="n">room</span><span class="o">*</span><span class="p">){</span>
|
||||
<span class="kt">int</span> <span class="n">dam</span><span class="p">;</span>
|
||||
|
|
@ -96,23 +97,23 @@ done by:</p>
|
|||
object that calls the command is denoted by a class property as <code class="docutils literal notranslate"><span class="pre">self.caller</span></code>. In this example
|
||||
<code class="docutils literal notranslate"><span class="pre">self.caller</span></code> is essentially the ‘object’ that has called the Command, but most of the time it is an
|
||||
Account object. For a more familiar Diku feel, create a variable that becomes the account object as:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1">#mygame/commands/command.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1">#mygame/commands/command.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
|
||||
|
|
@ -133,25 +134,25 @@ Account object. For a more familiar Diku feel, create a variable that becomes th
|
|||
</td></tr></table></div>
|
||||
<p>As mentioned above, care must be taken what specific object you are working with. If focused on a
|
||||
room object and you need to access the account object:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1">#mygame/typeclasses/room.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1">#mygame/typeclasses/room.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultRoom</span>
|
||||
|
||||
|
|
@ -172,8 +173,8 @@ room object and you need to access the account object:</p>
|
|||
<span class="n">race</span> <span class="o">=</span> <span class="n">ch</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">race</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="emulating-evennia-to-look-and-feel-like-a-diku-rom">
|
||||
</section>
|
||||
<section id="emulating-evennia-to-look-and-feel-like-a-diku-rom">
|
||||
<h2>Emulating Evennia to Look and Feel Like A Diku/ROM<a class="headerlink" href="#emulating-evennia-to-look-and-feel-like-a-diku-rom" title="Permalink to this headline">¶</a></h2>
|
||||
<p>To emulate a Diku Mud on Evennia some work has to be done before hand. If there is anything that all
|
||||
coders and builders remember from Diku/Rom days is the presence of VNUMs. Essentially all data was
|
||||
|
|
@ -185,33 +186,33 @@ and even a stand alone databases.</p>
|
|||
<p>Because of their wonderful structure all mob, room, zone, triggers, etc.. data can be saved in
|
||||
independently created global scripts.</p>
|
||||
<p>Here is a sample mob file from a Diku Derived flat file.</p>
|
||||
<div class="highlight-text notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27</pre></div></td><td class="code"><div class="highlight"><pre><span></span>#0
|
||||
<div class="highlight-text notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>#0
|
||||
mob0~
|
||||
mob0~
|
||||
mob0
|
||||
|
|
@ -247,11 +248,11 @@ in Evennia.</p>
|
|||
can either create this directly in-game with the @py command or create it in another file to do some
|
||||
checks and balances if for whatever reason the script needs to be created again. Progmatically it
|
||||
can be done like so:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">create_script</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">create_script</span>
|
||||
|
||||
<span class="n">mob_db</span> <span class="o">=</span> <span class="n">create_script</span><span class="p">(</span><span class="s2">"typeclasses.scripts.DefaultScript"</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s2">"mobdb"</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="n">obj</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
|
||||
|
|
@ -260,21 +261,21 @@ can be done like so:</p>
|
|||
</td></tr></table></div>
|
||||
<p>Just by creating a simple script object and assigning it a ‘vnums’ attribute as a type dictionary.
|
||||
Next we have to create the mob layout..</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># vnum : mob_data</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># vnum : mob_data</span>
|
||||
|
||||
<span class="n">mob_vnum_1</span> <span class="o">=</span> <span class="p">{</span>
|
||||
<span class="s1">'key'</span> <span class="p">:</span> <span class="s1">'puff'</span><span class="p">,</span>
|
||||
|
|
@ -299,8 +300,8 @@ create an instance of this mob and make its <code class="docutils literal notran
|
|||
<p><code class="docutils literal notranslate"><span class="pre">Here</span> <span class="pre">is</span> <span class="pre">:</span> <span class="pre">1</span></code></p>
|
||||
<p>You must restructure all default commands so that the mud looks at different properties defined on
|
||||
your mob.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Evennia for MUSH Users — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="evennia-for-mush-users">
|
||||
<section id="evennia-for-mush-users">
|
||||
<h1>Evennia for MUSH Users<a class="headerlink" href="#evennia-for-mush-users" title="Permalink to this headline">¶</a></h1>
|
||||
<p><em>This page is adopted from an article originally posted for the MUSH community <a class="reference external" href="http://musoapbox.net/topic/1150/evennia-for-mushers">here on
|
||||
musoapbox.net</a>.</em></p>
|
||||
|
|
@ -53,7 +54,7 @@ language. We will refer to this online scripting as <em>softcode</em> here.</p>
|
|||
<p>Evennia works quite differently from a MUSH both in its overall design and under the hood. The same
|
||||
things are achievable, just in a different way. Here are some fundamental differences to keep in
|
||||
mind if you are coming from the MUSH world.</p>
|
||||
<div class="section" id="developers-vs-players">
|
||||
<section id="developers-vs-players">
|
||||
<h2>Developers vs Players<a class="headerlink" href="#developers-vs-players" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In MUSH, users tend to code and expand all aspects of the game from inside it using softcode. A MUSH
|
||||
can thus be said to be managed solely by <em>Players</em> with different levels of access. Evennia on the
|
||||
|
|
@ -70,8 +71,8 @@ may get access to Python via the <code class="docutils literal notranslate"><spa
|
|||
to use. So the <em>Player</em> usually operates by making use of the tools prepared for them by the
|
||||
<em>Developer</em> - tools that can be as rigid or flexible as the developer desires.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="collaborating-on-a-game-python-vs-softcode">
|
||||
</section>
|
||||
<section id="collaborating-on-a-game-python-vs-softcode">
|
||||
<h2>Collaborating on a game - Python vs Softcode<a class="headerlink" href="#collaborating-on-a-game-python-vs-softcode" title="Permalink to this headline">¶</a></h2>
|
||||
<p>For a <em>Player</em>, collaborating on a game need not be too different between MUSH and Evennia. The
|
||||
building and description of the game world can still happen mostly in-game using build commands,
|
||||
|
|
@ -90,8 +91,8 @@ websites like github (or bitbucket for a free private repo). Source code can be
|
|||
text editors and IDEs with refactoring, syntax highlighting and all other conveniences. In short,
|
||||
collaborative development of an Evennia game is done in the same way most professional collaborative
|
||||
development is done in the world, meaning all the best tools can be used.</p>
|
||||
</div>
|
||||
<div class="section" id="parent-vs-typeclass-and-spawn">
|
||||
</section>
|
||||
<section id="parent-vs-typeclass-and-spawn">
|
||||
<h2><code class="docutils literal notranslate"><span class="pre">@parent</span></code> vs <code class="docutils literal notranslate"><span class="pre">@typeclass</span></code> and <code class="docutils literal notranslate"><span class="pre">@spawn</span></code><a class="headerlink" href="#parent-vs-typeclass-and-spawn" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Inheritance works differently in Python than in softcode. Evennia has no concept of a “master
|
||||
object” that other objects inherit from. There is in fact no reason at all to introduce “virtual
|
||||
|
|
@ -119,11 +120,11 @@ based inheritance of MUSH.</p>
|
|||
<p>There are other differences for sure, but that should give some feel for things. Enough with the
|
||||
theory. Let’s get down to more practical matters next. To install, see the
|
||||
<a class="reference internal" href="../Setup/Setup-Quickstart.html"><span class="doc">Getting Started instructions</span></a>.</p>
|
||||
</div>
|
||||
<div class="section" id="a-first-step-making-things-more-familiar">
|
||||
</section>
|
||||
<section id="a-first-step-making-things-more-familiar">
|
||||
<h2>A first step making things more familiar<a class="headerlink" href="#a-first-step-making-things-more-familiar" title="Permalink to this headline">¶</a></h2>
|
||||
<p>We will here give two examples of customizing Evennia to be more familiar to a MUSH <em>Player</em>.</p>
|
||||
<div class="section" id="activating-a-multi-descer">
|
||||
<section id="activating-a-multi-descer">
|
||||
<h3>Activating a multi-descer<a class="headerlink" href="#activating-a-multi-descer" title="Permalink to this headline">¶</a></h3>
|
||||
<p>By default Evennia’s <code class="docutils literal notranslate"><span class="pre">desc</span></code> command updates your description and that’s it. There is a more feature-
|
||||
rich optional “multi-descer” in <code class="docutils literal notranslate"><span class="pre">evennia/contrib/multidesc.py</span></code> though. This alternative allows for
|
||||
|
|
@ -134,29 +135,29 @@ Open the module in a text editor. We won’t go into Evennia in-game <em>Command
|
|||
further here, but suffice to say Evennia allows you to change which commands (or versions of
|
||||
commands) are available to the player from moment to moment depending on circumstance.</p>
|
||||
<p>Add two new lines to the module as seen below:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># the file mygame/commands/default_cmdsets.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># the file mygame/commands/default_cmdsets.py</span>
|
||||
<span class="c1"># [...] </span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia.contrib</span> <span class="kn">import</span> <span class="n">multidescer</span> <span class="c1"># <- added now</span>
|
||||
|
|
@ -194,12 +195,12 @@ add it to the <code class="docutils literal notranslate"><span class="pre">Chara
|
|||
start. So we need to reload Evennia with <code class="docutils literal notranslate"><span class="pre">@reload</span></code> - no one will be disconnected by doing this. If
|
||||
all went well you should now be able to use <code class="docutils literal notranslate"><span class="pre">desc</span></code> (or <code class="docutils literal notranslate"><span class="pre">+desc</span></code>) and find that you have more
|
||||
possibilities:</p>
|
||||
<div class="highlight-text notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6</pre></div></td><td class="code"><div class="highlight"><pre><span></span>> help +desc # get help on the command
|
||||
<div class="highlight-text notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>> help +desc # get help on the command
|
||||
> +desc eyes = His eyes are blue.
|
||||
> +desc basic = A big guy.
|
||||
> +desc/set basic + + eyes # we add an extra space between
|
||||
|
|
@ -212,12 +213,12 @@ where the error occurred. Find where the error is by locating the line number re
|
|||
<code class="docutils literal notranslate"><span class="pre">default_cmdsets.py</span></code> file (it’s the only one you’ve changed so far). Most likely you mis-spelled
|
||||
something or missed the indentation. Fix it and either <code class="docutils literal notranslate"><span class="pre">@reload</span></code> again or run <code class="docutils literal notranslate"><span class="pre">evennia</span> <span class="pre">start</span></code> as
|
||||
needed.</p>
|
||||
</div>
|
||||
<div class="section" id="customizing-the-multidescer-syntax">
|
||||
</section>
|
||||
<section id="customizing-the-multidescer-syntax">
|
||||
<h3>Customizing the multidescer syntax<a class="headerlink" href="#customizing-the-multidescer-syntax" title="Permalink to this headline">¶</a></h3>
|
||||
<p>As seen above the multidescer uses syntax like this (where <code class="docutils literal notranslate"><span class="pre">|/</span></code> are Evennia’s tags for line breaks)
|
||||
:</p>
|
||||
<div class="highlight-text notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span>> +desc/set basic + |/|/ + cape + footwear + |/|/ + attitude
|
||||
<div class="highlight-text notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span>> +desc/set basic + |/|/ + cape + footwear + |/|/ + attitude
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>This use of <code class="docutils literal notranslate"><span class="pre">+</span> </code> was prescribed by the <em>Developer</em> that coded this <code class="docutils literal notranslate"><span class="pre">+desc</span></code> command. What if the
|
||||
|
|
@ -226,7 +227,7 @@ necessarily. While Evennia does not allow the player to build their own multi-de
|
|||
line, it does allow for <em>re-mapping</em> the command syntax to one they prefer. This is done using the
|
||||
<code class="docutils literal notranslate"><span class="pre">nick</span></code> command.</p>
|
||||
<p>Here’s a nick that changes how to input the command above:</p>
|
||||
<div class="highlight-text notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span>> nick setdesc $1 $2 $3 $4 = +desc/set $1 + |/|/ + $2 + $3 + |/|/ + $4
|
||||
<div class="highlight-text notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span>> nick setdesc $1 $2 $3 $4 = +desc/set $1 + |/|/ + $2 + $3 + |/|/ + $4
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>The string on the left will be matched against your input and if matching, it will be replaced with
|
||||
|
|
@ -234,14 +235,14 @@ the string on the right. The <code class="docutils literal notranslate"><span cl
|
|||
the replacement. The nick allows <a class="reference external" href="http://www.linfo.org/wildcard.html">shell-like wildcards</a>, so you
|
||||
can use <code class="docutils literal notranslate"><span class="pre">*</span></code>, <code class="docutils literal notranslate"><span class="pre">?</span></code>, <code class="docutils literal notranslate"><span class="pre">[...]</span></code>, <code class="docutils literal notranslate"><span class="pre">[!...]</span></code> etc to match parts of the input.</p>
|
||||
<p>The same description as before can now be set as</p>
|
||||
<div class="highlight-text notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span>> setdesc basic cape footwear attitude
|
||||
<div class="highlight-text notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span>> setdesc basic cape footwear attitude
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>With the <code class="docutils literal notranslate"><span class="pre">nick</span></code> functionality players can mitigate a lot of syntax dislikes even without the
|
||||
developer changing the underlying Python code.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="next-steps">
|
||||
</section>
|
||||
</section>
|
||||
<section id="next-steps">
|
||||
<h2>Next steps<a class="headerlink" href="#next-steps" title="Permalink to this headline">¶</a></h2>
|
||||
<p>If you are a <em>Developer</em> and are interested in making a more MUSH-like Evennia game, a good start is
|
||||
to look into the Evennia <a class="reference internal" href="Starting/Part3/Tutorial-for-basic-MUSH-like-game.html"><span class="doc">Tutorial for a first MUSH-like game</span></a>.
|
||||
|
|
@ -258,8 +259,8 @@ to try out. If you feel you want a more visual overview you can also look at
|
|||
<p>… And of course, if you need further help you can always drop into the <a class="reference external" href="http://webchat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRydWUmMTE9MTk1JjEyPXRydWUbb">Evennia
|
||||
chatroom</a>
|
||||
or post a question in our <a class="reference external" href="https://groups.google.com/forum/#%21forum/evennia">forum/mailing list</a>!</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Evennia for roleplaying sessions — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="evennia-for-roleplaying-sessions">
|
||||
<section id="evennia-for-roleplaying-sessions">
|
||||
<h1>Evennia for roleplaying sessions<a class="headerlink" href="#evennia-for-roleplaying-sessions" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This tutorial will explain how to set up a realtime or play-by-post tabletop style game using a
|
||||
fresh Evennia server.</p>
|
||||
|
|
@ -60,15 +61,15 @@ simultaneously, regardless of location.</p></li>
|
|||
</ul>
|
||||
<p>We will find most of these things are already part of vanilla Evennia, but that we can expand on the
|
||||
defaults for our particular use-case. Below we will flesh out these components from start to finish.</p>
|
||||
<div class="section" id="starting-out">
|
||||
<section id="starting-out">
|
||||
<h2>Starting out<a class="headerlink" href="#starting-out" title="Permalink to this headline">¶</a></h2>
|
||||
<p>We will assume you start from scratch. You need Evennia installed, as per the <a class="reference internal" href="../Setup/Setup-Quickstart.html"><span class="doc">Setup Quickstart</span></a>
|
||||
instructions. Initialize a new game directory with <code class="docutils literal notranslate"><span class="pre">evennia</span> <span class="pre">init</span> <span class="pre"><gamedirname></span></code>. In this tutorial we assume your game dir is simply named <code class="docutils literal notranslate"><span class="pre">mygame</span></code>. You can use the
|
||||
default database and keep all other settings to default for now. Familiarize yourself with the
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame</span></code> folder before continuing. You might want to browse the
|
||||
<a class="reference internal" href="Starting/Part1/Starting-Part1.html"><span class="doc">First Steps Coding</span></a> tutorial, just to see roughly where things are modified.</p>
|
||||
</div>
|
||||
<div class="section" id="the-game-master-role">
|
||||
</section>
|
||||
<section id="the-game-master-role">
|
||||
<h2>The Game Master role<a class="headerlink" href="#the-game-master-role" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In brief:</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -77,7 +78,7 @@ command.</p></li>
|
|||
<li><p>Better but more work: Make a custom command to set/unset the above, while tweaking the Character
|
||||
to show your renewed GM status to the other accounts.</p></li>
|
||||
</ul>
|
||||
<div class="section" id="the-permission-hierarchy">
|
||||
<section id="the-permission-hierarchy">
|
||||
<h3>The permission hierarchy<a class="headerlink" href="#the-permission-hierarchy" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Evennia has the following <a class="reference external" href="Concepts/Building-Permissions.html#assigning-permissions">permission hierarchy</a> out of
|
||||
the box: <em>Players, Helpers, Builders, Admins</em> and finally <em>Developers</em>. We could change these but
|
||||
|
|
@ -99,8 +100,8 @@ restart/shutdown the server as well as changing the permission levels.</p></li>
|
|||
<div><p>The <a class="reference external" href="Concepts/Building-Permissions.html#the-super-user">superuser</a> is not part of the hierarchy and actually
|
||||
completely bypasses it. We’ll assume server admin(s) will “just” be Developers.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="how-to-grant-permissions">
|
||||
</section>
|
||||
<section id="how-to-grant-permissions">
|
||||
<h3>How to grant permissions<a class="headerlink" href="#how-to-grant-permissions" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Only <code class="docutils literal notranslate"><span class="pre">Developers</span></code> can (by default) change permission level. Only they have access to the <code class="docutils literal notranslate"><span class="pre">@perm</span></code>
|
||||
command:</p>
|
||||
|
|
@ -119,8 +120,8 @@ command:</p>
|
|||
<p>There is no need to remove the basic <code class="docutils literal notranslate"><span class="pre">Players</span></code> permission when adding the higher permission: the
|
||||
highest will be used. Permission level names are <em>not</em> case sensitive. You can also use both plural
|
||||
and singular, so “Admins” gives the same powers as “Admin”.</p>
|
||||
</div>
|
||||
<div class="section" id="optional-making-a-gm-granting-command">
|
||||
</section>
|
||||
<section id="optional-making-a-gm-granting-command">
|
||||
<h3>Optional: Making a GM-granting command<a class="headerlink" href="#optional-making-a-gm-granting-command" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Use of <code class="docutils literal notranslate"><span class="pre">@perm</span></code> works out of the box, but it’s really the bare minimum. Would it not be nice if other
|
||||
accounts could tell at a glance who the GM is? Also, we shouldn’t really need to remember that the
|
||||
|
|
@ -132,39 +133,39 @@ permission level is called “Admins”. It would be easier if we could just do
|
|||
its name will have the string<code class="docutils literal notranslate"><span class="pre">(GM)</span></code> added to the end.</p></li>
|
||||
<li><p>We’ll add a new command, for the server admin to assign the GM-flag properly.</p></li>
|
||||
</ol>
|
||||
<div class="section" id="character-modification">
|
||||
<section id="character-modification">
|
||||
<h4>Character modification<a class="headerlink" href="#character-modification" title="Permalink to this headline">¶</a></h4>
|
||||
<p>Let’s first start by customizing the Character. We recommend you browse the beginning of the
|
||||
<a class="reference internal" href="../Components/Accounts.html"><span class="doc">Account</span></a> page to make sure you know how Evennia differentiates between the OOC “Account
|
||||
objects” (not to be confused with the <code class="docutils literal notranslate"><span class="pre">Accounts</span></code> permission, which is just a string specifying your
|
||||
access) and the IC “Character objects”.</p>
|
||||
<p>Open <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/characters.py</span></code> and modify the default <code class="docutils literal notranslate"><span class="pre">Character</span></code> class:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/typeclasses/characters.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/typeclasses/characters.py</span>
|
||||
|
||||
<span class="c1"># [...]</span>
|
||||
|
||||
|
|
@ -204,72 +205,72 @@ that is, it will show only to those in the same location. If we wanted it to als
|
|||
<code class="docutils literal notranslate"><span class="pre">who</span></code> listings and channels, we’d need to make a similar change to the <code class="docutils literal notranslate"><span class="pre">Account</span></code> typeclass in
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/accounts.py</span></code>. We leave this as an exercise to the reader.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="new-gm-ungm-command">
|
||||
</section>
|
||||
<section id="new-gm-ungm-command">
|
||||
<h4>New @gm/@ungm command<a class="headerlink" href="#new-gm-ungm-command" title="Permalink to this headline">¶</a></h4>
|
||||
<p>We will describe in some detail how to create and add an Evennia <a class="reference internal" href="../Components/Commands.html"><span class="doc">command</span></a> here with the
|
||||
hope that we don’t need to be as detailed when adding commands in the future. We will build on
|
||||
Evennia’s default “mux-like” commands here.</p>
|
||||
<p>Open <code class="docutils literal notranslate"><span class="pre">mygame/commands/command.py</span></code> and add a new Command class at the bottom:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/command.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/command.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span>
|
||||
|
||||
|
|
@ -340,16 +341,16 @@ to act accordingly. Either way works, practicality and coding style decides whic
|
|||
<p>To actually make this command available (only to Developers, due to the lock on it), we add it to
|
||||
the default Account command set. Open the file <code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code> and find the
|
||||
<code class="docutils literal notranslate"><span class="pre">AccountCmdSet</span></code> class:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/commands/default_cmdsets.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/commands/default_cmdsets.py</span>
|
||||
|
||||
<span class="c1"># [...]</span>
|
||||
<span class="kn">from</span> <span class="nn">commands.command</span> <span class="kn">import</span> <span class="n">CmdMakeGM</span>
|
||||
|
|
@ -363,10 +364,10 @@ the default Account command set. Open the file <code class="docutils literal not
|
|||
</td></tr></table></div>
|
||||
<p>Finally, issue the <code class="docutils literal notranslate"><span class="pre">@reload</span></code> command to update the server to your changes. Developer-level players
|
||||
(or the superuser) should now have the <code class="docutils literal notranslate"><span class="pre">@gm/@ungm</span></code> command available.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="character-sheet">
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
<section id="character-sheet">
|
||||
<h2>Character sheet<a class="headerlink" href="#character-sheet" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In brief:</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -375,7 +376,7 @@ the default Account command set. Open the file <code class="docutils literal not
|
|||
<li><p>Add new commands to modify the Character sheet, both by Accounts and GMs.</p></li>
|
||||
<li><p>Make the Character sheet lockable by a GM, so the Player can no longer modify it.</p></li>
|
||||
</ul>
|
||||
<div class="section" id="building-a-character-sheet">
|
||||
<section id="building-a-character-sheet">
|
||||
<h3>Building a Character sheet<a class="headerlink" href="#building-a-character-sheet" title="Permalink to this headline">¶</a></h3>
|
||||
<p>There are many ways to build a Character sheet in text, from manually pasting strings together to
|
||||
more automated ways. Exactly what is the best/easiest way depends on the sheet one tries to create.
|
||||
|
|
@ -385,22 +386,22 @@ Commands to edit and display the output from those utilities.</p>
|
|||
<div><p>Note that due to the limitations of the wiki, no color is used in any of the examples. See
|
||||
<a class="reference internal" href="../Concepts/TextTags.html"><span class="doc">the text tag documentation</span></a> for how to add color to the tables and forms.</p>
|
||||
</div></blockquote>
|
||||
<div class="section" id="making-a-sheet-with-evtable">
|
||||
<section id="making-a-sheet-with-evtable">
|
||||
<h4>Making a sheet with EvTable<a class="headerlink" href="#making-a-sheet-with-evtable" title="Permalink to this headline">¶</a></h4>
|
||||
<p><a class="reference external" href="https://github.com/evennia/evennia/blob/master/evennia.utils.evtable">EvTable</a> is a text-table generator. It helps with displaying text in
|
||||
ordered rows and columns. This is an example of using it in code:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># this can be tried out in a Python shell like iPython</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># this can be tried out in a Python shell like iPython</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia.utils</span> <span class="kn">import</span> <span class="n">evtable</span>
|
||||
|
||||
|
|
@ -422,18 +423,18 @@ could also retroactively add new columns and rows to it with <code class="docuti
|
|||
<code class="docutils literal notranslate"><span class="pre">table.add_column()</span></code>: if necessary the table will expand with empty rows/columns to always remain
|
||||
rectangular.</p>
|
||||
<p>The result from printing the above table will be</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="n">table_string</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">table</span><span class="p">)</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="n">table_string</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">table</span><span class="p">)</span>
|
||||
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">table_string</span><span class="p">)</span>
|
||||
|
||||
|
|
@ -450,11 +451,11 @@ rectangular.</p>
|
|||
<p>This is a minimalistic but effective Character sheet. By combining the <code class="docutils literal notranslate"><span class="pre">table_string</span></code> with other
|
||||
strings one could build up a reasonably full graphical representation of a Character. For more
|
||||
advanced layouts we’ll look into EvForm next.</p>
|
||||
</div>
|
||||
<div class="section" id="making-a-sheet-with-evform">
|
||||
</section>
|
||||
<section id="making-a-sheet-with-evform">
|
||||
<h4>Making a sheet with EvForm<a class="headerlink" href="#making-a-sheet-with-evform" title="Permalink to this headline">¶</a></h4>
|
||||
<p><a class="reference external" href="https://github.com/evennia/evennia/blob/master/evennia.utils.evform">EvForm</a> allows the creation of a two-dimensional “graphic” made by
|
||||
text characters. On this surface, one marks and tags rectangular regions (“cells”) to be filled with
|
||||
text characters. On this surface, one marks and tags rectangular regions (”cells”) to be filled with
|
||||
content. This content can be either normal strings or <code class="docutils literal notranslate"><span class="pre">EvTable</span></code> instances (see the previous section,
|
||||
one such instance would be the <code class="docutils literal notranslate"><span class="pre">table</span></code> variable in that example).</p>
|
||||
<p>In the case of a Character sheet, these cells would be comparable to a line or box where you could
|
||||
|
|
@ -467,32 +468,32 @@ too small for it, the EvTable will do its best to try to resize to fit, but will
|
|||
to cropping its data or even give an error if too small to fit any data.</p>
|
||||
<p>An EvForm is defined in a Python module. Create a new file <code class="docutils literal notranslate"><span class="pre">mygame/world/charsheetform.py</span></code> and
|
||||
modify it thus:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1">#coding=utf-8</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1">#coding=utf-8</span>
|
||||
|
||||
<span class="c1"># in mygame/world/charsheetform.py</span>
|
||||
|
||||
|
|
@ -532,24 +533,24 @@ would identify a cell/table. The smallest identifiable cell/table area is 3 char
|
|||
including the identifier (for example <code class="docutils literal notranslate"><span class="pre">x2x</span></code>).</p>
|
||||
</div></blockquote>
|
||||
<p>Now we will map content to this form.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># again, this can be tested in a Python shell</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># again, this can be tested in a Python shell</span>
|
||||
|
||||
<span class="c1"># hard-code this info here, later we'll ask the</span>
|
||||
<span class="c1"># account for this info. We will re-use the 'table'</span>
|
||||
|
|
@ -577,7 +578,7 @@ directly into the <code class="docutils literal notranslate"><span class="pre">E
|
|||
above. Note however that the very first line of the <code class="docutils literal notranslate"><span class="pre">FORM</span></code> string is ignored, so start with a <code class="docutils literal notranslate"><span class="pre">\n</span></code>.</p>
|
||||
</div></blockquote>
|
||||
<p>We then map those to the cells of the form:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="n">form</span><span class="p">)</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="n">form</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">.--------------------------------------.</span>
|
||||
|
|
@ -603,52 +604,52 @@ above. Note however that the very first line of the <code class="docutils litera
|
|||
where needed. We chose to just enter the Advantages/Disadvantages as plain strings here, meaning
|
||||
long names ended up split between rows. If we wanted more control over the display we could have
|
||||
inserted <code class="docutils literal notranslate"><span class="pre">\n</span></code> line breaks after each line or used a borderless <code class="docutils literal notranslate"><span class="pre">EvTable</span></code> to display those as well.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="tie-a-character-sheet-to-a-character">
|
||||
</section>
|
||||
</section>
|
||||
<section id="tie-a-character-sheet-to-a-character">
|
||||
<h3>Tie a Character sheet to a Character<a class="headerlink" href="#tie-a-character-sheet-to-a-character" title="Permalink to this headline">¶</a></h3>
|
||||
<p>We will assume we go with the <code class="docutils literal notranslate"><span class="pre">EvForm</span></code> example above. We now need to attach this to a Character so
|
||||
it can be modified. For this we will modify our <code class="docutils literal notranslate"><span class="pre">Character</span></code> class a little more:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/character.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/character.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia.utils</span> <span class="kn">import</span> <span class="n">evform</span><span class="p">,</span> <span class="n">evtable</span>
|
||||
|
||||
|
|
@ -697,80 +698,80 @@ The easiest to force an existing Character to re-fire its <code class="docutils
|
|||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@typeclass</span><span class="o">/</span><span class="n">force</span> <span class="o"><</span><span class="n">Character</span> <span class="n">Name</span><span class="o">></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="command-for-account-to-change-character-sheet">
|
||||
</section>
|
||||
<section id="command-for-account-to-change-character-sheet">
|
||||
<h3>Command for Account to change Character sheet<a class="headerlink" href="#command-for-account-to-change-character-sheet" title="Permalink to this headline">¶</a></h3>
|
||||
<p>We will add a command to edit the sections of our Character sheet. Open
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/commands/command.py</span></code>.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># at the end of mygame/commands/command.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span>
|
||||
<span class="normal">60</span>
|
||||
<span class="normal">61</span>
|
||||
<span class="normal">62</span>
|
||||
<span class="normal">63</span>
|
||||
<span class="normal">64</span>
|
||||
<span class="normal">65</span>
|
||||
<span class="normal">66</span>
|
||||
<span class="normal">67</span>
|
||||
<span class="normal">68</span>
|
||||
<span class="normal">69</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># at the end of mygame/commands/command.py</span>
|
||||
|
||||
<span class="n">ALLOWED_ATTRS</span> <span class="o">=</span> <span class="p">(</span><span class="s2">"str"</span><span class="p">,</span> <span class="s2">"con"</span><span class="p">,</span> <span class="s2">"dex"</span><span class="p">,</span> <span class="s2">"int"</span><span class="p">,</span> <span class="s2">"wis"</span><span class="p">,</span> <span class="s2">"cha"</span><span class="p">)</span>
|
||||
<span class="n">ALLOWED_FIELDNAMES</span> <span class="o">=</span> <span class="n">ALLOWED_ATTRS</span> <span class="o">+</span> \
|
||||
|
|
@ -845,84 +846,84 @@ The easiest to force an existing Character to re-fire its <code class="docutils
|
|||
<code class="docutils literal notranslate"><span class="pre">sheet_locked</span></code> Attribute is checked and will return if not set.</p>
|
||||
<p>This command you import into <code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code> and add to the <code class="docutils literal notranslate"><span class="pre">CharacterCmdSet</span></code>,
|
||||
in the same way the <code class="docutils literal notranslate"><span class="pre">@gm</span></code> command was added to the <code class="docutils literal notranslate"><span class="pre">AccountCmdSet</span></code> earlier.</p>
|
||||
</div>
|
||||
<div class="section" id="commands-for-gm-to-change-character-sheet">
|
||||
</section>
|
||||
<section id="commands-for-gm-to-change-character-sheet">
|
||||
<h3>Commands for GM to change Character sheet<a class="headerlink" href="#commands-for-gm-to-change-character-sheet" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Game masters use basically the same input as Players do to edit a character sheet, except they can
|
||||
do it on other players than themselves. They are also not stopped by any <code class="docutils literal notranslate"><span class="pre">sheet_locked</span></code> flags.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69
|
||||
70
|
||||
71
|
||||
72
|
||||
73</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># continuing in mygame/commands/command.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span>
|
||||
<span class="normal">60</span>
|
||||
<span class="normal">61</span>
|
||||
<span class="normal">62</span>
|
||||
<span class="normal">63</span>
|
||||
<span class="normal">64</span>
|
||||
<span class="normal">65</span>
|
||||
<span class="normal">66</span>
|
||||
<span class="normal">67</span>
|
||||
<span class="normal">68</span>
|
||||
<span class="normal">69</span>
|
||||
<span class="normal">70</span>
|
||||
<span class="normal">71</span>
|
||||
<span class="normal">72</span>
|
||||
<span class="normal">73</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># continuing in mygame/commands/command.py</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdGMsheet</span><span class="p">(</span><span class="n">MuxCommand</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -1002,9 +1003,9 @@ edit. It also takes <code class="docutils literal notranslate"><span class="pre"
|
|||
<p>Before this can be used, it should be added to the default <code class="docutils literal notranslate"><span class="pre">CharacterCmdSet</span></code> in the same way as the
|
||||
normal <code class="docutils literal notranslate"><span class="pre">@sheet</span></code>. Due to the lock set on it, this command will only be available to <code class="docutils literal notranslate"><span class="pre">Admins</span></code> (i.e.
|
||||
GMs) or higher permission levels.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="dice-roller">
|
||||
</section>
|
||||
</section>
|
||||
<section id="dice-roller">
|
||||
<h2>Dice roller<a class="headerlink" href="#dice-roller" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Evennia’s <em>contrib</em> folder already comes with a full dice roller. To add it to the game, simply
|
||||
import <code class="docutils literal notranslate"><span class="pre">contrib.dice.CmdDice</span></code> into <code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code> and add <code class="docutils literal notranslate"><span class="pre">CmdDice</span></code> to the
|
||||
|
|
@ -1016,8 +1017,8 @@ to roll dice using normal RPG-style format:</p>
|
|||
</div>
|
||||
<p>Use <code class="docutils literal notranslate"><span class="pre">help</span> <span class="pre">dice</span></code> to see what syntax is supported or look at <code class="docutils literal notranslate"><span class="pre">evennia/contrib/dice.py</span></code> to see how it’s
|
||||
implemented.</p>
|
||||
</div>
|
||||
<div class="section" id="rooms">
|
||||
</section>
|
||||
<section id="rooms">
|
||||
<h2>Rooms<a class="headerlink" href="#rooms" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Evennia comes with rooms out of the box, so no extra work needed. A GM will automatically have all
|
||||
needed building commands available. A fuller go-through is found in the <a class="reference internal" href="Starting/Part1/Building-Quickstart.html"><span class="doc">Building tutorial</span></a>.
|
||||
|
|
@ -1037,8 +1038,8 @@ builds “matching” exits back in the opposite direction.</p></li>
|
|||
<div><p>TODO: Describe how to add a logging room, that logs says and poses to a log file that people can
|
||||
access after the fact.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="channels">
|
||||
</section>
|
||||
<section id="channels">
|
||||
<h2>Channels<a class="headerlink" href="#channels" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Evennia comes with <a class="reference external" href="Components/Communications.html#Channels">Channels</a> in-built and they are described fully in the
|
||||
documentation. For brevity, here are the relevant commands for normal use:</p>
|
||||
|
|
@ -1054,8 +1055,8 @@ set up for them.</p></li>
|
|||
<p>You can read channel history: if you for example are chatting on the <code class="docutils literal notranslate"><span class="pre">public</span></code> channel you can do
|
||||
<code class="docutils literal notranslate"><span class="pre">public/history</span></code> to see the 20 last posts to that channel or <code class="docutils literal notranslate"><span class="pre">public/history</span> <span class="pre">32</span></code> to view twenty
|
||||
posts backwards, starting with the 32nd from the end.</p>
|
||||
</div>
|
||||
<div class="section" id="pms">
|
||||
</section>
|
||||
<section id="pms">
|
||||
<h2>PMs<a class="headerlink" href="#pms" title="Permalink to this headline">¶</a></h2>
|
||||
<p>To send PMs to one another, players can use the <code class="docutils literal notranslate"><span class="pre">@page</span></code> (or <code class="docutils literal notranslate"><span class="pre">tell</span></code>) command:</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">page</span> <span class="n">recipient</span> <span class="o">=</span> <span class="n">message</span>
|
||||
|
|
@ -1064,8 +1065,8 @@ posts backwards, starting with the 32nd from the end.</p>
|
|||
</div>
|
||||
<p>Players can use <code class="docutils literal notranslate"><span class="pre">page</span></code> alone to see the latest messages. This also works if they were not online
|
||||
when the message was sent.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Gametime Tutorial — 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" />
|
||||
|
|
@ -37,14 +38,14 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="gametime-tutorial">
|
||||
<section id="gametime-tutorial">
|
||||
<h1>Gametime Tutorial<a class="headerlink" href="#gametime-tutorial" title="Permalink to this headline">¶</a></h1>
|
||||
<p>A lot of games use a separate time system we refer to as <em>game time</em>. This runs in parallel to what
|
||||
we usually think of as <em>real time</em>. The game time might run at a different speed, use different
|
||||
names for its time units or might even use a completely custom calendar. You don’t need to rely on a
|
||||
game time system at all. But if you do, Evennia offers basic tools to handle these various
|
||||
situations. This tutorial will walk you through these features.</p>
|
||||
<div class="section" id="a-game-time-with-a-standard-calendar">
|
||||
<section id="a-game-time-with-a-standard-calendar">
|
||||
<h2>A game time with a standard calendar<a class="headerlink" href="#a-game-time-with-a-standard-calendar" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Many games let their in-game time run faster or slower than real time, but still use our normal
|
||||
real-world calendar. This is common both for games set in present day as well as for games in
|
||||
|
|
@ -57,20 +58,20 @@ automatically handled by the system.</p></li>
|
|||
</ul>
|
||||
<p>Evennia’s game time features assume a standard calendar (see the relevant section below for a custom
|
||||
calendar).</p>
|
||||
<div class="section" id="setting-up-game-time-for-a-standard-calendar">
|
||||
<section id="setting-up-game-time-for-a-standard-calendar">
|
||||
<h3>Setting up game time for a standard calendar<a class="headerlink" href="#setting-up-game-time-for-a-standard-calendar" title="Permalink to this headline">¶</a></h3>
|
||||
<p>All is done through the settings. Here are the settings you should use if you want a game time with
|
||||
a standard calendar:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
|
||||
<span class="c1"># The time factor dictates if the game world runs faster (timefactor>1)</span>
|
||||
<span class="c1"># or slower (timefactor<1) than the real world.</span>
|
||||
<span class="n">TIME_FACTOR</span> <span class="o">=</span> <span class="mf">2.0</span>
|
||||
|
|
@ -91,12 +92,12 @@ real time, a minute in real time would be an hour in game time).</p>
|
|||
indicate the time your game started. As indicated, an epoch of 0 would mean January 1st, 1970. If
|
||||
you want to set your time in the future, you just need to find the starting point in seconds. There
|
||||
are several ways to do this in Python, this method will show you how to do it in local time:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># We're looking for the number of seconds representing</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># We're looking for the number of seconds representing</span>
|
||||
<span class="c1"># January 1st, 2020</span>
|
||||
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
|
||||
<span class="kn">import</span> <span class="nn">time</span>
|
||||
|
|
@ -106,8 +107,8 @@ are several ways to do this in Python, this method will show you how to do it in
|
|||
</td></tr></table></div>
|
||||
<p>This should return a huge number - the number of seconds since Jan 1 1970. Copy that directly into
|
||||
your settings (editing <code class="docutils literal notranslate"><span class="pre">server/conf/settings.py</span></code>):</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
||||
<span class="normal">2</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
|
||||
<span class="n">TIME_GAME_EPOCH</span> <span class="o">=</span> <span class="mi">1577865600</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
|
|
@ -132,8 +133,8 @@ this:</p>
|
|||
<p>The line that is most relevant here is the game time epoch. You see it shown at 2020-01-01. From
|
||||
this point forward, the game time keeps increasing. If you keep typing <code class="docutils literal notranslate"><span class="pre">@time</span></code>, you’ll see the game
|
||||
time updated correctly… and going (by default) twice as fast as the real time.</p>
|
||||
</div>
|
||||
<div class="section" id="time-related-events">
|
||||
</section>
|
||||
<section id="time-related-events">
|
||||
<h3>Time-related events<a class="headerlink" href="#time-related-events" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">gametime</span></code> utility also has a way to schedule game-related events, taking into account your game
|
||||
time, and assuming a standard calendar (see below for the same feature with a custom calendar). For
|
||||
|
|
@ -151,21 +152,21 @@ repeatedly.</p></li>
|
|||
to schedule. If the parameter isn’t given, it assumes the current time value of this specific unit.</p></li>
|
||||
</ul>
|
||||
<p>Here is a short example for making the sun rise every day:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file ingame_time.py in mygame/world/</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file ingame_time.py in mygame/world/</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia.utils</span> <span class="kn">import</span> <span class="n">gametime</span>
|
||||
<span class="kn">from</span> <span class="nn">typeclasses.rooms</span> <span class="kn">import</span> <span class="n">Room</span>
|
||||
|
|
@ -202,9 +203,9 @@ real-life calendar you need to be careful when scheduling events for the end of
|
|||
For example, if you set a script to run every month on the 31st it will run in January but find no
|
||||
such day in February, April etc. Similarly, leap years may change the number of days in the year.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="a-game-time-with-a-custom-calendar">
|
||||
</section>
|
||||
</section>
|
||||
<section id="a-game-time-with-a-custom-calendar">
|
||||
<h2>A game time with a custom calendar<a class="headerlink" href="#a-game-time-with-a-custom-calendar" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Using a custom calendar to handle game time is sometimes needed if you want to place your game in a
|
||||
fictional universe. For instance you may want to create the Shire calendar which Tolkien described
|
||||
|
|
@ -214,7 +215,7 @@ creating a planet in a different solar system with, say, days 29 hours long and
|
|||
days.</p>
|
||||
<p>Evennia handles custom calendars through an optional <em>contrib</em> module, called <code class="docutils literal notranslate"><span class="pre">custom_gametime</span></code>.
|
||||
Contrary to the normal <code class="docutils literal notranslate"><span class="pre">gametime</span></code> module described above it is not active by default.</p>
|
||||
<div class="section" id="setting-up-the-custom-calendar">
|
||||
<section id="setting-up-the-custom-calendar">
|
||||
<h3>Setting up the custom calendar<a class="headerlink" href="#setting-up-the-custom-calendar" title="Permalink to this headline">¶</a></h3>
|
||||
<p>In our first example of the Shire calendar, used by hobbits in books by Tolkien, we don’t really
|
||||
need the notion of weeks… but we need the notion of months having 30 days, not 28.</p>
|
||||
|
|
@ -223,13 +224,13 @@ dictionary containing as keys the name of the units, and as value the number of
|
|||
smallest unit for us) in this unit. Its keys must be picked among the following: “sec”, “min”,
|
||||
“hour”, “day”, “week”, “month” and “year” but you don’t have to include them all. Here is the
|
||||
configuration for the Shire calendar:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
|
||||
<span class="n">TIME_UNITS</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"sec"</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
|
||||
<span class="s2">"min"</span><span class="p">:</span> <span class="mi">60</span><span class="p">,</span>
|
||||
<span class="s2">"hour"</span><span class="p">:</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">60</span><span class="p">,</span>
|
||||
|
|
@ -244,22 +245,22 @@ configuration: instead, we skip from days to months directly.</p>
|
|||
<p>In order for this setting to work properly, remember all units have to be multiples of the previous
|
||||
units. If you create “day”, it needs to be multiple of hours, for instance.</p>
|
||||
<p>So for our example, our settings may look like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
|
||||
<span class="c1"># Time factor</span>
|
||||
<span class="n">TIME_FACTOR</span> <span class="o">=</span> <span class="mi">4</span>
|
||||
|
||||
|
|
@ -282,40 +283,40 @@ of time on our own. In our case the game time starts at year 0, month 0, day 0,
|
|||
<p>Note that while we use “month”, “week” etc in the settings, your game may not use those terms in-
|
||||
game, instead referring to them as “cycles”, “moons”, “sand falls” etc. This is just a matter of you
|
||||
displaying them differently. See next section.</p>
|
||||
</div>
|
||||
<div class="section" id="a-command-to-display-the-current-game-time">
|
||||
</section>
|
||||
<section id="a-command-to-display-the-current-game-time">
|
||||
<h3>A command to display the current game time<a class="headerlink" href="#a-command-to-display-the-current-game-time" title="Permalink to this headline">¶</a></h3>
|
||||
<p>As pointed out earlier, the <code class="docutils literal notranslate"><span class="pre">@time</span></code> command is meant to be used with a standard calendar, not a
|
||||
custom one. We can easily create a new command though. We’ll call it <code class="docutils literal notranslate"><span class="pre">time</span></code>, as is often the case
|
||||
on other MU*. Here’s an example of how we could write it (for the example, you can create a file
|
||||
<code class="docutils literal notranslate"><span class="pre">showtime.py</span></code> in your <code class="docutils literal notranslate"><span class="pre">commands</span></code> directory and paste this code in it):</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file mygame/commands/gametime.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file mygame/commands/gametime.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia.contrib</span> <span class="kn">import</span> <span class="n">custom_gametime</span>
|
||||
|
||||
|
|
@ -345,27 +346,27 @@ on other MU*. Here’s an example of how we could write it (for the example, yo
|
|||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>Don’t forget to add it in your CharacterCmdSet to see this command:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/default_cmdset.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/default_cmdset.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">commands.gametime</span> <span class="kn">import</span> <span class="n">CmdTime</span> <span class="c1"># <-- Add </span>
|
||||
|
||||
|
|
@ -396,16 +397,16 @@ it, you might see something like:</p>
|
|||
</div>
|
||||
<p>You could display it a bit more prettily with names for months and perhaps even days, if you want.
|
||||
And if “months” are called “moons” in your game, this is where you’d add that.</p>
|
||||
</div>
|
||||
<div class="section" id="time-related-events-in-custom-gametime">
|
||||
</section>
|
||||
<section id="time-related-events-in-custom-gametime">
|
||||
<h3>Time-related events in custom gametime<a class="headerlink" href="#time-related-events-in-custom-gametime" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">custom_gametime</span></code> module also has a way to schedule game-related events, taking into account
|
||||
your game time (and your custom calendar). It can be used to have a specific message every day at
|
||||
6:00 AM, to show the sun rises, for instance. The <code class="docutils literal notranslate"><span class="pre">custom_gametime.schedule</span></code> function works in the
|
||||
same way as described for the default one above.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Help System Tutorial — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="help-system-tutorial">
|
||||
<section id="help-system-tutorial">
|
||||
<h1>Help System Tutorial<a class="headerlink" href="#help-system-tutorial" title="Permalink to this headline">¶</a></h1>
|
||||
<p><strong>Before doing this tutorial you will probably want to read the intro in [Basic Web tutorial](Web-
|
||||
Tutorial).</strong> Reading the three first parts of the <a class="reference external" href="https://docs.djangoproject.com/en/1.9/intro/tutorial01/">Django
|
||||
|
|
@ -51,7 +52,7 @@ and regular help entries will be visible, depending on the logged-in user or an
|
|||
<li><p>Access the help system on your website.</p></li>
|
||||
<li><p>Identify whether the viewer of this page is logged-in and, if so, to what account.</p></li>
|
||||
</ul>
|
||||
<div class="section" id="creating-our-app">
|
||||
<section id="creating-our-app">
|
||||
<h2>Creating our app<a class="headerlink" href="#creating-our-app" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The first step is to create our new Django <em>app</em>. An app in Django can contain pages and
|
||||
mechanisms: your website may contain different apps. Actually, the website provided out-of-the-box
|
||||
|
|
@ -83,10 +84,10 @@ tutorial</a>.</p>
|
|||
<p>There is a last thing to be done: your folder has been added, but Django doesn’t know about it, it
|
||||
doesn’t know it’s a new app. We need to tell it, and we do so by editing a simple setting. Open
|
||||
your “server/conf/settings.py” file and add, or edit, these lines:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># Web configuration</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># Web configuration</span>
|
||||
<span class="n">INSTALLED_APPS</span> <span class="o">+=</span> <span class="p">(</span>
|
||||
<span class="s2">"web.help_system"</span><span class="p">,</span>
|
||||
<span class="p">)</span>
|
||||
|
|
@ -95,8 +96,8 @@ your “server/conf/settings.py” file and add, or edit, these lines:</p>
|
|||
<p>You can start Evennia if you want, and go to your website, probably at
|
||||
<a class="reference external" href="http://localhost:4001">http://localhost:4001</a> . You won’t see anything different though: we added
|
||||
the app but it’s fairly empty.</p>
|
||||
</div>
|
||||
<div class="section" id="our-new-page">
|
||||
</section>
|
||||
<section id="our-new-page">
|
||||
<h2>Our new page<a class="headerlink" href="#our-new-page" title="Permalink to this headline">¶</a></h2>
|
||||
<p>At this point, our new <em>app</em> contains mostly empty files that you can explore. In order to create
|
||||
a page for our help system, we need to add:</p>
|
||||
|
|
@ -109,18 +110,18 @@ a page for our help system, we need to add:</p>
|
|||
<div><p>We could get away by creating just a view and a new URL, but that’s not a recommended way to work
|
||||
with your website. Building on templates is so much more convenient.</p>
|
||||
</div></blockquote>
|
||||
<div class="section" id="create-a-view">
|
||||
<section id="create-a-view">
|
||||
<h3>Create a view<a class="headerlink" href="#create-a-view" title="Permalink to this headline">¶</a></h3>
|
||||
<p>A <em>view</em> in Django is a simple Python function placed in the “views.py” file in your app. It will
|
||||
handle the behavior that is triggered when a user asks for this information by entering a <em>URL</em> (the
|
||||
connection between <em>views</em> and <em>URLs</em> will be discussed later).</p>
|
||||
<p>So let’s create our view. You can open the “web/help_system/view.py” file and paste the following
|
||||
lines:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">render</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">render</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
|
||||
<span class="sd">"""The 'index' view."""</span>
|
||||
|
|
@ -129,8 +130,8 @@ lines:</p>
|
|||
</td></tr></table></div>
|
||||
<p>Our view handles all code logic. This time, there’s not much: when this function is called, it will
|
||||
render the template we will now create. But that’s where we will do most of our work afterward.</p>
|
||||
</div>
|
||||
<div class="section" id="create-a-template">
|
||||
</section>
|
||||
<section id="create-a-template">
|
||||
<h3>Create a template<a class="headerlink" href="#create-a-template" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">render</span></code> function called into our <em>view</em> asks the <em>template</em> <code class="docutils literal notranslate"><span class="pre">help_system/index.html</span></code>. The
|
||||
<em>templates</em> of our apps are stored in the app directory, “templates” sub-directory. Django may have
|
||||
|
|
@ -167,20 +168,20 @@ web page. This block is bigger, so we define it on several lines.</p></li>
|
|||
<li><p>This is perfectly normal HTML code to display a level-2 heading.</p></li>
|
||||
<li><p>And finally we close the <em>block</em> named “content”.</p></li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section" id="create-a-new-url">
|
||||
</section>
|
||||
<section id="create-a-new-url">
|
||||
<h3>Create a new URL<a class="headerlink" href="#create-a-new-url" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Last step to add our page: we need to add a <em>URL</em> leading to it… otherwise users won’t be able to
|
||||
access it. The URLs of our apps are stored in the app’s directory “urls.py” file.</p>
|
||||
<p>Open the “web/help_system/urls.py” file (you might have to create it) and write in it:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># URL patterns for the help_system app</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># URL patterns for the help_system app</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">url</span>
|
||||
<span class="kn">from</span> <span class="nn">web.help_system.views</span> <span class="kn">import</span> <span class="n">index</span>
|
||||
|
|
@ -192,10 +193,10 @@ access it. The URLs of our apps are stored in the app’s directory “urls.py
|
|||
</td></tr></table></div>
|
||||
<p>We also need to add our app as a namespace holder for URLS. Edit the file “web/urls.py”. In it you
|
||||
will find the <code class="docutils literal notranslate"><span class="pre">custom_patterns</span></code> variable. Replace it with:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="n">custom_patterns</span> <span class="o">=</span> <span class="p">[</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="n">custom_patterns</span> <span class="o">=</span> <span class="p">[</span>
|
||||
<span class="n">url</span><span class="p">(</span><span class="sa">r</span><span class="s1">'^help/'</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s1">'web.help_system.urls'</span><span class="p">,</span>
|
||||
<span class="n">namespace</span><span class="o">=</span><span class="s1">'help_system'</span><span class="p">,</span> <span class="n">app_name</span><span class="o">=</span><span class="s1">'help_system'</span><span class="p">)),</span>
|
||||
<span class="p">]</span>
|
||||
|
|
@ -210,17 +211,17 @@ describes to Django that all URLs beginning by ‘help/’ should be sent to the
|
|||
empty (<code class="docutils literal notranslate"><span class="pre">^$</span></code>).</p></li>
|
||||
</ol>
|
||||
<p>In other words, if the URL is ‘/help/’, then Django will execute our defined view.</p>
|
||||
</div>
|
||||
<div class="section" id="let-s-see-it-work">
|
||||
</section>
|
||||
<section id="let-s-see-it-work">
|
||||
<h3>Let’s see it work<a class="headerlink" href="#let-s-see-it-work" title="Permalink to this headline">¶</a></h3>
|
||||
<p>You can now reload or start Evennia. Open a tab in your browser and go to
|
||||
<a class="reference external" href="http://localhost:4001/help/">http://localhost:4001/help/</a> . If everything goes well, you should
|
||||
see your new page… which isn’t empty since Evennia uses our “base.html” <em>template</em>. In the
|
||||
content of our page, there’s only a heading that reads “help index”. Notice that the title of our
|
||||
page is “mygame - Help index” (“mygame” is replaced by the name of your game).</p>
|
||||
page is “mygame - Help index” (”mygame” is replaced by the name of your game).</p>
|
||||
<p>From now on, it will be easier to move forward and add features.</p>
|
||||
</div>
|
||||
<div class="section" id="a-brief-reminder">
|
||||
</section>
|
||||
<section id="a-brief-reminder">
|
||||
<h3>A brief reminder<a class="headerlink" href="#a-brief-reminder" title="Permalink to this headline">¶</a></h3>
|
||||
<p>We’ll be trying the following things:</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -246,9 +247,9 @@ problem. I have decided to use a <em>GET variable</em> here, which would create
|
|||
</div>
|
||||
<p>If you use this system, you don’t have to add a new URL: GET and POST variables are accessible
|
||||
through our requests and we’ll see how soon enough.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="handling-logged-in-users">
|
||||
</section>
|
||||
</section>
|
||||
<section id="handling-logged-in-users">
|
||||
<h2>Handling logged-in users<a class="headerlink" href="#handling-logged-in-users" title="Permalink to this headline">¶</a></h2>
|
||||
<p>One of our requirements is to have a help system tailored to our accounts. If an account with admin
|
||||
access logs in, the page should display a lot of commands that aren’t accessible to common users.
|
||||
|
|
@ -261,11 +262,11 @@ anonymous Django user. We then can use the <code class="docutils literal notran
|
|||
in or not. Last gift by Evennia, if the user is logged in, <code class="docutils literal notranslate"><span class="pre">request.user</span></code> contains a reference to
|
||||
an account object, which will help us a lot in coupling the game and online system.</p>
|
||||
<p>So we might end up with something like:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
|
||||
<span class="sd">"""The 'index' view."""</span>
|
||||
<span class="n">user</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span>
|
||||
<span class="k">if</span> <span class="ow">not</span> <span class="n">user</span><span class="o">.</span><span class="n">is_anonymous</span><span class="p">()</span> <span class="ow">and</span> <span class="n">user</span><span class="o">.</span><span class="n">character</span><span class="p">:</span>
|
||||
|
|
@ -276,11 +277,11 @@ an account object, which will help us a lot in coupling the game and online syst
|
|||
<div><p>Note: this code works when your MULTISESSION_MODE is set to 0 or 1. When it’s above, you would
|
||||
have something like:</p>
|
||||
</div></blockquote>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
|
||||
<span class="sd">"""The 'index' view."""</span>
|
||||
<span class="n">user</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span>
|
||||
<span class="k">if</span> <span class="ow">not</span> <span class="n">user</span><span class="o">.</span><span class="n">is_anonymous</span><span class="p">()</span> <span class="ow">and</span> <span class="n">user</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">_playable_characters</span><span class="p">:</span>
|
||||
|
|
@ -299,15 +300,15 @@ create it through your game: connect to it and enter:</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>So in our view, we could have something like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typeclasses.characters</span> <span class="kn">import</span> <span class="n">Character</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typeclasses.characters</span> <span class="kn">import</span> <span class="n">Character</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
|
||||
<span class="sd">"""The 'index' view."""</span>
|
||||
|
|
@ -320,99 +321,99 @@ create it through your game: connect to it and enter:</p>
|
|||
</td></tr></table></div>
|
||||
<p>This time, we have a valid character no matter what: remember to adapt this code if you’re running
|
||||
in multisession mode above 1.</p>
|
||||
</div>
|
||||
<div class="section" id="the-full-system">
|
||||
</section>
|
||||
<section id="the-full-system">
|
||||
<h2>The full system<a class="headerlink" href="#the-full-system" title="Permalink to this headline">¶</a></h2>
|
||||
<p>What we’re going to do is to browse through all commands and help entries, and list all the commands
|
||||
that can be seen by this character (either our ‘anonymous’ character, or our logged-in character).</p>
|
||||
<p>The code is longer, but it presents the entire concept in our view. Edit the
|
||||
“web/help_system/views.py” file and paste into it:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69
|
||||
70
|
||||
71
|
||||
72
|
||||
73
|
||||
74
|
||||
75
|
||||
76
|
||||
77
|
||||
78
|
||||
79
|
||||
80
|
||||
81
|
||||
82
|
||||
83
|
||||
84
|
||||
85
|
||||
86</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.http</span> <span class="kn">import</span> <span class="n">Http404</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span>
|
||||
<span class="normal">60</span>
|
||||
<span class="normal">61</span>
|
||||
<span class="normal">62</span>
|
||||
<span class="normal">63</span>
|
||||
<span class="normal">64</span>
|
||||
<span class="normal">65</span>
|
||||
<span class="normal">66</span>
|
||||
<span class="normal">67</span>
|
||||
<span class="normal">68</span>
|
||||
<span class="normal">69</span>
|
||||
<span class="normal">70</span>
|
||||
<span class="normal">71</span>
|
||||
<span class="normal">72</span>
|
||||
<span class="normal">73</span>
|
||||
<span class="normal">74</span>
|
||||
<span class="normal">75</span>
|
||||
<span class="normal">76</span>
|
||||
<span class="normal">77</span>
|
||||
<span class="normal">78</span>
|
||||
<span class="normal">79</span>
|
||||
<span class="normal">80</span>
|
||||
<span class="normal">81</span>
|
||||
<span class="normal">82</span>
|
||||
<span class="normal">83</span>
|
||||
<span class="normal">84</span>
|
||||
<span class="normal">85</span>
|
||||
<span class="normal">86</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.http</span> <span class="kn">import</span> <span class="n">Http404</span>
|
||||
<span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">render</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia.help.models</span> <span class="kn">import</span> <span class="n">HelpEntry</span>
|
||||
|
||||
|
|
@ -521,7 +522,7 @@ are stored in a dictionary. This is to simplify our job when displaying them in
|
|||
<p>Notice that, in both cases when we asked to render a <em>template</em>, we passed to <code class="docutils literal notranslate"><span class="pre">render</span></code> a third
|
||||
argument which is the dictionary of variables used in our templates. We can pass variables this
|
||||
way, and we will use them in our templates.</p>
|
||||
<div class="section" id="the-index-template">
|
||||
<section id="the-index-template">
|
||||
<h3>The index template<a class="headerlink" href="#the-index-template" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Let’s look at our full “index” <em>template</em>. You can open the
|
||||
“web/help_system/templates/help_sstem/index.html” file and paste the following into it:</p>
|
||||
|
|
@ -560,8 +561,8 @@ table will have 5 columns at the most per row.</p></li>
|
|||
URL would look something like “help?name=say”. We use <code class="docutils literal notranslate"><span class="pre">urlencode</span></code> to ensure special characters are
|
||||
properly escaped.</p></li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section" id="the-detail-template">
|
||||
</section>
|
||||
<section id="the-detail-template">
|
||||
<h3>The detail template<a class="headerlink" href="#the-detail-template" title="Permalink to this headline">¶</a></h3>
|
||||
<p>It’s now time to show the detail of a topic (command or help entry). You can create the file
|
||||
“web/help_system/templates/help_system/detail.html”. You can paste into it the following code:</p>
|
||||
|
|
@ -576,17 +577,17 @@ properly escaped.</p></li>
|
|||
</div>
|
||||
<p>This template is much easier to read. Some <em>filters</em> might be unknown to you, but they are just
|
||||
used to format here.</p>
|
||||
</div>
|
||||
<div class="section" id="put-it-all-together">
|
||||
</section>
|
||||
<section id="put-it-all-together">
|
||||
<h3>Put it all together<a class="headerlink" href="#put-it-all-together" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Remember to reload or start Evennia, and then go to
|
||||
<a class="reference external" href="http://localhost:4001/help/">http://localhost:4001/help</a>. You should see the list of commands and
|
||||
topics accessible by all characters. Try to login (click the “login” link in the menu of your
|
||||
website) and go to the same page again. You should now see a more detailed list of commands and
|
||||
help entries. Click on one to see its detail.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="to-improve-this-feature">
|
||||
</section>
|
||||
</section>
|
||||
<section id="to-improve-this-feature">
|
||||
<h2>To improve this feature<a class="headerlink" href="#to-improve-this-feature" title="Permalink to this headline">¶</a></h2>
|
||||
<p>As always, a tutorial is here to help you feel comfortable adding new features and code by yourself.
|
||||
Here are some ideas of things to improve this little feature:</p>
|
||||
|
|
@ -599,8 +600,8 @@ enter the URL, users won’t guess it’s there.</p></li>
|
|||
you see a help entry about how to use several commands, it would be great if these commands were
|
||||
themselves links to display their details.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Tutorials and Howto’s — 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" />
|
||||
|
|
@ -45,19 +46,19 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="tutorials-and-howto-s">
|
||||
<section id="tutorials-and-howto-s">
|
||||
<h1>Tutorials and Howto’s<a class="headerlink" href="#tutorials-and-howto-s" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The documents in this section aims to teach how to use Evennia in a tutorial or
|
||||
a step-by-step way. They often give hints on about solving a problem or implementing
|
||||
a particular feature or concept. They will often refer to the
|
||||
<a class="reference internal" href="../Components/Components-Overview.html"><span class="doc">components</span></a> or <a class="reference internal" href="../Concepts/Concepts-Overview.html"><span class="doc">concepts</span></a>
|
||||
docs for those that want to dive deeper.</p>
|
||||
<div class="section" id="the-starting-tutorial">
|
||||
<section id="the-starting-tutorial">
|
||||
<h2>The Starting Tutorial<a class="headerlink" href="#the-starting-tutorial" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Recommended starting point! This will take you from absolute beginner to making
|
||||
a small, but full, game with Evennia. Even if you have a very different game style
|
||||
in mind for your own game, this will give you a good start.</p>
|
||||
<div class="section" id="part-1-what-we-have">
|
||||
<section id="part-1-what-we-have">
|
||||
<h3>Part 1: What we have<a class="headerlink" href="#part-1-what-we-have" title="Permalink to this headline">¶</a></h3>
|
||||
<ol class="simple">
|
||||
<li><p><a class="reference internal" href="Starting/Part1/Starting-Part1.html"><span class="doc">Introduction & Overview</span></a></p></li>
|
||||
|
|
@ -74,16 +75,16 @@ in mind for your own game, this will give you a good start.</p>
|
|||
<li><p><a class="reference internal" href="Starting/Part1/Searching-Things.html"><span class="doc">Searching for things</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="Starting/Part1/Django-queries.html"><span class="doc">Advanced searching with Django queries</span></a></p></li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section" id="part-2-what-we-want">
|
||||
</section>
|
||||
<section id="part-2-what-we-want">
|
||||
<h3>Part 2: What we want<a class="headerlink" href="#part-2-what-we-want" title="Permalink to this headline">¶</a></h3>
|
||||
<ol class="simple">
|
||||
<li><p><a class="reference internal" href="Starting/Part2/Starting-Part2.html"><span class="doc">Introduction & Overview</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="Starting/Part2/Game-Planning.html"><span class="doc">On planning a game</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="Starting/Part2/Planning-Some-Useful-Contribs.html"><span class="doc">Planning to use some useful Contribs</span></a></p></li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section" id="part3-how-we-get-there">
|
||||
</section>
|
||||
<section id="part3-how-we-get-there">
|
||||
<h3>Part3: How we get there<a class="headerlink" href="#part3-how-we-get-there" title="Permalink to this headline">¶</a></h3>
|
||||
<ol class="simple">
|
||||
<li><p><a class="reference internal" href="Starting/Part3/Starting-Part3.html"><span class="doc">Introduction & Overview</span></a></p></li>
|
||||
|
|
@ -94,16 +95,16 @@ in mind for your own game, this will give you a good start.</p>
|
|||
<li><p><a class="reference internal" href="../Unimplemented.html"><span class="doc">Quests and Zones</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="../Unimplemented.html"><span class="doc">A Combat system</span></a></p></li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section" id="part-4-using-what-we-created">
|
||||
</section>
|
||||
<section id="part-4-using-what-we-created">
|
||||
<h3>Part 4: Using what we created<a class="headerlink" href="#part-4-using-what-we-created" title="Permalink to this headline">¶</a></h3>
|
||||
<ol class="simple">
|
||||
<li><p><a class="reference internal" href="Starting/Part4/Starting-Part4.html"><span class="doc">Introduction & Overview</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="../Unimplemented.html"><span class="doc">Building the tech demo</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="../Unimplemented.html"><span class="doc">Creating a game world</span></a></p></li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section" id="part-5-showing-the-world">
|
||||
</section>
|
||||
<section id="part-5-showing-the-world">
|
||||
<h3>Part 5: Showing the world<a class="headerlink" href="#part-5-showing-the-world" title="Permalink to this headline">¶</a></h3>
|
||||
<ol class="simple">
|
||||
<li><p><a class="reference internal" href="Starting/Part5/Starting-Part5.html"><span class="doc">Introduction & Overview</span></a></p></li>
|
||||
|
|
@ -112,15 +113,15 @@ in mind for your own game, this will give you a good start.</p>
|
|||
<li><p><a class="reference internal" href="../Unimplemented.html"><span class="doc">Taking your game online</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="../Unimplemented.html"><span class="doc">Next steps</span></a></p></li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="faqs">
|
||||
</section>
|
||||
</section>
|
||||
<section id="faqs">
|
||||
<h2>FAQs<a class="headerlink" href="#faqs" title="Permalink to this headline">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference internal" href="Coding-FAQ.html"><span class="doc">Coding FAQ</span></a></p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="howto-s">
|
||||
</section>
|
||||
<section id="howto-s">
|
||||
<h2>Howto’s<a class="headerlink" href="#howto-s" title="Permalink to this headline">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference internal" href="Default-Exit-Errors.html"><span class="doc">Giving Exits a default error</span></a></p></li>
|
||||
|
|
@ -130,23 +131,23 @@ in mind for your own game, this will give you a good start.</p>
|
|||
<li><p><a class="reference internal" href="Manually-Configuring-Color.html"><span class="doc">Configuring color</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="Tutorial-Tweeting-Game-Stats.html"><span class="doc">Tweet game stats</span></a></p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="mobs-and-npcs">
|
||||
</section>
|
||||
<section id="mobs-and-npcs">
|
||||
<h2>Mobs and NPCs<a class="headerlink" href="#mobs-and-npcs" title="Permalink to this headline">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference internal" href="Tutorial-NPCs-listening.html"><span class="doc">NPCs that listen to you</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="Tutorial-Aggressive-NPCs.html"><span class="doc">Mobs that attack you</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="NPC-shop-Tutorial.html"><span class="doc">Shopkeepers</span></a></p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="vehicles">
|
||||
</section>
|
||||
<section id="vehicles">
|
||||
<h2>Vehicles<a class="headerlink" href="#vehicles" title="Permalink to this headline">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference internal" href="Building-a-mech-tutorial.html"><span class="doc">Building a mech</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="Tutorial-Vehicles.html"><span class="doc">Building a train</span></a></p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="systems">
|
||||
</section>
|
||||
<section id="systems">
|
||||
<h2>Systems<a class="headerlink" href="#systems" title="Permalink to this headline">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference internal" href="Gametime-Tutorial.html"><span class="doc">Understanding In-game time</span></a></p></li>
|
||||
|
|
@ -154,16 +155,16 @@ in mind for your own game, this will give you a good start.</p>
|
|||
<li><p><a class="reference internal" href="Mass-and-weight-for-objects.html"><span class="doc">Adding mass to objects</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="Weather-Tutorial.html"><span class="doc">Add weather</span></a></p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="web-related-tutorials">
|
||||
</section>
|
||||
<section id="web-related-tutorials">
|
||||
<h2>Web-related tutorials<a class="headerlink" href="#web-related-tutorials" title="Permalink to this headline">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference internal" href="Add-a-wiki-on-your-website.html"><span class="doc">Add a wiki</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="Web-Character-Generation.html"><span class="doc">A web-based character generation</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="Web-Character-View-Tutorial.html"><span class="doc">View Character on website</span></a></p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="deep-dives">
|
||||
</section>
|
||||
<section id="deep-dives">
|
||||
<h2>Deep-dives<a class="headerlink" href="#deep-dives" title="Permalink to this headline">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference internal" href="Parsing-commands-tutorial.html"><span class="doc">Parsing command inputs</span></a></p></li>
|
||||
|
|
@ -172,8 +173,8 @@ in mind for your own game, this will give you a good start.</p>
|
|||
<li><p><a class="reference internal" href="Evennia-for-Diku-Users.html"><span class="doc">Evennia for Diku Users</span></a></p></li>
|
||||
<li><p><a class="reference internal" href="Evennia-for-MUSH-Users.html"><span class="doc">Evennia for MUSH-Users</span></a></p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Manually Configuring Color — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="manually-configuring-color">
|
||||
<section id="manually-configuring-color">
|
||||
<h1>Manually Configuring Color<a class="headerlink" href="#manually-configuring-color" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This is a small tutorial for customizing your character objects, using the example of letting users
|
||||
turn on and off ANSI color parsing as an example. <code class="docutils literal notranslate"><span class="pre">@options</span> <span class="pre">NOCOLOR=True</span></code> will now do what this
|
||||
|
|
@ -57,19 +58,19 @@ configuration system for your characters. This is the basic sequence:</p>
|
|||
<li><p>Overload the <code class="docutils literal notranslate"><span class="pre">msg()</span></code> method on the typeclass and change how it uses markup.</p></li>
|
||||
<li><p>Create a custom command to allow users to change their setting.</p></li>
|
||||
</ol>
|
||||
<div class="section" id="setting-up-a-custom-typeclass">
|
||||
<section id="setting-up-a-custom-typeclass">
|
||||
<h2>Setting up a custom Typeclass<a class="headerlink" href="#setting-up-a-custom-typeclass" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Create a new module in <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses</span></code> named, for example, <code class="docutils literal notranslate"><span class="pre">mycharacter.py</span></code>. Alternatively you
|
||||
can simply add a new class to ‘mygamegame/typeclasses/characters.py’.</p>
|
||||
<p>In your new module(or characters.py), create a new <a class="reference internal" href="../Components/Typeclasses.html"><span class="doc">Typeclass</span></a> inheriting from
|
||||
<code class="docutils literal notranslate"><span class="pre">evennia.DefaultCharacter</span></code>. We will also import <code class="docutils literal notranslate"><span class="pre">evennia.utils.ansi</span></code>, which we will use later.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Character</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Character</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia.utils</span> <span class="kn">import</span> <span class="n">ansi</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">ColorableCharacter</span><span class="p">(</span><span class="n">Character</span><span class="p">):</span>
|
||||
|
|
@ -93,28 +94,28 @@ switch clears all attributes and properties back to the default for the new type
|
|||
useful in this case to avoid ending up with an object having a “mixture” of properties from the old
|
||||
typeclass and the new one. <code class="docutils literal notranslate"><span class="pre">/force</span></code> might be needed if you edit the typeclass and want to update the
|
||||
object despite the actual typeclass name not having changed.</p>
|
||||
</div>
|
||||
<div class="section" id="overload-the-msg-method">
|
||||
</section>
|
||||
<section id="overload-the-msg-method">
|
||||
<h2>Overload the <code class="docutils literal notranslate"><span class="pre">msg()</span></code> method<a class="headerlink" href="#overload-the-msg-method" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Next we need to overload the <code class="docutils literal notranslate"><span class="pre">msg()</span></code> method. What we want is to check the configuration value before
|
||||
calling the main function. The original <code class="docutils literal notranslate"><span class="pre">msg</span></code> method call is seen in <code class="docutils literal notranslate"><span class="pre">evennia/objects/objects.py</span></code>
|
||||
and is called like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="n">msg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">from_obj</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">session</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="n">msg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">from_obj</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">session</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>As long as we define a method on our custom object with the same name and keep the same number of
|
||||
arguments/keywords we will overload the original. Here’s how it could look:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">class</span> <span class="nc">ColorableCharacter</span><span class="p">(</span><span class="n">Character</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">class</span> <span class="nc">ColorableCharacter</span><span class="p">(</span><span class="n">Character</span><span class="p">):</span>
|
||||
<span class="c1"># [...]</span>
|
||||
<span class="n">msg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">from_obj</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">session</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
|
||||
<span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||||
|
|
@ -136,44 +137,44 @@ command:</p>
|
|||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="nd">@py</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">config_color</span> <span class="o">=</span> <span class="kc">False</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="custom-color-config-command">
|
||||
</section>
|
||||
<section id="custom-color-config-command">
|
||||
<h2>Custom color config command<a class="headerlink" href="#custom-color-config-command" title="Permalink to this headline">¶</a></h2>
|
||||
<p>For completeness, let’s add a custom command so users can turn off their color display themselves if
|
||||
they want.</p>
|
||||
<p>In <code class="docutils literal notranslate"><span class="pre">mygame/commands</span></code>, create a new file, call it for example <code class="docutils literal notranslate"><span class="pre">configcmds.py</span></code> (it’s likely that
|
||||
you’ll want to add other commands for configuration down the line). You can also copy/rename the
|
||||
command template.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdConfigColor</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -208,20 +209,20 @@ command template.</p>
|
|||
<p>Lastly, we make this command available to the user by adding it to the default <code class="docutils literal notranslate"><span class="pre">CharacterCmdSet</span></code> in
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code> and reloading the server. Make sure you also import the
|
||||
command:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">mygame.commands</span> <span class="kn">import</span> <span class="n">configcmds</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">mygame.commands</span> <span class="kn">import</span> <span class="n">configcmds</span>
|
||||
<span class="k">class</span> <span class="nc">CharacterCmdSet</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">CharacterCmdSet</span><span class="p">):</span>
|
||||
<span class="c1"># [...]</span>
|
||||
<span class="k">def</span> <span class="nf">at_cmdset_creation</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
|
|
@ -237,8 +238,8 @@ command:</p>
|
|||
<span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">configcmds</span><span class="o">.</span><span class="n">CmdConfigColor</span><span class="p">())</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="more-colors">
|
||||
</section>
|
||||
<section id="more-colors">
|
||||
<h2>More colors<a class="headerlink" href="#more-colors" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Apart from ANSI colors, Evennia also supports <strong>Xterm256</strong> colors (See [Colors](../Concepts/TextTags#colored-
|
||||
text)). The <code class="docutils literal notranslate"><span class="pre">msg()</span></code> method supports the <code class="docutils literal notranslate"><span class="pre">xterm256</span></code> keyword for manually activating/deactiving
|
||||
|
|
@ -249,8 +250,8 @@ regardless of if Evennia thinks their client supports it or not.</p>
|
|||
<span class="nd">@py</span> <span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"|gThis should be uncolored"</span><span class="p">,</span> <span class="n">nomarkup</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Mass and weight for objects — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="mass-and-weight-for-objects">
|
||||
<section id="mass-and-weight-for-objects">
|
||||
<h1>Mass and weight for objects<a class="headerlink" href="#mass-and-weight-for-objects" title="Permalink to this headline">¶</a></h1>
|
||||
<p>An easy addition to add dynamic variety to your world objects is to give them some mass. Why mass
|
||||
and not weight? Weight varies in setting; for example things on the Moon weigh 1/6 as much. On
|
||||
|
|
@ -46,18 +47,18 @@ Earth’s surface and in most environments, no relative weight factor is needed.
|
|||
determine a character’s burden weight for travel speed… The total mass of an object can
|
||||
contribute to the force of a weapon swing, or a speeding meteor to give it a potential striking
|
||||
force.</p>
|
||||
<div class="section" id="objects">
|
||||
<section id="objects">
|
||||
<h2>Objects<a class="headerlink" href="#objects" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Now that we have reasons for keeping track of object mass, let’s look at the default object class
|
||||
inside your mygame/typeclasses/objects.py and see how easy it is to total up mass from an object and
|
||||
its contents.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># inside your mygame/typeclasses/objects.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># inside your mygame/typeclasses/objects.py</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Object</span><span class="p">(</span><span class="n">DefaultObject</span><span class="p">):</span>
|
||||
<span class="c1"># [...]</span>
|
||||
|
|
@ -73,8 +74,8 @@ return a total mass value.</p>
|
|||
module, see [[Adding-Object-Typeclass-Tutorial]] with its Heavy class object. You could set the
|
||||
default for Heavy types to something much larger than 1 gram or whatever unit you want to use. Any
|
||||
non-default mass would be stored on the <code class="docutils literal notranslate"><span class="pre">mass</span></code> [[Attributes]] of the objects.</p>
|
||||
</div>
|
||||
<div class="section" id="characters-and-rooms">
|
||||
</section>
|
||||
<section id="characters-and-rooms">
|
||||
<h2>Characters and rooms<a class="headerlink" href="#characters-and-rooms" title="Permalink to this headline">¶</a></h2>
|
||||
<p>You can add a <code class="docutils literal notranslate"><span class="pre">get_mass</span></code> definition to characters and rooms, also.</p>
|
||||
<p>If you were in a one metric-ton elevator with four other friends also wearing armor and carrying
|
||||
|
|
@ -83,52 +84,52 @@ gold bricks, you might wonder if this elevator’s going to move, and how fast.<
|
|||
<code class="docutils literal notranslate"><span class="pre">@set</span> <span class="pre">elevator/mass=1000000</span></code>, we’re <code class="docutils literal notranslate"><span class="pre">@set</span> <span class="pre">me/mass=85000</span></code> and our armor is <code class="docutils literal notranslate"><span class="pre">@set</span> <span class="pre">armor/mass=50000</span></code>.
|
||||
We’re each carrying 20 gold bars each <code class="docutils literal notranslate"><span class="pre">@set</span> <span class="pre">gold</span> <span class="pre">bar/mass=12400</span></code> then step into the elevator and see
|
||||
the following message in the elevator’s appearance: <code class="docutils literal notranslate"><span class="pre">Elevator</span> <span class="pre">weight</span> <span class="pre">and</span> <span class="pre">contents</span> <span class="pre">should</span> <span class="pre">not</span> <span class="pre">exceed</span> <span class="pre">3</span> <span class="pre">metric</span> <span class="pre">tons.</span></code> Are we safe? Maybe not if you consider dynamic loading. But at rest:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># Elevator object knows when it checks itself:</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># Elevator object knows when it checks itself:</span>
|
||||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_mass</span><span class="p">()</span> <span class="o"><</span> <span class="mi">3000000</span><span class="p">:</span>
|
||||
<span class="k">pass</span> <span class="c1"># Elevator functions as normal.</span>
|
||||
<span class="k">else</span><span class="p">:</span>
|
||||
<span class="k">pass</span> <span class="c1"># Danger! Alarm sounds, cable snaps, elevator stops...</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="inventory">
|
||||
</section>
|
||||
<section id="inventory">
|
||||
<h2>Inventory<a class="headerlink" href="#inventory" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Example of listing mass of items in your inventory:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CmdInventory</span><span class="p">(</span><span class="n">MuxCommand</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CmdInventory</span><span class="p">(</span><span class="n">MuxCommand</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> view inventory</span>
|
||||
<span class="sd"> Usage:</span>
|
||||
|
|
@ -161,8 +162,8 @@ the following message in the elevator’s appearance: <code class="docutils lite
|
|||
<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="n">string</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>NPC shop Tutorial — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="npc-shop-tutorial">
|
||||
<section id="npc-shop-tutorial">
|
||||
<h1>NPC shop Tutorial<a class="headerlink" href="#npc-shop-tutorial" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This tutorial will describe how to make an NPC-run shop. We will make use of the <a class="reference internal" href="../Components/EvMenu.html"><span class="doc">EvMenu</span></a>
|
||||
system to present shoppers with a menu where they can buy things from the store’s stock.</p>
|
||||
|
|
@ -57,12 +58,12 @@ compare it to the <code class="docutils literal notranslate"><span class="pre">g
|
|||
deducted and the goods transferred from the store room to the inventory of the customer.</p></li>
|
||||
<li><p>We will lock the store room so that only people with the right key can get in there.</p></li>
|
||||
</ul>
|
||||
<div class="section" id="the-shop-menu">
|
||||
<section id="the-shop-menu">
|
||||
<h2>The shop menu<a class="headerlink" href="#the-shop-menu" title="Permalink to this headline">¶</a></h2>
|
||||
<p>We want to show a menu to the customer where they can list, examine and buy items in the store. This
|
||||
menu should change depending on what is currently for sale. Evennia’s <em>EvMenu</em> utility will manage
|
||||
the menu for us. It’s a good idea to <a class="reference internal" href="../Components/EvMenu.html"><span class="doc">read up on EvMenu</span></a> if you are not familiar with it.</p>
|
||||
<div class="section" id="designing-the-menu">
|
||||
<section id="designing-the-menu">
|
||||
<h3>Designing the menu<a class="headerlink" href="#designing-the-menu" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The shopping menu’s design is straightforward. First we want the main screen. You get this when you
|
||||
enter a shop and use the <code class="docutils literal notranslate"><span class="pre">browse</span></code> or <code class="docutils literal notranslate"><span class="pre">buy</span></code> command:</p>
|
||||
|
|
@ -95,41 +96,41 @@ particular item:</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>After this you should be back to the top level of the shopping menu again and can continue browsing.</p>
|
||||
</div>
|
||||
<div class="section" id="coding-the-menu">
|
||||
</section>
|
||||
<section id="coding-the-menu">
|
||||
<h3>Coding the menu<a class="headerlink" href="#coding-the-menu" title="Permalink to this headline">¶</a></h3>
|
||||
<p>EvMenu defines the <em>nodes</em> (each menu screen with options) as normal Python functions. Each node
|
||||
must be able to change on the fly depending on what items are currently for sale. EvMenu will
|
||||
automatically make the <code class="docutils literal notranslate"><span class="pre">quit</span></code> command available to us so we won’t add that manually. For compactness
|
||||
we will put everything needed for our shop in one module, <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/npcshop.py</span></code>.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/npcshop.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/npcshop.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia.utils</span> <span class="kn">import</span> <span class="n">evmenu</span>
|
||||
|
||||
|
|
@ -166,40 +167,40 @@ to build up the menu’s options.</p>
|
|||
<p>Note that <em>all options point to the same menu node</em> called <code class="docutils literal notranslate"><span class="pre">menunode_inspect_and_buy</span></code>! We can’t know
|
||||
which goods will be available to sale so we rely on this node to modify itself depending on the
|
||||
circumstances. Let’s create it now.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># further down in mygame/typeclasses/npcshop.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># further down in mygame/typeclasses/npcshop.py</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">menunode_inspect_and_buy</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">):</span>
|
||||
<span class="s2">"Sets up the buy menu screen."</span>
|
||||
|
|
@ -248,36 +249,36 @@ back to the top node (the <code class="docutils literal notranslate"><span class
|
|||
need to return anything. In <code class="docutils literal notranslate"><span class="pre">buy_ware_result</span></code> we determine if the customer can afford the cost and
|
||||
give proper return messages. This is also where we actually move the bought item into the inventory
|
||||
of the customer.</p>
|
||||
</div>
|
||||
<div class="section" id="the-command-to-start-the-menu">
|
||||
</section>
|
||||
<section id="the-command-to-start-the-menu">
|
||||
<h3>The command to start the menu<a class="headerlink" href="#the-command-to-start-the-menu" title="Permalink to this headline">¶</a></h3>
|
||||
<p>We could <em>in principle</em> launch the shopping menu the moment a customer steps into our shop room, but
|
||||
this would probably be considered pretty annoying. It’s better to create a <a class="reference internal" href="../Components/Commands.html"><span class="doc">Command</span></a> for
|
||||
customers to explicitly wanting to shop around.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/npcshop.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/npcshop.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
|
||||
|
|
@ -307,20 +308,20 @@ customers to explicitly wanting to shop around.</p>
|
|||
since the only global functions available in this module are our menu nodes, this will work fine
|
||||
(you could also have put those in a separate module). We now just need to put this command in a
|
||||
<a class="reference internal" href="../Components/Command-Sets.html"><span class="doc">CmdSet</span></a> so we can add it correctly to the game:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">CmdSet</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">CmdSet</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">ShopCmdSet</span><span class="p">(</span><span class="n">CmdSet</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="nf">at_cmdset_creation</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">add</span><span class="p">(</span><span class="n">CmdBuy</span><span class="p">())</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="building-the-shop">
|
||||
</section>
|
||||
</section>
|
||||
<section id="building-the-shop">
|
||||
<h2>Building the shop<a class="headerlink" href="#building-the-shop" title="Permalink to this headline">¶</a></h2>
|
||||
<p>There are really only two things that separate our shop from any other Room:</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -332,72 +333,72 @@ the shop.</p></li>
|
|||
commands. Just to show how it can be done we’ll instead make a custom <a class="reference internal" href="../Components/Typeclasses.html"><span class="doc">Typeclass</span></a> for
|
||||
the shop room and make a small command that builders can use to build both the shop and the
|
||||
storeroom at once.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># bottom of mygame/typeclasses/npcshop.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span>
|
||||
<span class="normal">60</span>
|
||||
<span class="normal">61</span>
|
||||
<span class="normal">62</span>
|
||||
<span class="normal">63</span>
|
||||
<span class="normal">64</span>
|
||||
<span class="normal">65</span>
|
||||
<span class="normal">66</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># bottom of mygame/typeclasses/npcshop.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultRoom</span><span class="p">,</span> <span class="n">DefaultExit</span><span class="p">,</span> <span class="n">DefaultObject</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia.utils.create</span> <span class="kn">import</span> <span class="n">create_object</span>
|
||||
|
|
@ -485,8 +486,8 @@ you need to come up with a more robust lock-key solution.</p>
|
|||
You could add better default descriptions as part of the <code class="docutils literal notranslate"><span class="pre">@buildshop</span></code> command or leave descriptions
|
||||
this up to the Builder.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="the-shop-is-open-for-business">
|
||||
</section>
|
||||
<section id="the-shop-is-open-for-business">
|
||||
<h2>The shop is open for business!<a class="headerlink" href="#the-shop-is-open-for-business" title="Permalink to this headline">¶</a></h2>
|
||||
<p>We now have a functioning shop and an easy way for Builders to create it. All you need now is to
|
||||
<code class="docutils literal notranslate"><span class="pre">@open</span></code> a new exit from the rest of the game into the shop and put some sell-able items in the store
|
||||
|
|
@ -505,8 +506,8 @@ would then be gone and the counter be wrong - the shop would pass us the next it
|
|||
store room regularly. This shop example could also easily be owned by a human Player (run for them
|
||||
by a hired NPC) - the shop owner would get the key to the store room and be responsible for keeping
|
||||
it well stocked.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Parsing command arguments, theory and best practices — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="parsing-command-arguments-theory-and-best-practices">
|
||||
<section id="parsing-command-arguments-theory-and-best-practices">
|
||||
<h1>Parsing command arguments, theory and best practices<a class="headerlink" href="#parsing-command-arguments-theory-and-best-practices" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This tutorial will elaborate on the many ways one can parse command arguments. The first step after
|
||||
<a class="reference internal" href="Starting/Part1/Adding-Commands.html"><span class="doc">adding a command</span></a> usually is to parse its arguments. There are lots of
|
||||
|
|
@ -53,7 +54,7 @@ This might be true for others.</p>
|
|||
<li><p>Take a look at optional arguments.</p></li>
|
||||
<li><p>Parse argument containing object names.</p></li>
|
||||
</ul>
|
||||
<div class="section" id="what-are-command-arguments">
|
||||
<section id="what-are-command-arguments">
|
||||
<h2>What are command arguments?<a class="headerlink" href="#what-are-command-arguments" title="Permalink to this headline">¶</a></h2>
|
||||
<p>I’m going to talk about command arguments and parsing a lot in this tutorial. So let’s be sure we
|
||||
talk about the same thing before going any further:</p>
|
||||
|
|
@ -82,31 +83,31 @@ work with.</p>
|
|||
<p>We don’t usually use the command argument as is (which is just text, of type <code class="docutils literal notranslate"><span class="pre">str</span></code> in Python). We
|
||||
need to extract useful information. We might want to ask the user for a number, or the name of
|
||||
another character present in the same room. We’re going to see how to do all that now.</p>
|
||||
</div>
|
||||
<div class="section" id="working-with-strings">
|
||||
</section>
|
||||
<section id="working-with-strings">
|
||||
<h2>Working with strings<a class="headerlink" href="#working-with-strings" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In object terms, when you write a command in Evennia (when you write the Python class), the
|
||||
arguments are stored in the <code class="docutils literal notranslate"><span class="pre">args</span></code> attribute. Which is to say, inside your <code class="docutils literal notranslate"><span class="pre">func</span></code> method, you can
|
||||
access the command arguments in <code class="docutils literal notranslate"><span class="pre">self.args</span></code>.</p>
|
||||
<div class="section" id="self-args">
|
||||
<section id="self-args">
|
||||
<h3>self.args<a class="headerlink" href="#self-args" title="Permalink to this headline">¶</a></h3>
|
||||
<p>To begin with, look at this example:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16</pre></div></td><td class="code"><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>
|
||||
<div class="highlight-python notranslate"><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 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>
|
||||
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> Test command.</span>
|
||||
|
|
@ -138,29 +139,29 @@ you receive from the game server.</p>
|
|||
</div></blockquote>
|
||||
<p>Notice two things here:</p>
|
||||
<ol class="simple">
|
||||
<li><p>The left space between our command key (“test”, here) and our command argument is not removed.
|
||||
<li><p>The left space between our command key (”test”, here) and our command argument is not removed.
|
||||
That’s why there are two spaces in our output at line 2. Try entering something like “testok”.</p></li>
|
||||
<li><p>Even if you don’t enter command arguments, the command will still be called with an empty string
|
||||
in <code class="docutils literal notranslate"><span class="pre">self.args</span></code>.</p></li>
|
||||
</ol>
|
||||
<p>Perhaps a slight modification to our code would be appropriate to see what’s happening. We will
|
||||
force Python to display the command arguments as a debug string using a little shortcut.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16</pre></div></td><td class="code"><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>
|
||||
<div class="highlight-python notranslate"><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 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>
|
||||
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> Test command.</span>
|
||||
|
|
@ -193,8 +194,8 @@ read… to debug, anyway.</p>
|
|||
<p>I insist so much on that point because it’s crucial: the command argument is just a string (of type
|
||||
<code class="docutils literal notranslate"><span class="pre">str</span></code>) and we will use this to parse it. What you will see is mostly not Evennia-specific, it’s
|
||||
Python-specific and could be used in any other project where you have the same need.</p>
|
||||
</div>
|
||||
<div class="section" id="stripping">
|
||||
</section>
|
||||
<section id="stripping">
|
||||
<h3>Stripping<a class="headerlink" href="#stripping" title="Permalink to this headline">¶</a></h3>
|
||||
<p>As you’ve seen, our command arguments are stored with the space. And the space between the command
|
||||
and the arguments is often of no importance.</p>
|
||||
|
|
@ -216,14 +217,14 @@ string.</p></li>
|
|||
<li><p><code class="docutils literal notranslate"><span class="pre">rstrip</span></code>: same thing but only removes from the right end (right strip) of the string.</p></li>
|
||||
</ul>
|
||||
<p>Some Python examples might help:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="s1">' this is '</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="c1"># remove spaces by default</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="s1">' this is '</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="c1"># remove spaces by default</span>
|
||||
<span class="go">'this is'</span>
|
||||
<span class="gp">>>> </span><span class="s2">" What if I'm right? "</span><span class="o">.</span><span class="n">lstrip</span><span class="p">()</span> <span class="c1"># strip spaces from the left</span>
|
||||
<span class="go">"What if I'm right? "</span>
|
||||
|
|
@ -235,26 +236,26 @@ string.</p></li>
|
|||
</td></tr></table></div>
|
||||
<p>Usually, since we don’t need the space separator, but still want our command to work if there’s no
|
||||
separator, we call <code class="docutils literal notranslate"><span class="pre">lstrip</span></code> on the command arguments:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20</pre></div></td><td class="code"><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>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><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>
|
||||
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> Test command.</span>
|
||||
|
|
@ -298,8 +299,8 @@ our <code class="docutils literal notranslate"><span class="pre">self.args.lstri
|
|||
separators. You can specify one or more characters as a parameter. If you specify more than one
|
||||
character, all of them will be stripped from your original string.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="convert-arguments-to-numbers">
|
||||
</section>
|
||||
<section id="convert-arguments-to-numbers">
|
||||
<h3>Convert arguments to numbers<a class="headerlink" href="#convert-arguments-to-numbers" title="Permalink to this headline">¶</a></h3>
|
||||
<p>As pointed out, <code class="docutils literal notranslate"><span class="pre">self.args</span></code> is a string (of type <code class="docutils literal notranslate"><span class="pre">str</span></code>). What if we want the user to enter a
|
||||
number?</p>
|
||||
|
|
@ -320,41 +321,41 @@ You played 1, you have won!
|
|||
<p>If that’s your first command, it’s a good opportunity to try to write it. A command with a simple
|
||||
and finite role always is a good starting choice. Here’s how we could (first) write it… but it
|
||||
won’t work as is, I warn you:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
|
||||
|
|
@ -403,50 +404,50 @@ the string and it returns an integer, if it could. If it can’t, it will raise
|
|||
we’ll need to catch that. However, we also have to indicate to Evennia that, should the number be
|
||||
invalid, no further parsing should be done. Here’s a new attempt at our command with this
|
||||
converting:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span><span class="p">,</span> <span class="n">InterruptCommand</span>
|
||||
|
||||
|
|
@ -506,51 +507,51 @@ positive number between 1 and 6. And the user can enter <code class="docutils l
|
|||
that matter, the game still works. It might be worth addressing. Again, you could write a
|
||||
condition to do that, but since we’re catching an exception, we might end up with something cleaner
|
||||
by grouping:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span><span class="p">,</span> <span class="n">InterruptCommand</span>
|
||||
|
||||
|
|
@ -605,8 +606,8 @@ latter condition.</p>
|
|||
which remains the same. This is one goal of separating argument parsing from command processing,
|
||||
these two actions are best kept isolated.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="working-with-several-arguments">
|
||||
</section>
|
||||
<section id="working-with-several-arguments">
|
||||
<h3>Working with several arguments<a class="headerlink" href="#working-with-several-arguments" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Often a command expects several arguments. So far, in our example with the “roll” command, we only
|
||||
expect one argument: a number and just a number. What if we want the user to specify several
|
||||
|
|
@ -653,7 +654,7 @@ glance:</p>
|
|||
<span class="gp">>>> </span><span class="n">args</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">" "</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="c1"># one split, that is a list with two elements (before, after)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>[‘that’, ‘is something great’]</p>
|
||||
<p>[’that’, ‘is something great’]</p>
|
||||
<blockquote>
|
||||
<div><blockquote>
|
||||
<div></div></blockquote>
|
||||
|
|
@ -677,72 +678,72 @@ which will raise an exception if there is an error: variable unpacking.</p>
|
|||
<p>We won’t talk about this feature in details here. It would be complicated. But the code is really
|
||||
straightforward to use. Let’s take our example of the roll command but let’s add a first argument:
|
||||
the number of dice to roll.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span>
|
||||
<span class="normal">60</span>
|
||||
<span class="normal">61</span>
|
||||
<span class="normal">62</span>
|
||||
<span class="normal">63</span>
|
||||
<span class="normal">64</span>
|
||||
<span class="normal">65</span>
|
||||
<span class="normal">66</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span><span class="p">,</span> <span class="n">InterruptCommand</span>
|
||||
|
||||
|
|
@ -811,11 +812,11 @@ the number of dice to roll.</p>
|
|||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>The beginning of the <code class="docutils literal notranslate"><span class="pre">parse()</span></code> method is what interests us most:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span>
|
||||
<span class="n">number</span><span class="p">,</span> <span class="n">guess</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">" "</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
|
||||
<span class="k">except</span> <span class="ne">ValueError</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">"Invalid usage. Enter two numbers separated by a space."</span><span class="p">)</span>
|
||||
|
|
@ -848,8 +849,8 @@ as well:</p>
|
|||
<span class="go">>>></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="optional-arguments">
|
||||
</section>
|
||||
<section id="optional-arguments">
|
||||
<h3>Optional arguments<a class="headerlink" href="#optional-arguments" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Sometimes, you’ll come across commands that have optional arguments. These arguments are not
|
||||
necessary but they can be set if more information is needed. I will not provide the entire command
|
||||
|
|
@ -862,15 +863,15 @@ the player could enter the “tel” command like this:</p>
|
|||
</div>
|
||||
<p>The equal sign is optional along with whatever is specified after it. A possible solution in our
|
||||
<code class="docutils literal notranslate"><span class="pre">parse</span></code> method would be:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="n">args</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">lstrip</span><span class="p">()</span>
|
||||
|
||||
<span class="c1"># = is optional</span>
|
||||
|
|
@ -893,9 +894,9 @@ might too easily break your code if you’re not careful.</p>
|
|||
</div>
|
||||
<p>Then <code class="docutils literal notranslate"><span class="pre">destination</span></code> will contain: <code class="docutils literal notranslate"><span class="pre">"</span> <span class="pre">chest</span> <span class="pre">=</span> <span class="pre">chair"</span></code>. This is often desired, but it’s up to you to
|
||||
set parsing however you like.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="evennia-searches">
|
||||
</section>
|
||||
</section>
|
||||
<section id="evennia-searches">
|
||||
<h2>Evennia searches<a class="headerlink" href="#evennia-searches" title="Permalink to this headline">¶</a></h2>
|
||||
<p>After this quick tour of some <code class="docutils literal notranslate"><span class="pre">str</span></code> methods, we’ll take a look at some Evennia-specific features
|
||||
that you won’t find in standard Python.</p>
|
||||
|
|
@ -906,7 +907,7 @@ about… what is this <code class="docutils literal notranslate"><span class="pr
|
|||
all typeclassed objects (you will most likely use the one on characters or accounts). This method
|
||||
supports a very wide array of arguments and has <a class="reference internal" href="Starting/Part1/Searching-Things.html"><span class="doc">its own tutorial</span></a>.
|
||||
Some examples of useful cases follow:</p>
|
||||
<div class="section" id="local-searches">
|
||||
<section id="local-searches">
|
||||
<h3>Local searches<a class="headerlink" href="#local-searches" title="Permalink to this headline">¶</a></h3>
|
||||
<p>When an account or a character enters a command, the account or character is found in the <code class="docutils literal notranslate"><span class="pre">caller</span></code>
|
||||
attribute. Therefore, <code class="docutils literal notranslate"><span class="pre">self.caller</span></code> will contain an account or a character (or a session if that’s
|
||||
|
|
@ -914,8 +915,8 @@ a session command, though that’s not as frequent). The <code class="docutils
|
|||
caller.</p>
|
||||
<p>Let’s take the same example of our little “tel” command. The user can specify an object as
|
||||
argument:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
||||
<span class="normal">2</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">lstrip</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
|
|
@ -923,10 +924,10 @@ argument:</p>
|
|||
in the caller’s location and its contents by default (that is to say, if the command has been
|
||||
entered by a character, it will search the object in the character’s room and the character’s
|
||||
inventory).</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">lstrip</span><span class="p">()</span>
|
||||
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">obj</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
|
||||
|
|
@ -935,13 +936,13 @@ inventory).</p>
|
|||
<p>We specify only one argument to the <code class="docutils literal notranslate"><span class="pre">search</span></code> method here: the string to search. If Evennia finds a
|
||||
match, it will return it and we keep it in the <code class="docutils literal notranslate"><span class="pre">obj</span></code> attribute. If it can’t find anything, it will
|
||||
return <code class="docutils literal notranslate"><span class="pre">None</span></code> so we need to check for that:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">lstrip</span><span class="p">()</span>
|
||||
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">obj</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
|
||||
|
|
@ -952,22 +953,22 @@ return <code class="docutils literal notranslate"><span class="pre">None</span><
|
|||
</td></tr></table></div>
|
||||
<p>That’s it. After this condition, you know that whatever is in <code class="docutils literal notranslate"><span class="pre">self.obj</span></code> is a valid Evennia object
|
||||
(another character, an object, an exit…).</p>
|
||||
</div>
|
||||
<div class="section" id="quiet-searches">
|
||||
</section>
|
||||
<section id="quiet-searches">
|
||||
<h3>Quiet searches<a class="headerlink" href="#quiet-searches" title="Permalink to this headline">¶</a></h3>
|
||||
<p>By default, Evennia will handle the case when more than one match is found in the search. The user
|
||||
will be asked to narrow down and re-enter the command. You can, however, ask to be returned the
|
||||
list of matches and handle this list yourself:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">lstrip</span><span class="p">()</span>
|
||||
|
||||
<span class="n">objs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">quiet</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||||
|
|
@ -983,22 +984,22 @@ list of matches and handle this list yourself:</p>
|
|||
to <code class="docutils literal notranslate"><span class="pre">True</span></code>, then errors are ignored and a list is always returned, so we need to handle it as such.
|
||||
Notice in this example, <code class="docutils literal notranslate"><span class="pre">self.obj</span></code> will contain a valid object too, but if several matches are
|
||||
found, <code class="docutils literal notranslate"><span class="pre">self.obj</span></code> will contain the first one, even if more matches are available.</p>
|
||||
</div>
|
||||
<div class="section" id="global-searches">
|
||||
</section>
|
||||
<section id="global-searches">
|
||||
<h3>Global searches<a class="headerlink" href="#global-searches" title="Permalink to this headline">¶</a></h3>
|
||||
<p>By default, Evennia will perform a local search, that is, a search limited by the location in which
|
||||
the caller is. If you want to perform a global search (search in the entire database), just set the
|
||||
<code class="docutils literal notranslate"><span class="pre">global_search</span></code> keyword argument to <code class="docutils literal notranslate"><span class="pre">True</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">lstrip</span><span class="p">()</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">obj</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">global_search</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="conclusion">
|
||||
</section>
|
||||
</section>
|
||||
<section id="conclusion">
|
||||
<h2>Conclusion<a class="headerlink" href="#conclusion" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Parsing command arguments is vital for most game designers. If you design “intelligent” commands,
|
||||
users should be able to guess how to use them without reading the help, or with a very quick peek at
|
||||
|
|
@ -1009,8 +1010,8 @@ unexpected ways and report back the right errors), you will have happier players
|
|||
longer on your game. I hope this tutorial gave you some pointers on ways to improve your command
|
||||
parsing. There are, of course, other ways you will discover, or ways you are already using in your
|
||||
code.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Our own commands — 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" />
|
||||
|
|
@ -46,19 +47,19 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="our-own-commands">
|
||||
<section id="our-own-commands">
|
||||
<h1>Our own commands<a class="headerlink" href="#our-own-commands" title="Permalink to this headline">¶</a></h1>
|
||||
<p>In this lesson we’ll learn how to create our own Evennia <em>Commands</em>. If you are new to Python you’ll
|
||||
also learn some more basics about how to manipulate strings and get information out of Evennia.</p>
|
||||
<p>A Command is something that handles the input from a user and causes a result to happen.
|
||||
An example is <code class="docutils literal notranslate"><span class="pre">look</span></code>, which examines your current location and tells how it looks like and
|
||||
what is in it.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Commands are not typeclassed</p>
|
||||
<p>If you just came from the previous lesson, you might want to know that Commands and
|
||||
CommandSets are not <cite>typeclassed</cite>. That is, instances of them are not saved to the
|
||||
database. They are “just” normal Python classes.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>In Evennia, a Command is a Python <em>class</em>. If you are unsure about what a class is, review the
|
||||
previous lessons! A Command inherits from <code class="docutils literal notranslate"><span class="pre">evennia.Command</span></code> or from one of the alternative command-
|
||||
classes, such as <code class="docutils literal notranslate"><span class="pre">MuxCommand</span></code> which is what most default commands use.</p>
|
||||
|
|
@ -73,24 +74,24 @@ commands in that cmdset available to the object. So, to summarize:</p>
|
|||
<li><p>A group of Commands is stored in a CmdSet</p></li>
|
||||
<li><p>CmdSets are stored on objects - this defines which commands are available to that object.</p></li>
|
||||
</ul>
|
||||
<div class="section" id="creating-a-custom-command">
|
||||
<section id="creating-a-custom-command">
|
||||
<h2>Creating a custom command<a class="headerlink" href="#creating-a-custom-command" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Open <code class="docutils literal notranslate"><span class="pre">mygame/commands/command.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||||
<span class="sd">(module docstring)</span>
|
||||
<span class="sd">"""</span>
|
||||
|
||||
|
|
@ -118,11 +119,11 @@ that a little later.</p>
|
|||
</div></blockquote>
|
||||
<p>We could modify this module directly, but to train imports we’ll work in a separate module. Open a new file
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/commands/mycommands.py</span></code> and add the following code:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="kn">from</span> <span class="nn">commands.command</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdEcho</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
|
|
@ -132,18 +133,18 @@ that a little later.</p>
|
|||
<p>This is the simplest form of command you can imagine. It just gives itself a name, “echo”. This is
|
||||
what you will use to call this command later.</p>
|
||||
<p>Next we need to put this in a CmdSet. It will be a one-command CmdSet for now! Change your file as such:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="kn">from</span> <span class="nn">commands.command</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">CmdSet</span>
|
||||
|
||||
|
|
@ -218,22 +219,22 @@ that this would be <code class="docutils literal notranslate"><span class="pre">
|
|||
</ul>
|
||||
<p>The reason our command doesn’t do anything yet is because it’s missing a <code class="docutils literal notranslate"><span class="pre">func</span></code> method. This is what Evennia
|
||||
looks for to figure out what a Command actually does. Modify your <code class="docutils literal notranslate"><span class="pre">CmdEcho</span></code> class:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdEcho</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -278,22 +279,22 @@ Echo: 'Woo Tang!'
|
|||
</div>
|
||||
<p>There are ways to force Evennia to <em>require</em> an initial space, but right now we want to just ignore it since
|
||||
it looks a bit weird for our echo example. Tweak the code:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdEcho</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -325,7 +326,7 @@ Echo: 'Woo Tang!'
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>You will get the docstring you put in your Command-class.</p>
|
||||
<div class="section" id="making-our-cmdset-persistent">
|
||||
<section id="making-our-cmdset-persistent">
|
||||
<h3>Making our cmdset persistent<a class="headerlink" href="#making-our-cmdset-persistent" title="Permalink to this headline">¶</a></h3>
|
||||
<p>It’s getting a little annoying to have to re-add our cmdset every time we reload, right? It’s simple
|
||||
enough to make <code class="docutils literal notranslate"><span class="pre">echo</span></code> a <em>permanent</em> change though:</p>
|
||||
|
|
@ -338,8 +339,8 @@ needing to re-add the MyCmdSet again. To remove the cmdset again, do</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>But for now, keep it around, we’ll expand it with some more examples.</p>
|
||||
</div>
|
||||
<div class="section" id="figuring-out-who-to-hit">
|
||||
</section>
|
||||
<section id="figuring-out-who-to-hit">
|
||||
<h3>Figuring out who to hit<a class="headerlink" href="#figuring-out-who-to-hit" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Let’s try something a little more exciting than just echo. Let’s make a <code class="docutils literal notranslate"><span class="pre">hit</span></code> command, for punching
|
||||
someone in the face! This is how we want it to work:</p>
|
||||
|
|
@ -353,29 +354,29 @@ You hit <target> with full force!
|
|||
</div>
|
||||
<p>Here, <code class="docutils literal notranslate"><span class="pre"><hitter></span></code> would be the one using the <code class="docutils literal notranslate"><span class="pre">hit</span></code> command and <code class="docutils literal notranslate"><span class="pre"><target></span></code> is the one doing the punching.</p>
|
||||
<p>Still in <code class="docutils literal notranslate"><span class="pre">mygame/commands/mycommands.py</span></code>, add a new class, between <code class="docutils literal notranslate"><span class="pre">CmdEcho</span></code> and <code class="docutils literal notranslate"><span class="pre">MyCmdSet</span></code>.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdHit</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -410,7 +411,7 @@ You hit <target> with full force!
|
|||
in a <em>local variable</em> <code class="docutils literal notranslate"><span class="pre">args</span></code>. Note that we don’t modify <code class="docutils literal notranslate"><span class="pre">self.args</span></code> by doing this, <code class="docutils literal notranslate"><span class="pre">self.args</span></code> will still
|
||||
have the whitespace and is not the same as <code class="docutils literal notranslate"><span class="pre">args</span></code> in this example.</p></li>
|
||||
</ul>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">if-statements</p>
|
||||
<p>The full form of the if statement is</p>
|
||||
<blockquote>
|
||||
|
|
@ -426,7 +427,7 @@ have the whitespace and is not the same as <code class="docutils literal notrans
|
|||
<p>There can be any number of <cite>elifs</cite> to mark when different branches of the code should run. If
|
||||
the <cite>else</cite> condition is given, it will run if none of the other conditions was truthy. In Python
|
||||
the <cite>if..elif..else</cite> structure also serves the same function as <cite>case</cite> in some other languages.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<ul>
|
||||
<li><p><strong>Line 16</strong> has our first <em>conditional</em>, an <code class="docutils literal notranslate"><span class="pre">if</span></code> statement. This is written on the form <code class="docutils literal notranslate"><span class="pre">if</span> <span class="pre"><condition>:</span></code> and only
|
||||
if that condition is ‘truthy’ will the indented code block under the <code class="docutils literal notranslate"><span class="pre">if</span></code> statement run. To learn what is truthy in
|
||||
|
|
@ -450,13 +451,13 @@ In that case, <code class="docutils literal notranslate"><span class="pre">targe
|
|||
<li><p><strong>Lines 22-23</strong>: At this point we have a suitable target and can send our punching strings to each.</p></li>
|
||||
</ul>
|
||||
<p>Finally we must also add this to a CmdSet. Let’s add it to <code class="docutils literal notranslate"><span class="pre">MyCmdSet</span></code> which we made permanent earlier.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">MyCmdSet</span><span class="p">(</span><span class="n">CmdSet</span><span class="p">):</span>
|
||||
|
||||
|
|
@ -465,7 +466,7 @@ In that case, <code class="docutils literal notranslate"><span class="pre">targe
|
|||
<span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">CmdHit</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Errors in your code</p>
|
||||
<p>With longer code snippets to try, it gets more and more likely you’ll
|
||||
make an error and get a <cite>traceback</cite> when you reload. This will either appear
|
||||
|
|
@ -473,7 +474,7 @@ directly in-game or in your log (view it with <cite>evennia -l</cite> in a termi
|
|||
Don’t panic; tracebacks are your friends - they are to be read bottom-up and usually describe
|
||||
exactly where your problem is. Refer to <a class="reference external" href="Python-basic-introduction.html">The Python intro</a> for
|
||||
more hints. If you get stuck, reach out to the Evennia community for help.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>Next we reload to let Evennia know of these code changes and try it out:</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>> reload
|
||||
hit
|
||||
|
|
@ -490,16 +491,16 @@ You hit Smaug with full force!
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>You won’t see the second string. Only Smaug sees that (and is not amused).</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="summary">
|
||||
</section>
|
||||
</section>
|
||||
<section id="summary">
|
||||
<h2>Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In this lesson we learned how to create our own Command, add it to a CmdSet and then to ourselves.
|
||||
We also upset a dragon.</p>
|
||||
<p>In the next lesson we’ll learn how to hit Smaug with different weapons. We’ll also
|
||||
get into how we replace and extend Evennia’s default Commands.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Using the game and building stuff — 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" />
|
||||
|
|
@ -46,7 +47,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="using-the-game-and-building-stuff">
|
||||
<section id="using-the-game-and-building-stuff">
|
||||
<h1>Using the game and building stuff<a class="headerlink" href="#using-the-game-and-building-stuff" title="Permalink to this headline">¶</a></h1>
|
||||
<p>In this lesson we will test out what we can do in-game out-of-the-box. Evennia ships with
|
||||
<a class="reference external" href="../../../api/evennia.commands.default.html#modules">around 90 default commands</a>, and while you can override those as you please,
|
||||
|
|
@ -69,7 +70,7 @@ an object.</p>
|
|||
<div><p>Are you used to commands starting with @, like @create? That will work too. Evennia simply ignores
|
||||
the preceeding @.</p>
|
||||
</div></blockquote>
|
||||
<div class="section" id="getting-help">
|
||||
<section id="getting-help">
|
||||
<h2>Getting help<a class="headerlink" href="#getting-help" title="Permalink to this headline">¶</a></h2>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">help</span>
|
||||
</pre></div>
|
||||
|
|
@ -79,8 +80,8 @@ the preceeding @.</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>to see the in-game help for that command.</p>
|
||||
</div>
|
||||
<div class="section" id="looking-around">
|
||||
</section>
|
||||
<section id="looking-around">
|
||||
<h2>Looking around<a class="headerlink" href="#looking-around" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The most common comman is</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">look</span>
|
||||
|
|
@ -93,8 +94,8 @@ room or <code class="docutils literal notranslate"><span class="pre">me</span></
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>will give you your own description. <code class="docutils literal notranslate"><span class="pre">look</span> <span class="pre">here</span></code> is, in this case, the same as plain <code class="docutils literal notranslate"><span class="pre">look</span></code>.</p>
|
||||
</div>
|
||||
<div class="section" id="stepping-down-from-godhood">
|
||||
</section>
|
||||
<section id="stepping-down-from-godhood">
|
||||
<h2>Stepping Down From Godhood<a class="headerlink" href="#stepping-down-from-godhood" title="Permalink to this headline">¶</a></h2>
|
||||
<p>If you just installed Evennia, your very first player account is called user #1, also known as the
|
||||
<em>superuser</em> or <em>god user</em>. This user is very powerful, so powerful that it will override many game
|
||||
|
|
@ -112,8 +113,8 @@ fine for the examples on this page. Use</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>to get superuser status again when you are done.</p>
|
||||
</div>
|
||||
<div class="section" id="creating-an-object">
|
||||
</section>
|
||||
<section id="creating-an-object">
|
||||
<h2>Creating an Object<a class="headerlink" href="#creating-an-object" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Basic objects can be anything – swords, flowers and non-player characters. They are created using
|
||||
the <code class="docutils literal notranslate"><span class="pre">create</span></code> command:</p>
|
||||
|
|
@ -190,8 +191,8 @@ the raw description of your current room (including color codes), so that you ca
|
|||
set its description to something else.</p>
|
||||
<p>You create new Commands (or modify existing ones) in Python outside the game. We will get to that
|
||||
later, in the <a class="reference internal" href="Adding-Commands.html"><span class="doc">Commands tutorial</span></a>.</p>
|
||||
</div>
|
||||
<div class="section" id="get-a-personality">
|
||||
</section>
|
||||
<section id="get-a-personality">
|
||||
<h2>Get a Personality<a class="headerlink" href="#get-a-personality" title="Permalink to this headline">¶</a></h2>
|
||||
<p><a class="reference internal" href="../../../Components/Scripts.html"><span class="doc">Scripts</span></a> are powerful out-of-character objects useful for many “under the hood” things.
|
||||
One of their optional abilities is to do things on a timer. To try out a first script, let’s put one
|
||||
|
|
@ -222,8 +223,8 @@ output every time it fires.</p>
|
|||
</div>
|
||||
<p>You create your own scripts in Python, outside the game; the path you give to <code class="docutils literal notranslate"><span class="pre">script</span></code> is literally
|
||||
the Python path to your script file. The <a class="reference internal" href="../../../Components/Scripts.html"><span class="doc">Scripts</span></a> page explains more details.</p>
|
||||
</div>
|
||||
<div class="section" id="pushing-your-buttons">
|
||||
</section>
|
||||
<section id="pushing-your-buttons">
|
||||
<h2>Pushing Your Buttons<a class="headerlink" href="#pushing-your-buttons" title="Permalink to this headline">¶</a></h2>
|
||||
<p>If we get back to the box we made, there is only so much fun you can have with it at this point. It’s
|
||||
just a dumb generic object. If you renamed it to <code class="docutils literal notranslate"><span class="pre">stone</span></code> and changed its description, noone would be
|
||||
|
|
@ -251,8 +252,8 @@ inside <a class="reference external" href="../../../api/evennia.contrib.tutorial
|
|||
<p class="admonition-title">Warning</p>
|
||||
<p>Don’t press the invitingly blinking red button.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="making-yourself-a-house">
|
||||
</section>
|
||||
<section id="making-yourself-a-house">
|
||||
<h2>Making Yourself a House<a class="headerlink" href="#making-yourself-a-house" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The main command for shaping the game world is <code class="docutils literal notranslate"><span class="pre">dig</span></code>. For example, if you are standing in Limbo you
|
||||
can dig a route to your new house location like this:</p>
|
||||
|
|
@ -292,8 +293,8 @@ want to link to.</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>(You can also us the #dbref of limbo, which you can find by using <code class="docutils literal notranslate"><span class="pre">examine</span> <span class="pre">here</span></code> when in limbo).</p>
|
||||
</div>
|
||||
<div class="section" id="reshuffling-the-world">
|
||||
</section>
|
||||
<section id="reshuffling-the-world">
|
||||
<h2>Reshuffling the World<a class="headerlink" href="#reshuffling-the-world" title="Permalink to this headline">¶</a></h2>
|
||||
<p>You can find things using the <code class="docutils literal notranslate"><span class="pre">find</span></code> command. Assuming you are back at <code class="docutils literal notranslate"><span class="pre">Limbo</span></code>, let’s teleport the
|
||||
<em>large box</em> to our house.</p>
|
||||
|
|
@ -321,8 +322,8 @@ without actually yourself going to <code class="docutils literal notranslate"><s
|
|||
<p>It will ask you for confirmation. Once you give it, the box will be gone.</p>
|
||||
<p>You can destroy many objects in one go by giving a comma-separated list of objects (or a range
|
||||
of #dbrefs, if they are not in the same location) to the command.</p>
|
||||
</div>
|
||||
<div class="section" id="adding-a-help-entry">
|
||||
</section>
|
||||
<section id="adding-a-help-entry">
|
||||
<h2>Adding a Help Entry<a class="headerlink" href="#adding-a-help-entry" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The Command-help is something you modify in Python code. We’ll get to that when we get to how to
|
||||
add Commands. But you can also add regular help entries, for example to explain something about
|
||||
|
|
@ -331,13 +332,13 @@ the history of your game world:</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>You will now find your new <code class="docutils literal notranslate"><span class="pre">History</span></code> entry in the <code class="docutils literal notranslate"><span class="pre">help</span></code> list and read your help-text with <code class="docutils literal notranslate"><span class="pre">help</span> <span class="pre">History</span></code>.</p>
|
||||
</div>
|
||||
<div class="section" id="adding-a-world">
|
||||
</section>
|
||||
<section id="adding-a-world">
|
||||
<h2>Adding a World<a class="headerlink" href="#adding-a-world" title="Permalink to this headline">¶</a></h2>
|
||||
<p>After this brief introduction to building and using in-game commands you may be ready to see a more fleshed-out
|
||||
example. Evennia comes with a tutorial world for you to explore. We will try that out in the next section.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Creating things — 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" />
|
||||
|
|
@ -46,7 +47,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="creating-things">
|
||||
<section id="creating-things">
|
||||
<h1>Creating things<a class="headerlink" href="#creating-things" title="Permalink to this headline">¶</a></h1>
|
||||
<p>We have already created some things - dragons for example. There are many different things to create
|
||||
in Evennia though. In the last lesson we learned about typeclasses, the way to make objects persistent in the database.</p>
|
||||
|
|
@ -77,7 +78,7 @@ are available on <code class="docutils literal notranslate"><span class="pre">ev
|
|||
to let regular players or builders without Python-access help build the game world.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="section" id="creating-objects">
|
||||
<section id="creating-objects">
|
||||
<h2>Creating Objects<a class="headerlink" href="#creating-objects" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This is one of the most common creation-types. These are entities that inherits from <code class="docutils literal notranslate"><span class="pre">DefaultObject</span></code> at any distance.
|
||||
They have an existence in the game world and includes rooms, characters, exits, weapons, flower pots and castles.</p>
|
||||
|
|
@ -88,14 +89,14 @@ They have an existence in the game world and includes rooms, characters, exits,
|
|||
</div>
|
||||
<p>Since we didn’t specify the <code class="docutils literal notranslate"><span class="pre">typeclass</span></code> as the first argument, the default given by <code class="docutils literal notranslate"><span class="pre">settings.BASE_OBJECT_TYPECLASS</span></code>
|
||||
(<code class="docutils literal notranslate"><span class="pre">typeclasses.objects.Object</span></code>) will be used.</p>
|
||||
</div>
|
||||
<div class="section" id="creating-accounts">
|
||||
</section>
|
||||
<section id="creating-accounts">
|
||||
<h2>Creating Accounts<a class="headerlink" href="#creating-accounts" title="Permalink to this headline">¶</a></h2>
|
||||
<p>An <em>Account</em> is an out-of-character (OOC) entity, with no existence in the game world.
|
||||
You can find the parent class for Accounts in <code class="docutils literal notranslate"><span class="pre">typeclasses/accounts.py</span></code>.</p>
|
||||
<p><em>TODO</em></p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Django Database queries — 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" />
|
||||
|
|
@ -46,7 +47,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="django-database-queries">
|
||||
<section id="django-database-queries">
|
||||
<h1>Django Database queries<a class="headerlink" href="#django-database-queries" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="admonition important">
|
||||
<p class="admonition-title">Important</p>
|
||||
|
|
@ -84,11 +85,11 @@ only wanted the cannons, we would do</p>
|
|||
<p>Note that <code class="docutils literal notranslate"><span class="pre">Weapon</span></code> and <code class="docutils literal notranslate"><span class="pre">Cannon</span></code> are different typeclasses. You won’t find any <code class="docutils literal notranslate"><span class="pre">Cannon</span></code> instances in
|
||||
the <code class="docutils literal notranslate"><span class="pre">all_weapon</span></code> result above, confusing as that may sound. To get instances of a Typeclass <em>and</em> the
|
||||
instances of all its children classes you need to use <code class="docutils literal notranslate"><span class="pre">_family</span></code>:</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">_family</p>
|
||||
<p>The all_family, filter_family etc is an Evennia-specific
|
||||
thing. It’s not part of regular Django.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">really_all_weapons</span> <span class="o">=</span> <span class="n">Weapon</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all_family</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
|
|
@ -138,7 +139,7 @@ found.</p></li>
|
|||
<div><p>All of Evennia search functions use querysets under the hood. The <code class="docutils literal notranslate"><span class="pre">evennia.search_*</span></code> functions actually
|
||||
return querysets, which means you could in principle keep adding queries to their results as well.</p>
|
||||
</div></blockquote>
|
||||
<div class="section" id="queryset-field-lookups">
|
||||
<section id="queryset-field-lookups">
|
||||
<h2>Queryset field lookups<a class="headerlink" href="#queryset-field-lookups" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Above we found roses with exactly the <code class="docutils literal notranslate"><span class="pre">db_key</span></code> <code class="docutils literal notranslate"><span class="pre">"rose"</span></code>. This is an <em>exact</em> match that is <em>case sensitive</em>,
|
||||
so it would not find <code class="docutils literal notranslate"><span class="pre">"Rose"</span></code>.</p>
|
||||
|
|
@ -177,8 +178,8 @@ comparisons (same for <code class="docutils literal notranslate"><span class="pr
|
|||
<code class="docutils literal notranslate"><span class="pre">db_key</span></code> and <code class="docutils literal notranslate"><span class="pre">db_category</span></code> together.</p>
|
||||
<p>For more field lookups, see the
|
||||
<a class="reference external" href="https://docs.djangoproject.com/en/3.0/ref/models/querysets/#field-lookups">django docs</a> on the subject.</p>
|
||||
</div>
|
||||
<div class="section" id="get-that-werewolf">
|
||||
</section>
|
||||
<section id="get-that-werewolf">
|
||||
<h2>Get that werewolf …<a class="headerlink" href="#get-that-werewolf" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Let’s see if we can make a query for the werewolves in the moonlight we mentioned at the beginning
|
||||
of this section.</p>
|
||||
|
|
@ -189,21 +190,21 @@ of this section.</p>
|
|||
</div>
|
||||
<p>This is an example of a more complex query. We’ll consider it an example of what is
|
||||
possible.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Line breaks</p>
|
||||
<p>Note the way of writing this code. It would have been very hard to read if we just wrote it in
|
||||
one long line. But since we wrapped it in <cite>(…)</cite> we can spread it out over multiple lines
|
||||
without worrying about line breaks!</p>
|
||||
</div>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typeclasses.characters</span> <span class="kn">import</span> <span class="n">Character</span>
|
||||
</aside>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typeclasses.characters</span> <span class="kn">import</span> <span class="n">Character</span>
|
||||
|
||||
<span class="n">will_transform</span> <span class="o">=</span> <span class="p">(</span>
|
||||
<span class="n">Character</span><span class="o">.</span><span class="n">objects</span>
|
||||
|
|
@ -234,11 +235,11 @@ that we can treat like an object for this purpose; it references all Tags on the
|
|||
<code class="docutils literal notranslate"><span class="pre">obj.attributes.add()</span></code>. Attributes are custom database entities <em>linked</em> to an object. They are not
|
||||
separate fields <em>on</em> that object like <code class="docutils literal notranslate"><span class="pre">db_key</span></code> or <code class="docutils literal notranslate"><span class="pre">db_location</span></code> are.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="complex-queries">
|
||||
</section>
|
||||
<section id="complex-queries">
|
||||
<h2>Complex queries<a class="headerlink" href="#complex-queries" title="Permalink to this headline">¶</a></h2>
|
||||
<p>All examples so far used <code class="docutils literal notranslate"><span class="pre">AND</span></code> relations. The arguments to <code class="docutils literal notranslate"><span class="pre">.filter</span></code> are added together with <code class="docutils literal notranslate"><span class="pre">AND</span></code>
|
||||
(“we want tag room to be “monlit” <em>and</em> lycantrhopy be > 2”).</p>
|
||||
(”we want tag room to be “monlit” <em>and</em> lycantrhopy be > 2”).</p>
|
||||
<p>For queries using <code class="docutils literal notranslate"><span class="pre">OR</span></code> and <code class="docutils literal notranslate"><span class="pre">NOT</span></code> we need Django’s
|
||||
<a class="reference external" href="https://docs.djangoproject.com/en/1.11/topics/db/queries/#complex-lookups-with-q-objects">Q object</a>. It is
|
||||
imported from Django directly:</p>
|
||||
|
|
@ -269,19 +270,19 @@ with a certain level of <code class="docutils literal notranslate"><span class="
|
|||
recently bitten, even if their <code class="docutils literal notranslate"><span class="pre">lycantrophy</span></code> level is not yet high enough (more dramatic this way!). Let’s say there is
|
||||
a Tag “recently_bitten” that controls this.</p>
|
||||
<p>This is how we’d change our query:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">Q</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">Q</span>
|
||||
|
||||
<span class="n">will_transform</span> <span class="o">=</span> <span class="p">(</span>
|
||||
<span class="n">Character</span><span class="o">.</span><span class="n">objects</span>
|
||||
|
|
@ -297,17 +298,17 @@ a Tag “recently_bitten” that controls this.</p>
|
|||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>That’s quite compact. It may be easier to see what’s going on if written this way:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">Q</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">Q</span>
|
||||
|
||||
<span class="n">q_moonlit</span> <span class="o">=</span> <span class="n">Q</span><span class="p">(</span><span class="n">db_location__db_tags__db_key__iexact</span><span class="o">=</span><span class="s2">"moonlit"</span><span class="p">)</span>
|
||||
<span class="n">q_lycantropic</span> <span class="o">=</span> <span class="n">Q</span><span class="p">(</span><span class="n">db_attributes__db_key</span><span class="o">=</span><span class="s2">"lycantrophy"</span><span class="p">,</span> <span class="n">db_attributes__db_value__gt</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
|
||||
|
|
@ -320,30 +321,30 @@ a Tag “recently_bitten” that controls this.</p>
|
|||
<span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">SQL</p>
|
||||
<p>These Python structures are internally converted to SQL, the native language of the database.
|
||||
If you are familiar with SQL, these are many-to-many tables joined with <cite>LEFT OUTER JOIN</cite>,
|
||||
which may lead to multiple merged rows combining the same object with different relations.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>This reads as “Find all Characters in a moonlit room that either has the Attribute <code class="docutils literal notranslate"><span class="pre">lycantrophy</span></code> higher
|
||||
than two <em>or</em> which has the Tag <code class="docutils literal notranslate"><span class="pre">recently_bitten</span></code>”. With an OR-query like this it’s possible to find the
|
||||
same Character via different paths, so we add <code class="docutils literal notranslate"><span class="pre">.distinct()</span></code> at the end. This makes sure that there is only
|
||||
one instance of each Character in the result.</p>
|
||||
</div>
|
||||
<div class="section" id="annotations">
|
||||
</section>
|
||||
<section id="annotations">
|
||||
<h2>Annotations<a class="headerlink" href="#annotations" title="Permalink to this headline">¶</a></h2>
|
||||
<p>What if we wanted to filter on some condition that isn’t represented easily by a field on the
|
||||
object? Maybe we want to find rooms only containing five or more objects?</p>
|
||||
<p>We <em>could</em> do it like this (don’t actually do it this way!):</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="kn">from</span> <span class="nn">typeclasses.rooms</span> <span class="kn">import</span> <span class="n">Room</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="kn">from</span> <span class="nn">typeclasses.rooms</span> <span class="kn">import</span> <span class="n">Room</span>
|
||||
|
||||
<span class="n">all_rooms</span> <span class="o">=</span> <span class="n">Rooms</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">()</span>
|
||||
|
||||
|
|
@ -358,15 +359,15 @@ to an ever-growing list. This is <em>not</em> a good idea, once your database gr
|
|||
be unnecessarily computing-intensive. The database is much more suitable for this.</p>
|
||||
<p><em>Annotations</em> allow you to set a ‘variable’ inside the query that you can
|
||||
then access from other parts of the query. Let’s do the same example as before directly in the database:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typeclasses.rooms</span> <span class="kn">import</span> <span class="n">Room</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typeclasses.rooms</span> <span class="kn">import</span> <span class="n">Room</span>
|
||||
<span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">Count</span>
|
||||
|
||||
<span class="n">rooms</span> <span class="o">=</span> <span class="p">(</span>
|
||||
|
|
@ -387,24 +388,24 @@ Django. In this case it allows you to find all objects that <em>has the current
|
|||
<p>Next we filter on this annotation, using the name <code class="docutils literal notranslate"><span class="pre">num_objects</span></code> as something we can filter for. We
|
||||
use <code class="docutils literal notranslate"><span class="pre">num_objects__gte=5</span></code> which means that <code class="docutils literal notranslate"><span class="pre">num_objects</span></code> should be greater than 5. This is a little
|
||||
harder to get one’s head around but much more efficient than lopping over all objects in Python.</p>
|
||||
</div>
|
||||
<div class="section" id="f-objects">
|
||||
</section>
|
||||
<section id="f-objects">
|
||||
<h2>F-objects<a class="headerlink" href="#f-objects" title="Permalink to this headline">¶</a></h2>
|
||||
<p>What if we wanted to compare two dynamic parameters against one another in a query? For example, what if
|
||||
instead of having 5 or more objects, we only wanted objects that had a bigger inventory than they had
|
||||
tags (silly example, but …)? This can be with Django’s
|
||||
<a class="reference external" href="https://docs.djangoproject.com/en/1.11/ref/models/expressions/#f-expressions">F objects</a>.
|
||||
So-called F expressions allow you to do a query that looks at a value of each object in the database.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">Count</span><span class="p">,</span> <span class="n">F</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">Count</span><span class="p">,</span> <span class="n">F</span>
|
||||
<span class="kn">from</span> <span class="nn">typeclasses.rooms</span> <span class="kn">import</span> <span class="n">Room</span>
|
||||
|
||||
<span class="n">result</span> <span class="o">=</span> <span class="p">(</span>
|
||||
|
|
@ -419,8 +420,8 @@ So-called F expressions allow you to do a query that looks at a value of each ob
|
|||
<p>Here we used <code class="docutils literal notranslate"><span class="pre">.annotate</span></code> to create two in-query ‘variables’ <code class="docutils literal notranslate"><span class="pre">num_objects</span></code> and <code class="docutils literal notranslate"><span class="pre">num_tags</span></code>. We then
|
||||
directly use these results in the filter. Using <code class="docutils literal notranslate"><span class="pre">F()</span></code> allows for also the right-hand-side of the filter
|
||||
condition to be calculated on the fly, completely within the database.</p>
|
||||
</div>
|
||||
<div class="section" id="grouping-and-returning-only-certain-properties">
|
||||
</section>
|
||||
<section id="grouping-and-returning-only-certain-properties">
|
||||
<h2>Grouping and returning only certain properties<a class="headerlink" href="#grouping-and-returning-only-certain-properties" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Suppose you used tags to mark someone belonging to an organization. Now you want to make a list and
|
||||
need to get the membership count of every organization all at once.</p>
|
||||
|
|
@ -428,15 +429,15 @@ need to get the membership count of every organization all at once.</p>
|
|||
you run a <code class="docutils literal notranslate"><span class="pre">.filter</span></code>, what you get back is a bunch of full typeclass instances, like roses or swords.
|
||||
Using <code class="docutils literal notranslate"><span class="pre">.values_list</span></code> you can instead choose to only get back certain properties on objects.
|
||||
The <code class="docutils literal notranslate"><span class="pre">.order_by</span></code> method finally allows for sorting the results according to some criterion:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">Count</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">Count</span>
|
||||
<span class="kn">from</span> <span class="nn">typeclasses.rooms</span> <span class="kn">import</span> <span class="n">Room</span>
|
||||
|
||||
<span class="n">result</span> <span class="o">=</span> <span class="p">(</span>
|
||||
|
|
@ -468,15 +469,15 @@ in a format like the following:</p>
|
|||
<span class="p">]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="conclusions">
|
||||
</section>
|
||||
<section id="conclusions">
|
||||
<h2>Conclusions<a class="headerlink" href="#conclusions" title="Permalink to this headline">¶</a></h2>
|
||||
<p>We have covered a lot of ground in this lesson and covered several more complex topics. Knowing how to
|
||||
query using Django is a powerful skill to have.</p>
|
||||
<p>This concludes the first part of the Evennia starting tutorial - “What we have”. Now we have a good foundation
|
||||
to understand how to plan what our tutorial game will be about.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Overview of the Evennia library — 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" />
|
||||
|
|
@ -46,13 +47,13 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="overview-of-the-evennia-library">
|
||||
<section id="overview-of-the-evennia-library">
|
||||
<h1>Overview of the Evennia library<a class="headerlink" href="#overview-of-the-evennia-library" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">API</p>
|
||||
<p>API stands for <cite>Application Programming Interface</cite>, a description for how to access
|
||||
the resources of a program or library.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>A good place to start exploring Evennia is the <a class="reference internal" href="../../../Evennia-API.html"><span class="doc">Evenia-API frontpage</span></a>.
|
||||
This page sums up the main components of Evennia with a short description of each. Try clicking through
|
||||
to a few entries - once you get deep enough you’ll see full descriptions
|
||||
|
|
@ -63,7 +64,7 @@ what you can download from us. The github repo is also searchable.</p>
|
|||
<p>Finally, you can clone the evennia repo to your own computer and read the sources locally. This is necessary
|
||||
if you want to help with Evennia’s development itself. See the
|
||||
<a class="reference internal" href="../../../Setup/Extended-Installation.html"><span class="doc">extended install instructions</span></a> if you want to do this.</p>
|
||||
<div class="section" id="where-is-it">
|
||||
<section id="where-is-it">
|
||||
<h2>Where is it?<a class="headerlink" href="#where-is-it" title="Permalink to this headline">¶</a></h2>
|
||||
<p>If Evennia is installed, you can import from it simply with</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">evennia</span>
|
||||
|
|
@ -123,18 +124,18 @@ from here to <code class="docutils literal notranslate"><span class="pre">mygame
|
|||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">__init__.py</p>
|
||||
<p>The <cite>__init__.py</cite> file is a special Python filename used to represent a Python ‘package’.
|
||||
When you import <cite>evennia</cite> on its own, you import this file. When you do <cite>evennia.foo</cite> Python will
|
||||
first look for a property <cite>.foo</cite> in <cite>__init__.py</cite> and then for a module or folder of that name
|
||||
in the same location.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>While all the actual Evennia code is found in the various folders, the <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code> represents the entire
|
||||
package <code class="docutils literal notranslate"><span class="pre">evennia</span></code>. It contains “shortcuts” to code that is actually located elsewhere. Most of these shortcuts
|
||||
are listed if you <a class="reference internal" href="../../../Evennia-API.html"><span class="doc">scroll down a bit</span></a> on the Evennia-API page.</p>
|
||||
</div>
|
||||
<div class="section" id="an-example-of-exploring-the-library">
|
||||
</section>
|
||||
<section id="an-example-of-exploring-the-library">
|
||||
<h2>An example of exploring the library<a class="headerlink" href="#an-example-of-exploring-the-library" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In the previous lesson we took a brief look at <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/objects</span></code> as an example of a Python module. Let’s
|
||||
open it again. Inside is the <code class="docutils literal notranslate"><span class="pre">Object</span></code> class, which inherits from <code class="docutils literal notranslate"><span class="pre">DefaultObject</span></code>.
|
||||
|
|
@ -148,13 +149,13 @@ are actually importing from <code class="docutils literal notranslate"><span cla
|
|||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">.objects.objects</span> <span class="kn">import</span> <span class="n">DefaultObject</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Relative and absolute imports</p>
|
||||
<p>The first full-stop in <cite>from .objects.objects …</cite> means that
|
||||
we are importing from the current location. This is called a <cite>relative import</cite>.
|
||||
By comparison, <cite>from evennia.objects.objects</cite> is an <cite>absolute import</cite>. In this particular
|
||||
case, the two would give the same result.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<blockquote>
|
||||
<div><p>You can also look at <a class="reference external" href="Evennia-API.html#typeclasses">the right section of the API frontpage</a> and click through
|
||||
to the code that way.</p>
|
||||
|
|
@ -171,8 +172,8 @@ to look it up in the docs:</p>
|
|||
<li><p>You can now read what this does and what methods are on it. If you want to see the full source, click the
|
||||
[<a class="reference external" href="../../../_modules/evennia/objects/objects.html#DefaultObject">source</a>] link.</p></li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Overview of your new Game Dir — 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" />
|
||||
|
|
@ -46,7 +47,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="overview-of-your-new-game-dir">
|
||||
<section id="overview-of-your-new-game-dir">
|
||||
<h1>Overview of your new Game Dir<a class="headerlink" href="#overview-of-your-new-game-dir" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Next we will take a little detour to look at the <em>Tutorial World</em>. This is a little solo adventure
|
||||
that comes with Evennia, a showcase for some of the things that are possible.</p>
|
||||
|
|
@ -61,7 +62,7 @@ Python package management).</p>
|
|||
</div></blockquote>
|
||||
<p>You may have noticed when we were building things in-game that we would often refer to code through
|
||||
“python paths”, such as</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Python-paths</p>
|
||||
<p>A ‘python path’ uses ‘.’ instead of ‘/’ or ‘<cite>\</cite>’ and
|
||||
skips the <cite>.py</cite> ending of files. It can also point to
|
||||
|
|
@ -70,7 +71,7 @@ looking for code in your game dir, your python paths can start
|
|||
from there.</p>
|
||||
<p>So a path <cite>/home/foo/devel/mygame/commands/command.py</cite>
|
||||
would translate to a Python-path <cite>commands.command</cite>.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">create</span><span class="o">/</span><span class="n">drop</span> <span class="n">button</span><span class="p">:</span><span class="n">tutorial_examples</span><span class="o">.</span><span class="n">red_button</span><span class="o">.</span><span class="n">RedButton</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
|
|
@ -107,16 +108,16 @@ Maybe you don’t need a world/ folder but prefer many folders with different as
|
|||
Or a new folder ‘rules’ for your RPG rules? This is fine. If you move things around you just need
|
||||
to update Evennia’s default settings to point to the right places in the new structure.</p>
|
||||
</div></blockquote>
|
||||
<div class="section" id="commands">
|
||||
<section id="commands">
|
||||
<h2>commands/<a class="headerlink" href="#commands" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">commands/</span></code> folder holds Python modules related to creating and extending the <a class="reference internal" href="../../../Components/Commands.html"><span class="doc">Commands</span></a>
|
||||
of Evennia. These manifest in game like the server understanding input like <code class="docutils literal notranslate"><span class="pre">look</span></code> or <code class="docutils literal notranslate"><span class="pre">dig</span></code>.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Classes</p>
|
||||
<p>A <cite>class</cite> is template for creating object-instances of a particular type
|
||||
in Python. We will explain classes in more detail in the next
|
||||
<a class="reference external" href="Python-basic-tutorial-part-two">python overview</a>.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference external" href="https://github.com/evennia/evennia/blob/master/evennia/game_template/commands/command.py">command.py</a> (Python-path: <code class="docutils literal notranslate"><span class="pre">commands.command</span></code>) - this contain the
|
||||
base <em>classes</em> for designing new input commands, or override the defaults.</p></li>
|
||||
|
|
@ -126,8 +127,8 @@ meaning a user could have a different set of commands (or versions of commands)
|
|||
in the game. In order to add a new command to the game, it’s common to import the new command-class
|
||||
from <code class="docutils literal notranslate"><span class="pre">command.py</span></code> and add it to one of the default cmdsets in this module.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="server">
|
||||
</section>
|
||||
<section id="server">
|
||||
<h2>server/<a class="headerlink" href="#server" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This folder contains resource necessary for running Evennia. Contrary to the other folders, the structure
|
||||
of this should be kept the way it is.</p>
|
||||
|
|
@ -137,13 +138,13 @@ contains the entire database. Just copy it to make a backup. For development you
|
|||
make a copy once you have set up everything you need and just copy that back to ‘reset’ the state.
|
||||
If you delete this file you can easily recreate it by running <code class="docutils literal notranslate"><span class="pre">evennia</span> <span class="pre">migrate</span></code>.</p></li>
|
||||
</ul>
|
||||
<div class="section" id="server-logs">
|
||||
<section id="server-logs">
|
||||
<h3>server/logs/<a class="headerlink" href="#server-logs" title="Permalink to this headline">¶</a></h3>
|
||||
<p>This holds the server logs. When you do <code class="docutils literal notranslate"><span class="pre">evennia</span> <span class="pre">--log</span></code>, the evennia program is in fact tailing and concatenating
|
||||
the <code class="docutils literal notranslate"><span class="pre">server.log</span></code> and <code class="docutils literal notranslate"><span class="pre">portal.log</span></code> files in this directory. The logs are rotated every week. Depending on your settings,
|
||||
other logs, like the webserver HTTP request log can also be found here.</p>
|
||||
</div>
|
||||
<div class="section" id="server-conf">
|
||||
</section>
|
||||
<section id="server-conf">
|
||||
<h3>server/conf/<a class="headerlink" href="#server-conf" title="Permalink to this headline">¶</a></h3>
|
||||
<p>This contains all configuration files of the Evennia server. These are regular Python modules which
|
||||
means that they must be extended with valid Python. You can also add logic to them if you wanted to.</p>
|
||||
|
|
@ -199,8 +200,8 @@ to add them.</p></li>
|
|||
<li><p><code class="docutils literal notranslate"><span class="pre">server_services_plugins.py</span></code> - This allows to override internal server connection protocols.</p></li>
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">web_plugins.py</span></code> - This allows to add plugins to the Evennia webserver as it starts.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="typeclasses">
|
||||
</section>
|
||||
<section id="typeclasses">
|
||||
<h3>typeclasses/<a class="headerlink" href="#typeclasses" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The <a class="reference internal" href="../../../Components/Typeclasses.html"><span class="doc">Typeclasses</span></a> of Evennia are Evennia-specific Python classes whose instances save themselves
|
||||
to the database. This allows a Character to remain in the same place and your updated strength stat to still
|
||||
|
|
@ -227,8 +228,8 @@ an entire planet or an actual dungeon room.</p></li>
|
|||
anything that needs database persistence, such as combat, weather, or economic systems. They also
|
||||
have the ability to execute code repeatedly, on a timer.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="web">
|
||||
</section>
|
||||
<section id="web">
|
||||
<h3>web/<a class="headerlink" href="#web" title="Permalink to this headline">¶</a></h3>
|
||||
<p>This folder contains folders for overriding the default web-presence of Evennia with your own designs.
|
||||
Most of these folders are empty except for a README file or a subset of other empty folders.</p>
|
||||
|
|
@ -247,8 +248,8 @@ only particular parts of a default template without touching others.</p></li>
|
|||
Evennia will copy static data from <code class="docutils literal notranslate"><span class="pre">static_overrides</span></code> here when the server starts.</p></li>
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">urls.py</span></code> - this module links up the Python code to the URLs you go to in the browser.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="world">
|
||||
</section>
|
||||
<section id="world">
|
||||
<h3>world/<a class="headerlink" href="#world" title="Permalink to this headline">¶</a></h3>
|
||||
<p>This folder only contains some example files. It’s meant to hold ‘the rest’ of your game implementation. Many
|
||||
people change and re-structure this in various ways to better fit their ideas.</p>
|
||||
|
|
@ -261,9 +262,9 @@ to easily vary objects without changing their base typeclass. For example, one c
|
|||
tell that Two goblins, while both of the class ‘Goblin’ (so they follow the same code logic), should have different
|
||||
equipment, stats and looks.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Persistent objects and typeclasses — 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" />
|
||||
|
|
@ -46,40 +47,40 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="persistent-objects-and-typeclasses">
|
||||
<section id="persistent-objects-and-typeclasses">
|
||||
<h1>Persistent objects and typeclasses<a class="headerlink" href="#persistent-objects-and-typeclasses" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Now that we have learned a little about how to find things in the Evennia library, let’s use it.</p>
|
||||
<p>In the <a class="reference internal" href="Python-classes-and-objects.html"><span class="doc">Python classes and objects</span></a> lesson we created the dragons Fluffy, Cuddly
|
||||
and Smaug and made them fly and breathe fire. So far our dragons are short-lived - whenever we <code class="docutils literal notranslate"><span class="pre">restart</span></code>
|
||||
the server or <code class="docutils literal notranslate"><span class="pre">quit()</span></code> out of python mode they are gone.</p>
|
||||
<p>This is what you should have in <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/monsters.py</span></code> so far:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="k">class</span> <span class="nc">Monster</span><span class="p">:</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> This is a base class for Monsters.</span>
|
||||
|
|
@ -108,20 +109,20 @@ the server or <code class="docutils literal notranslate"><span class="pre">quit(
|
|||
<span class="nb">print</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">key</span><span class="si">}</span><span class="s2"> breathes fire!"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="section" id="our-first-persistent-object">
|
||||
<section id="our-first-persistent-object">
|
||||
<h2>Our first persistent object<a class="headerlink" href="#our-first-persistent-object" title="Permalink to this headline">¶</a></h2>
|
||||
<p>At this point we should know enough to understand what is happening in <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/objects.py</span></code>. Let’s
|
||||
open it:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||||
<span class="sd">module docstring</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultObject</span>
|
||||
|
|
@ -146,31 +147,31 @@ the <code class="docutils literal notranslate"><span class="pre">Object</span></
|
|||
<p>One thing that Evennia classes offers and which you don’t get with vanilla Python classes is <em>persistence</em>. As
|
||||
you’ve found, Fluffy, Cuddly and Smaug are gone once we reload the server. Let’s see if we can fix this.</p>
|
||||
<p>Go back to <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/monsters.py</span></code>. Change it as follows:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="kn">from</span> <span class="nn">typeclasses.objects</span> <span class="kn">import</span> <span class="n">Object</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Monster</span><span class="p">(</span><span class="n">Object</span><span class="p">):</span>
|
||||
|
|
@ -200,16 +201,16 @@ you’ve found, Fluffy, Cuddly and Smaug are gone once we reload the server. Let
|
|||
<p>Don’t forget to save. We removed <code class="docutils literal notranslate"><span class="pre">Monster.__init__</span></code> and made <code class="docutils literal notranslate"><span class="pre">Monster</span></code> inherit from Evennia’s <code class="docutils literal notranslate"><span class="pre">Object</span></code> (which in turn
|
||||
inherits from Evennia’s <code class="docutils literal notranslate"><span class="pre">DefaultObject</span></code>, as we saw). By extension, this means that <code class="docutils literal notranslate"><span class="pre">Dragon</span></code> also inherits
|
||||
from <code class="docutils literal notranslate"><span class="pre">DefaultObject</span></code>, just from further away!</p>
|
||||
<div class="section" id="making-a-new-object-by-calling-the-class">
|
||||
<section id="making-a-new-object-by-calling-the-class">
|
||||
<h3>Making a new object by calling the class<a class="headerlink" href="#making-a-new-object-by-calling-the-class" title="Permalink to this headline">¶</a></h3>
|
||||
<p>First reload the server as usual. We will need to create the dragon a little differently this time:</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Keyword arguments</p>
|
||||
<p>Keyword arguments (like <cite>db_key=”Smaug”</cite>) is a way to
|
||||
name the input arguments to a function or method. They make
|
||||
things easier to read but also allows for conveniently setting
|
||||
defaults for values not given explicitly.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>> py
|
||||
> from typeclasses.monsters import Dragon
|
||||
> smaug = Dragon(db_key="Smaug", db_location=here)
|
||||
|
|
@ -240,8 +241,8 @@ location we can easily do this in <code class="docutils literal notranslate"><sp
|
|||
Smaug breathes fire!
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="creating-using-create-object">
|
||||
</section>
|
||||
<section id="creating-using-create-object">
|
||||
<h3>Creating using create_object<a class="headerlink" href="#creating-using-create-object" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Creating Smaug like we did above is nice because it’s similar to how we created non-database
|
||||
bound Python instances before. But you need to use <code class="docutils literal notranslate"><span class="pre">db_key</span></code> instead of <code class="docutils literal notranslate"><span class="pre">key</span></code> and you also have to
|
||||
|
|
@ -263,8 +264,8 @@ Fluffy is moving!
|
|||
means that we want the first element of this list (counting in Python always starts from 0). If there were
|
||||
multiple Fluffies we could get the second one with <code class="docutils literal notranslate"><span class="pre">[1]</span></code>.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="creating-using-create-command">
|
||||
</section>
|
||||
<section id="creating-using-create-command">
|
||||
<h3>Creating using create-command<a class="headerlink" href="#creating-using-create-command" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Finally, you can also create a new Dragon using the familiar builder-commands we explored a few lessons ago:</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">create</span><span class="o">/</span><span class="n">drop</span> <span class="n">Cuddly</span><span class="p">:</span><span class="n">typeclasses</span><span class="o">.</span><span class="n">monsters</span><span class="o">.</span><span class="n">Monster</span>
|
||||
|
|
@ -278,9 +279,9 @@ and then do a call akin to</p>
|
|||
</div>
|
||||
<p>That’s pretty much all there is to the mighty <code class="docutils literal notranslate"><span class="pre">create</span></code> command! The rest is just parsing for the command
|
||||
to understand just what the user wants to create.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="typeclasses">
|
||||
</section>
|
||||
</section>
|
||||
<section id="typeclasses">
|
||||
<h2>Typeclasses<a class="headerlink" href="#typeclasses" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">Object</span></code> (and <code class="docutils literal notranslate"><span class="pre">DefafultObject</span></code> class we inherited from above is what we refer to as a <em>Typeclass</em>. This
|
||||
is an Evennia thing. The instance of a typeclass saves itself to the database when it is created, and after
|
||||
|
|
@ -321,7 +322,7 @@ can easily just change the child classes to inherit in that way instead; Evennia
|
|||
</div></blockquote>
|
||||
<p>As seen with our <code class="docutils literal notranslate"><span class="pre">Dragon</span></code> example, you don’t <em>have</em> to modify these modules directly. You can just make your
|
||||
own modules and import the base class.</p>
|
||||
<div class="section" id="examining-and-defaults">
|
||||
<section id="examining-and-defaults">
|
||||
<h3>Examining and defaults<a class="headerlink" href="#examining-and-defaults" title="Permalink to this headline">¶</a></h3>
|
||||
<p>When you do</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">create</span><span class="o">/</span><span class="n">drop</span> <span class="n">giantess</span><span class="p">:</span><span class="n">typeclasses</span><span class="o">.</span><span class="n">monsters</span><span class="o">.</span><span class="n">Monster</span>
|
||||
|
|
@ -389,32 +390,32 @@ as you like.</p>
|
|||
<p>But the reason Evennia knows to fall back to this class is not hard-coded - it’s a setting. The default is
|
||||
in <a class="reference external" href="https://github.com/evennia/evennia/blob/master/evennia/settings_default.py#L465">evennia/settings_default.py</a>,
|
||||
with the name <code class="docutils literal notranslate"><span class="pre">BASE_OBJECT_TYPECLASS</span></code>, which is set to <code class="docutils literal notranslate"><span class="pre">typeclasses.objects.Object</span></code>.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Changing things</p>
|
||||
<p>While it’s tempting to change folders around to your liking, this can
|
||||
make it harder to follow tutorials and may confuse if
|
||||
you are asking others for help. So don’t overdo it unless you really
|
||||
know what you are doing.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>So if you wanted the creation commands and methods to default to some other class you could
|
||||
add your own <code class="docutils literal notranslate"><span class="pre">BASE_OBJECT_TYPECLASS</span></code> line to <code class="docutils literal notranslate"><span class="pre">mygame/server/conf/settings.py</span></code>. The same is true for all the other
|
||||
typeclasseses, like characters, rooms and accounts. This way you can change the
|
||||
layout of your game dir considerably if you wanted. You just need to tell Evennia where everything is.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="modifying-ourselves">
|
||||
</section>
|
||||
</section>
|
||||
<section id="modifying-ourselves">
|
||||
<h2>Modifying ourselves<a class="headerlink" href="#modifying-ourselves" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Let’s try to modify ourselves a little. Open up <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/characters.py</span></code>.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||||
<span class="sd">(module docstring)</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultCharacter</span>
|
||||
|
|
@ -466,24 +467,24 @@ commands available to you at a given moment.</p></li>
|
|||
</ul>
|
||||
<p>Look at the <strong>Typeclass</strong> field and you’ll find that it points to <code class="docutils literal notranslate"><span class="pre">typeclasses.character.Character</span></code> as expected.
|
||||
So if we modify this class we’ll also modify ourselves.</p>
|
||||
<div class="section" id="a-method-on-ourselves">
|
||||
<section id="a-method-on-ourselves">
|
||||
<h3>A method on ourselves<a class="headerlink" href="#a-method-on-ourselves" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Let’s try something simple first. Back in <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/characters.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="k">class</span> <span class="nc">Character</span><span class="p">(</span><span class="n">DefaultCharacter</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> (class docstring)</span>
|
||||
|
|
@ -505,13 +506,13 @@ So if we modify this class we’ll also modify ourselves.</p>
|
|||
<span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">15</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Tuples and lists</p>
|
||||
<ul class="simple">
|
||||
<li><p>A <cite>list</cite> is written <cite>[a, b, c, d, …]</cite>. It can be modified after creation.</p></li>
|
||||
<li><p>A <cite>tuple</cite> is written <cite>(a, b, c, …)</cite>. It cannot be modified once created.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
<p>We made a new method, gave it a docstring and had it <code class="docutils literal notranslate"><span class="pre">return</span></code> the RP-esque values we set. It comes back as a
|
||||
<em>tuple</em> <code class="docutils literal notranslate"><span class="pre">(10,</span> <span class="pre">12,</span> <span class="pre">15)</span></code>. To get a specific value you could specify the <em>index</em> of the value you want,
|
||||
starting from zero:</p>
|
||||
|
|
@ -519,8 +520,8 @@ starting from zero:</p>
|
|||
<span class="n">Strength</span> <span class="ow">is</span> <span class="mf">10.</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="attributes">
|
||||
</section>
|
||||
<section id="attributes">
|
||||
<h3>Attributes<a class="headerlink" href="#attributes" title="Permalink to this headline">¶</a></h3>
|
||||
<p>So what happens when we increase our strength? This would be one way:</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">py</span> <span class="bp">self</span><span class="o">.</span><span class="n">str</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">str</span> <span class="o">+</span> <span class="mi">1</span>
|
||||
|
|
@ -551,17 +552,17 @@ since we have the stats hardcoded in the class, <em>every</em> character instanc
|
|||
same <code class="docutils literal notranslate"><span class="pre">str</span></code>, <code class="docutils literal notranslate"><span class="pre">dex</span></code> and <code class="docutils literal notranslate"><span class="pre">int</span></code> now! This is clearly not what we want.</p>
|
||||
<p>Evennia offers a special, persistent type of property for this, called an <code class="docutils literal notranslate"><span class="pre">Attribute</span></code>. Rework your
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/characters.py</span></code> like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="k">class</span> <span class="nc">Character</span><span class="p">(</span><span class="n">DefaultCharacter</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> (class docstring)</span>
|
||||
|
|
@ -574,12 +575,12 @@ same <code class="docutils literal notranslate"><span class="pre">str</span></co
|
|||
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">str</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">dex</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">int</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Spaces in Attribute name?</p>
|
||||
<p>What if you want spaces in your Attribute name? Or you want to assign the
|
||||
name of the Attribute on-the fly? Then you can use <cite>.attributes.add(name, value)</cite> instead,
|
||||
for example <cite>self.attributes.add(“str”, 10)</cite>.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>We removed the hard-coded stats and added added <code class="docutils literal notranslate"><span class="pre">.db</span></code> for every stat. The <code class="docutils literal notranslate"><span class="pre">.db</span></code> handler makes the stat
|
||||
into an an Evennia <code class="docutils literal notranslate"><span class="pre">Attribute</span></code>.</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">reload</span>
|
||||
|
|
@ -617,39 +618,39 @@ server reload. Let’s modify the strength:</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>Our change now survives a reload since Evennia automatically saves the Attribute to the database for us.</p>
|
||||
</div>
|
||||
<div class="section" id="setting-things-on-new-characters">
|
||||
</section>
|
||||
<section id="setting-things-on-new-characters">
|
||||
<h3>Setting things on new Characters<a class="headerlink" href="#setting-things-on-new-characters" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Things a looking better, but one thing remains strange - the stats start out with a value <code class="docutils literal notranslate"><span class="pre">None</span></code> and we
|
||||
have to manually set them to something reasonable. In a later lesson we will investigate character-creation
|
||||
in more detail. For now, let’s give every new character some random stats to start with.</p>
|
||||
<p>We want those stats to be set only once, when the object is first created. For the Character, this method
|
||||
is called <code class="docutils literal notranslate"><span class="pre">at_object_creation</span></code>.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">__init__ vs at_object_creation</p>
|
||||
<p>For the <cite>Monster</cite> class we used <cite>__init__</cite> to set up the class. We can’t use this
|
||||
for a typeclass because it will be called more than once, at the very least after
|
||||
every reload and maybe more depending on caching. Even if you are familiar with Python,
|
||||
avoid touching <cite>__init__</cite> for typeclasses, the results will not be what you expect.</p>
|
||||
</div>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># up by the other imports</span>
|
||||
</aside>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># up by the other imports</span>
|
||||
<span class="kn">import</span> <span class="nn">random</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Character</span><span class="p">(</span><span class="n">DefaultCharacter</span><span class="p">):</span>
|
||||
|
|
@ -692,8 +693,8 @@ created long before, so it will not be called again.</p>
|
|||
<span class="p">(</span><span class="mi">8</span><span class="p">,</span> <span class="mi">16</span><span class="p">,</span> <span class="mi">14</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="updating-all-characters-in-a-loop">
|
||||
</section>
|
||||
<section id="updating-all-characters-in-a-loop">
|
||||
<h3>Updating all Characters in a loop<a class="headerlink" href="#updating-all-characters-in-a-loop" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Needless to say, for your game you are wise to have a feel for what you want to go into the <code class="docutils literal notranslate"><span class="pre">at_object_creation</span></code> hook
|
||||
before you create a lot of objects (characters in this case). But should it come to that you don’t want to have to
|
||||
|
|
@ -715,14 +716,14 @@ this is done (still in python multi-line mode):</p>
|
|||
<span class="o">></span> <span class="n">char</span><span class="o">.</span><span class="n">at_object_creation</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Database queries</p>
|
||||
<p><cite>Character.objects.all()</cite> is an example of a database query expressed in Python. This will be converted
|
||||
into a database query under the hood. This syntax is part of
|
||||
<a class="reference external" href="https://docs.djangoproject.com/en/3.0/topics/db/queries/">Django’s query language</a>. You don’t need to
|
||||
know Django to use Evennia, but if you ever need more specific database queries, this is always available
|
||||
when you need it.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>We import the <code class="docutils literal notranslate"><span class="pre">Character</span></code> class and then we use <code class="docutils literal notranslate"><span class="pre">.objects.all()</span></code> to get all <code class="docutils literal notranslate"><span class="pre">Character</span></code> instances. Simplified,
|
||||
<code class="docutils literal notranslate"><span class="pre">.objects</span></code> is a resource from which one can <em>query</em> for all <code class="docutils literal notranslate"><span class="pre">Characters</span></code>. Using <code class="docutils literal notranslate"><span class="pre">.all()</span></code> gets us a listing
|
||||
of all of them that we then immediately loop over. Boom, we just updated all Characters, including ourselves:</p>
|
||||
|
|
@ -732,16 +733,16 @@ of all of them that we then immediately loop over. Boom, we just updated all Cha
|
|||
<span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">18</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="extra-credits">
|
||||
</section>
|
||||
</section>
|
||||
<section id="extra-credits">
|
||||
<h2>Extra Credits<a class="headerlink" href="#extra-credits" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This principle is the same for other typeclasses. So using the tools explored in this lesson, try to expand
|
||||
the default room with an <code class="docutils literal notranslate"><span class="pre">is_dark</span></code> flag. It can be either <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code>.
|
||||
Have all new rooms start with <code class="docutils literal notranslate"><span class="pre">is_dark</span> <span class="pre">=</span> <span class="pre">False</span></code> and make it so that once you change it, it survives a reload.
|
||||
Oh, and if you created any other rooms before, make sure they get the new flag too!</p>
|
||||
</div>
|
||||
<div class="section" id="conclusions">
|
||||
</section>
|
||||
<section id="conclusions">
|
||||
<h2>Conclusions<a class="headerlink" href="#conclusions" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In this lesson we created database-persistent dragons by having their classes inherit from one <code class="docutils literal notranslate"><span class="pre">Object</span></code>, one
|
||||
of Evennia’s <em>typeclasses</em>. We explored where Evennia looks for typeclasses if we don’t specify the path
|
||||
|
|
@ -749,8 +750,8 @@ explicitly. We then modified ourselves - via the <code class="docutils literal n
|
|||
led to the need to use Evennia’s <em>Attributes</em>, settable via <code class="docutils literal notranslate"><span class="pre">.db</span></code> and to use a for-loop to update ourselves.</p>
|
||||
<p>Typeclasses are a fundamental part of Evennia and we will see a lot of more uses of them in the course of
|
||||
this tutorial. But that’s enough of them for now. It’s time to take some action. Let’s learn about <em>Commands</em>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>More about Commands — 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" />
|
||||
|
|
@ -46,11 +47,11 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="more-about-commands">
|
||||
<section id="more-about-commands">
|
||||
<h1>More about Commands<a class="headerlink" href="#more-about-commands" title="Permalink to this headline">¶</a></h1>
|
||||
<p>In this lesson we learn some basics about parsing the input of Commands. We will
|
||||
also learn how to add, modify and extend Evennia’s default commands.</p>
|
||||
<div class="section" id="more-advanced-parsing">
|
||||
<section id="more-advanced-parsing">
|
||||
<h2>More advanced parsing<a class="headerlink" href="#more-advanced-parsing" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In the last lesson we made a <code class="docutils literal notranslate"><span class="pre">hit</span></code> Command and hit a dragon with it. You should have the code
|
||||
from that still around.</p>
|
||||
|
|
@ -67,49 +68,49 @@ from that still around.</p>
|
|||
<p>If you don’t specify a weapon you’ll use your fists. It’s also nice to be able to skip “with” if
|
||||
you are in a hurry. Time to modify <code class="docutils literal notranslate"><span class="pre">mygame/commands/mycommands.py</span></code> again. Let us break out the parsing
|
||||
a little, in a new method <code class="docutils literal notranslate"><span class="pre">parse</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1">#...</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1">#...</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdHit</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -158,13 +159,13 @@ a little, in a new method <code class="docutils literal notranslate"><span class
|
|||
<code class="docutils literal notranslate"><span class="pre">parse</span></code> not only makes things a little easier to read, it also means you can easily let other Commands <em>inherit</em>
|
||||
your parsing - if you wanted some other Command to also understand input on the form <code class="docutils literal notranslate"><span class="pre"><arg></span> <span class="pre">with</span> <span class="pre"><arg></span></code> you’d inherit
|
||||
from this class and just implement the <code class="docutils literal notranslate"><span class="pre">func</span></code> needed for that command without implementing <code class="docutils literal notranslate"><span class="pre">parse</span></code> anew.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Tuples and Lists</p>
|
||||
<ul class="simple">
|
||||
<li><p>A <cite>list</cite> is written as <cite>[a, b, c, d, …]</cite>. You can add and grow/shrink a list after it was first created.</p></li>
|
||||
<li><p>A <cite>tuple</cite> is written as <cite>(a, b, c, d, …)</cite>. A tuple cannot be modified once it is created.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
<ul>
|
||||
<li><p><strong>Line 14</strong> - We do the stripping of <code class="docutils literal notranslate"><span class="pre">self.args</span></code> once and for all here. We also store the stripped version back
|
||||
into <code class="docutils literal notranslate"><span class="pre">self.args</span></code>, overwriting it. So there is no way to get back the non-stripped version from here on, which is fine
|
||||
|
|
@ -233,8 +234,8 @@ change (no code changed, only stuff in the database).</p>
|
|||
You hit smaug with sword!
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="adding-a-command-to-an-object">
|
||||
</section>
|
||||
<section id="adding-a-command-to-an-object">
|
||||
<h2>Adding a Command to an object<a class="headerlink" href="#adding-a-command-to-an-object" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The commands of a cmdset attached to an object with <code class="docutils literal notranslate"><span class="pre">obj.cmdset.add()</span></code> will by default be made available to that object
|
||||
but <em>also to those in the same location as that object</em>. If you did the <a class="reference internal" href="Building-Quickstart.html"><span class="doc">Building introduction</span></a>
|
||||
|
|
@ -253,7 +254,7 @@ add <code class="docutils literal notranslate"><span class="pre">MyCmdSet</span>
|
|||
<span class="n">hit</span><span class="o">-</span><span class="mi">2</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Multi-matches</p>
|
||||
<p>Some game engines will just pick the first hit when finding more than one.
|
||||
Evennia will always give you a choice. The reason for this is that Evennia
|
||||
|
|
@ -261,7 +262,7 @@ cannot know if <cite>hit</cite> and <cite>hit</cite> are different or the same -
|
|||
differently depending on the object it sits on? Besides, imagine if you had
|
||||
a red and a blue button both with the command <cite>push</cite> on it. Now you just write
|
||||
<cite>push</cite>. Wouldn’t you prefer to be asked <cite>which</cite> button you really wanted to push?</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>Woah, that didn’t go as planned. Evennia actually found <em>two</em> <code class="docutils literal notranslate"><span class="pre">hit</span></code> commands to didn’t know which one to use
|
||||
(<em>we</em> know they are the same, but Evennia can’t be sure of that). As we can see, <code class="docutils literal notranslate"><span class="pre">hit-1</span></code> is the one found on
|
||||
the sword. The other one is from adding <code class="docutils literal notranslate"><span class="pre">MyCmdSet</span></code> to ourself earlier. It’s easy enough to tell Evennia which
|
||||
|
|
@ -291,19 +292,19 @@ Who do you want to hit?
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">hit</span></code> command is now only available if you hold or are in the same room as the sword.</p>
|
||||
<div class="section" id="you-need-to-hold-the-sword">
|
||||
<section id="you-need-to-hold-the-sword">
|
||||
<h3>You need to hold the sword!<a class="headerlink" href="#you-need-to-hold-the-sword" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Let’s get a little ahead of ourselves and make it so you have to <em>hold</em> the sword for the <code class="docutils literal notranslate"><span class="pre">hit</span></code> command to
|
||||
be available. This involves a <em>Lock</em>. We’ve cover locks in more detail later, just know that they are useful
|
||||
for limiting the kind of things you can do with an object, including limiting just when you can call commands on
|
||||
it.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Locks</p>
|
||||
<p>Evennia Locks are defined as a mini-language defined in <cite>lockstrings</cite>. The lockstring
|
||||
is on a form <cite><situation>:<lockfuncs></cite>, where <cite>situation</cite> determines when this
|
||||
lock applies and the <cite>lockfuncs</cite> (there can be more than one) are run to determine
|
||||
if the lock-check passes or not depending on circumstance.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">py</span> <span class="bp">self</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s2">"sword"</span><span class="p">)</span><span class="o">.</span><span class="n">locks</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s2">"call:holds()"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
|
|
@ -311,13 +312,13 @@ if the lock-check passes or not depending on circumstance.</p>
|
|||
this object if you are <em>holding</em> the object (that is, it’s in your inventory).</p>
|
||||
<p>For locks to work, you cannot be <em>superuser</em>, since the superuser passes all locks. You need to <code class="docutils literal notranslate"><span class="pre">quell</span></code> yourself
|
||||
first:</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">quell/unquell</p>
|
||||
<p>Quelling allows you as a developer to take on the role of players with less
|
||||
priveleges. This is useful for testing and debugging, in particular since a
|
||||
superuser has a little <cite>too</cite> much power sometimes.
|
||||
Use <cite>unquell</cite> to get back to your normal self.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">quell</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
|
|
@ -338,9 +339,9 @@ We can do that in two ways:</p>
|
|||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">py</span> <span class="bp">self</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s2">"sword"</span><span class="p">)</span><span class="o">.</span><span class="n">delete</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="adding-the-command-to-a-default-cmdset">
|
||||
</section>
|
||||
</section>
|
||||
<section id="adding-the-command-to-a-default-cmdset">
|
||||
<h2>Adding the Command to a default Cmdset<a class="headerlink" href="#adding-the-command-to-a-default-cmdset" title="Permalink to this headline">¶</a></h2>
|
||||
<p>As we have seen we can use <code class="docutils literal notranslate"><span class="pre">obj.cmdset.add()</span></code> to add a new cmdset to objects, whether that object
|
||||
is ourself (<code class="docutils literal notranslate"><span class="pre">self</span></code>) or other objects like the <code class="docutils literal notranslate"><span class="pre">sword</span></code>.</p>
|
||||
|
|
@ -354,55 +355,55 @@ All these commands are in just loaded on the default objects that Evennia provid
|
|||
</ul>
|
||||
<p>The thing must commonly modified is the <code class="docutils literal notranslate"><span class="pre">CharacterCmdSet</span></code>.</p>
|
||||
<p>The default cmdset are defined in <code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code>. Open that file now:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||||
<span class="sd">(module docstring)</span>
|
||||
<span class="sd">"""</span>
|
||||
|
||||
|
|
@ -453,11 +454,11 @@ All these commands are in just loaded on the default objects that Evennia provid
|
|||
<span class="c1">#</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">super()</p>
|
||||
<p>The <cite>super()</cite> function refers to the parent of the current class and is commonly
|
||||
used to call same-named methods on the parent.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">evennia.default_cmds</span></code> is a container that holds all of Evennia’s default commands and cmdsets. In this module
|
||||
we can see that this was imported and then a new child class was made for each cmdset. Each class looks familiar
|
||||
(except the <code class="docutils literal notranslate"><span class="pre">key</span></code>, that’s mainly used to easily identify the cmdset in listings). In each <code class="docutils literal notranslate"><span class="pre">at_cmdset_creation</span></code> all
|
||||
|
|
@ -467,22 +468,22 @@ This is what adds all the default commands to each CmdSet.</p>
|
|||
add a Command with the same <code class="docutils literal notranslate"><span class="pre">.key</span></code> as a default command, it would completely replace that original. So if you were
|
||||
to add a command with a key <code class="docutils literal notranslate"><span class="pre">look</span></code>, the original <code class="docutils literal notranslate"><span class="pre">look</span></code> command would be replaced by your own version.</p>
|
||||
<p>For now, let’s add our own <code class="docutils literal notranslate"><span class="pre">hit</span></code> and <code class="docutils literal notranslate"><span class="pre">echo</span></code> commands to the <code class="docutils literal notranslate"><span class="pre">CharacterCmdSet</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">commands</span> <span class="kn">import</span> <span class="n">mycommands</span>
|
||||
|
||||
|
|
@ -507,19 +508,19 @@ Who do you want to hit?
|
|||
</div>
|
||||
<p>Your new commands are now available for all player characters in the game. There is another way to add a bunch
|
||||
of commands at once, and that is to add a <em>CmdSet</em> to the other cmdset. All commands in that cmdset will then be added:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">commands</span> <span class="kn">import</span> <span class="n">mycommands</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">commands</span> <span class="kn">import</span> <span class="n">mycommands</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CharacterCmdSet</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">CharacterCmdSet</span><span class="p">):</span>
|
||||
|
||||
|
|
@ -536,29 +537,29 @@ of commands at once, and that is to add a <em>CmdSet</em> to the other cmdset. A
|
|||
</td></tr></table></div>
|
||||
<p>Which way you use depends on how much control you want, but if you already have a CmdSet,
|
||||
this is practical. A Command can be a part of any number of different CmdSets.</p>
|
||||
<div class="section" id="removing-commands">
|
||||
<section id="removing-commands">
|
||||
<h3>Removing Commands<a class="headerlink" href="#removing-commands" title="Permalink to this headline">¶</a></h3>
|
||||
<p>To remove your custom commands again, you of course just delete the change you did to
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code>. But what if you want to remove a default command?</p>
|
||||
<p>We already know that we use <code class="docutils literal notranslate"><span class="pre">cmdset.remove()</span></code> to remove a cmdset. It turns out you can
|
||||
do the same in <code class="docutils literal notranslate"><span class="pre">at_cmdset_creation</span></code>. For example, let’s remove the default <code class="docutils literal notranslate"><span class="pre">get</span></code> Command
|
||||
from Evennia. We happen to know this can be found as <code class="docutils literal notranslate"><span class="pre">default_cmds.CmdGet</span></code>.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
<span class="kn">from</span> <span class="nn">commands</span> <span class="kn">import</span> <span class="n">mycommands</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CharacterCmdSet</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">CharacterCmdSet</span><span class="p">):</span>
|
||||
|
|
@ -581,24 +582,24 @@ from Evennia. We happen to know this can be found as <code class="docutils liter
|
|||
<span class="n">Command</span> <span class="s1">'get'</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">available</span> <span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="replace-a-default-command">
|
||||
</section>
|
||||
</section>
|
||||
<section id="replace-a-default-command">
|
||||
<h2>Replace a default command<a class="headerlink" href="#replace-a-default-command" title="Permalink to this headline">¶</a></h2>
|
||||
<p>At this point you already have all the pieces for how to do this! We just need to add a new
|
||||
command with the same <code class="docutils literal notranslate"><span class="pre">key</span></code> in the <code class="docutils literal notranslate"><span class="pre">CharacterCmdSet</span></code> to replace the default one.</p>
|
||||
<p>Let’s combine this with what we know about classes and
|
||||
how to <em>override</em> a parent class. Open <code class="docutils literal notranslate"><span class="pre">mygame/commands/mycommands.py</span></code> and lets override
|
||||
that <code class="docutils literal notranslate"><span class="pre">CmdGet</span></code> command.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># up top, by the other imports</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># up top, by the other imports</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span>
|
||||
|
||||
<span class="c1"># somewhere below </span>
|
||||
|
|
@ -626,22 +627,22 @@ has a special function <code class="docutils literal notranslate"><span class="p
|
|||
</ul>
|
||||
<p>We now just have to add this so it replaces the default <code class="docutils literal notranslate"><span class="pre">get</span></code> command. Open
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code> again:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
<span class="kn">from</span> <span class="nn">commands</span> <span class="kn">import</span> <span class="n">mycommands</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CharacterCmdSet</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">CharacterCmdSet</span><span class="p">):</span>
|
||||
|
|
@ -659,12 +660,12 @@ has a special function <code class="docutils literal notranslate"><span class="p
|
|||
<span class="c1"># ...</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Another way</p>
|
||||
<p>Instead of adding <cite>MyCmdGet</cite> explicitly in default_cmdset.py,
|
||||
you could also add it to <cite>mycommands.MyCmdSet</cite> and let it be
|
||||
added automatically for you.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>> reload
|
||||
> get
|
||||
Get What?
|
||||
|
|
@ -673,14 +674,14 @@ Get What?
|
|||
</div>
|
||||
<p>We just made a new <code class="docutils literal notranslate"><span class="pre">get</span></code>-command that tells us everything we could pick up (well, we can’t pick up ourselves, so
|
||||
there’s some room for improvement there).</p>
|
||||
</div>
|
||||
<div class="section" id="summary">
|
||||
</section>
|
||||
<section id="summary">
|
||||
<h2>Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In this lesson we got into some more advanced string formatting - many of those tricks will help you a lot in
|
||||
the future! We also made a functional sword. Finally we got into how to add to, extend and replace a default
|
||||
command on ourselves.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Starting to code Evennia — 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" />
|
||||
|
|
@ -46,7 +47,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="starting-to-code-evennia">
|
||||
<section id="starting-to-code-evennia">
|
||||
<h1>Starting to code Evennia<a class="headerlink" href="#starting-to-code-evennia" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Time to dip our toe into some coding! Evennia is written and extended in <a class="reference external" href="http://python.org">Python</a>, which
|
||||
is a mature and professional programming language that is very fast to work with.</p>
|
||||
|
|
@ -63,18 +64,18 @@ superuser powers back:</p>
|
|||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="n">unquell</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="section" id="evennia-hello-world">
|
||||
<section id="evennia-hello-world">
|
||||
<h2>Evennia Hello world<a class="headerlink" href="#evennia-hello-world" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">py</span></code> Command (or <code class="docutils literal notranslate"><span class="pre">!</span></code>, which is an alias) allows you as a superuser to execute raw Python from in-
|
||||
game. This is useful for quick testing. From the game’s input line, enter the following:</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">py</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"Hello World!"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Command input</p>
|
||||
<p>The line with <cite>></cite> indicates input to enter in-game, while the lines below are the
|
||||
expected return from that input.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>You will see</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>> print("Hello world!")
|
||||
Hello World!
|
||||
|
|
@ -86,8 +87,8 @@ mean that you are inputting a <em>string</em> (i.e. text). You could also have u
|
|||
Python accepts both. A third variant is triple-quotes (<code class="docutils literal notranslate"><span class="pre">"""..."""</span></code> or <code class="docutils literal notranslate"><span class="pre">'''...'''</span></code>, which work across multiple
|
||||
lines and are common for larger text-blocks. The way we use the <code class="docutils literal notranslate"><span class="pre">py</span></code> command right now only supports
|
||||
single-line input however.</p>
|
||||
</div>
|
||||
<div class="section" id="making-some-text-graphics">
|
||||
</section>
|
||||
<section id="making-some-text-graphics">
|
||||
<h2>Making some text ‘graphics’<a class="headerlink" href="#making-some-text-graphics" title="Permalink to this headline">¶</a></h2>
|
||||
<p>When making a text-game you will, unsurprisingly, be working a lot with text. Even if you have the occational
|
||||
button or even graphical element, the normal process is for the user to input commands as
|
||||
|
|
@ -115,7 +116,7 @@ is to use the <code class="docutils literal notranslate"><span class="pre">.form
|
|||
This is a good idea!
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Functions and Methods</p>
|
||||
<dl class="simple">
|
||||
<dt>Function:</dt><dd><p>Something that performs and action when you <cite>call</cite> it with zero or more <cite>arguments</cite>. A function
|
||||
|
|
@ -124,7 +125,7 @@ is stand-alone in a python module, like <cite>print()</cite></p>
|
|||
<dt>Method:</dt><dd><p>A function that sits “on” an object, like <cite><string>.format()</cite>.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</aside>
|
||||
<p>A method can be thought of as a resource “on” another object. The method knows on which object it
|
||||
sits and can thus affect it in various ways. You access it with the period <code class="docutils literal notranslate"><span class="pre">.</span></code>. In this case, the
|
||||
string has a resource <code class="docutils literal notranslate"><span class="pre">format(...)</span></code> that modifies it. More specifically, it replaced the <code class="docutils literal notranslate"><span class="pre">{}</span></code> marker
|
||||
|
|
@ -210,8 +211,8 @@ gives the normal text color. You can also use RGB (Red-Green-Blue) values from 0
|
|||
color at all). Use the Evennia webclient.</p>
|
||||
</div></blockquote>
|
||||
<p>Use the commands <code class="docutils literal notranslate"><span class="pre">color</span> <span class="pre">ansi</span></code> or <code class="docutils literal notranslate"><span class="pre">color</span> <span class="pre">xterm</span></code> to see which colors are available. Experiment!</p>
|
||||
</div>
|
||||
<div class="section" id="importing-code-from-other-modules">
|
||||
</section>
|
||||
<section id="importing-code-from-other-modules">
|
||||
<h2>Importing code from other modules<a class="headerlink" href="#importing-code-from-other-modules" title="Permalink to this headline">¶</a></h2>
|
||||
<p>As we saw in the previous sections, we used <code class="docutils literal notranslate"><span class="pre">.format</span></code> to format strings and <code class="docutils literal notranslate"><span class="pre">me.msg</span></code> to access
|
||||
the <code class="docutils literal notranslate"><span class="pre">msg</span></code> method on <code class="docutils literal notranslate"><span class="pre">me</span></code>. This use of the full-stop character is used to access all sorts of resources,
|
||||
|
|
@ -225,15 +226,15 @@ structure should look:</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>For now, only add one line to <code class="docutils literal notranslate"><span class="pre">test.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="s2">"Hello World!"</span><span class="p">)</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="s2">"Hello World!"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Python module</p>
|
||||
<p>This is a text file with the <cite>.py</cite> file ending. A module
|
||||
contains Python source code and from within Python one can
|
||||
access its contents by importing it via its python-path.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>Don’t forget to <em>save</em> the file. We just created our first Python <em>module</em>!
|
||||
To use this in-game we have to <em>import</em> it. Try this:</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">py</span> <span class="kn">import</span> <span class="nn">world.test</span>
|
||||
|
|
@ -274,13 +275,13 @@ not very useful.</p>
|
|||
<div><p>We’ll get back to more advanced ways to import code in later tutorial sections - this is an
|
||||
important topic. But for now, let’s press on and resolve this particular problem.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="our-first-own-function">
|
||||
</section>
|
||||
<section id="our-first-own-function">
|
||||
<h2>Our first own function<a class="headerlink" href="#our-first-own-function" title="Permalink to this headline">¶</a></h2>
|
||||
<p>We want to be able to print our hello-world message at any time, not just once after a server
|
||||
reload. Change your <code class="docutils literal notranslate"><span class="pre">mygame/world/test.py</span></code> file to look like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">hello_world</span><span class="p">():</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
||||
<span class="normal">2</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">hello_world</span><span class="p">():</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="s2">"Hello World!"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
|
|
@ -333,8 +334,8 @@ Hello world!
|
|||
Hello world!
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="sending-text-to-others">
|
||||
</section>
|
||||
<section id="sending-text-to-others">
|
||||
<h2>Sending text to others<a class="headerlink" href="#sending-text-to-others" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">print</span></code> command is a standard Python structure. We can use that here in the <code class="docutils literal notranslate"><span class="pre">py</span></code> command since
|
||||
we can se the output. It’s great for debugging and quick testing. But if you need to send a text
|
||||
|
|
@ -355,13 +356,13 @@ is attached to. So if we, for example, had an object <code class="docutils liter
|
|||
to the object <code class="docutils literal notranslate"><span class="pre">you</span></code>.</p>
|
||||
<p>For now, <code class="docutils literal notranslate"><span class="pre">print</span></code> and <code class="docutils literal notranslate"><span class="pre">me.msg</span></code> behaves the same, just remember that <code class="docutils literal notranslate"><span class="pre">print</span></code> is mainly used for
|
||||
debugging and <code class="docutils literal notranslate"><span class="pre">.msg()</span></code> will be more useful for you in the future.</p>
|
||||
</div>
|
||||
<div class="section" id="parsing-python-errors">
|
||||
</section>
|
||||
<section id="parsing-python-errors">
|
||||
<h2>Parsing Python errors<a class="headerlink" href="#parsing-python-errors" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Let’s try this new text-sending in the function we just created. Go back to
|
||||
your <code class="docutils literal notranslate"><span class="pre">test.py</span></code> file and Replace the function with this instead:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">hello_world</span><span class="p">():</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
||||
<span class="normal">2</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">hello_world</span><span class="p">():</span>
|
||||
<span class="n">me</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"Hello World!"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
|
|
@ -371,20 +372,20 @@ then run it like before:</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>No go - this time you get an error!</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="n">File</span> <span class="s2">"./world/test.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">2</span><span class="p">,</span> <span class="ow">in</span> <span class="n">hello_world</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="n">File</span> <span class="s2">"./world/test.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">2</span><span class="p">,</span> <span class="ow">in</span> <span class="n">hello_world</span>
|
||||
<span class="n">me</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"Hello World!"</span><span class="p">)</span>
|
||||
<span class="ne">NameError</span><span class="p">:</span> <span class="n">name</span> <span class="s1">'me'</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">defined</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Errors in the logs</p>
|
||||
<p>In regular use, tracebacks will often appear in the log rather than
|
||||
in the game. Use <cite>evennia –log</cite> to view the log in the terminal. Make
|
||||
sure to scroll back if you expect an error and don’t see it. Use
|
||||
<cite>Ctrl-C</cite> (or <cite>Cmd-C</cite> on Mac) to exit the log-view.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>This is called a <em>traceback</em>. Python’s errors are very friendly and will most of the time tell you
|
||||
exactly what and where things go wrong. It’s important that you learn to parse tracebacks so you
|
||||
know how to fix your code.</p>
|
||||
|
|
@ -404,14 +405,14 @@ the environment into which it is imported. It knew what <code class="docutils li
|
|||
reserved word (as mentioned, it’s just something Evennia came up with for convenience in the <code class="docutils literal notranslate"><span class="pre">py</span></code>
|
||||
command). As far as the module is concerned <code class="docutils literal notranslate"><span class="pre">me</span></code> is an unfamiliar name, appearing out of nowhere.
|
||||
Hence the <code class="docutils literal notranslate"><span class="pre">NameError</span></code>.</p>
|
||||
</div>
|
||||
<div class="section" id="passing-arguments-to-functions">
|
||||
</section>
|
||||
<section id="passing-arguments-to-functions">
|
||||
<h2>Passing arguments to functions<a class="headerlink" href="#passing-arguments-to-functions" title="Permalink to this headline">¶</a></h2>
|
||||
<p>We know that <code class="docutils literal notranslate"><span class="pre">me</span></code> exists at the point when we run the <code class="docutils literal notranslate"><span class="pre">py</span></code> command, because we can do <code class="docutils literal notranslate"><span class="pre">py</span> <span class="pre">me.msg("Hello</span> <span class="pre">World!")</span></code>
|
||||
with no problem. So let’s <em>pass</em> that me along to the function so it knows what it should be.
|
||||
Go back to your <code class="docutils literal notranslate"><span class="pre">test.py</span></code> and change it to this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">who</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
||||
<span class="normal">2</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">who</span><span class="p">):</span>
|
||||
<span class="n">who</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"Hello World!"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
|
|
@ -436,8 +437,8 @@ Python philosophy is to <a class="reference external" href="https://docs.python.
|
|||
rather than to add a lot of code to prevent it from happening. See <a class="reference external" href="https://en.wikipedia.org/wiki/Duck_typing">duck typing</a>
|
||||
and the concept of <em>Leap before you Look</em>.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="finding-others-to-send-to">
|
||||
</section>
|
||||
<section id="finding-others-to-send-to">
|
||||
<h2>Finding others to send to<a class="headerlink" href="#finding-others-to-send-to" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Let’s wrap up this first Python <code class="docutils literal notranslate"><span class="pre">py</span></code> crash-course by finding someone else to send to.</p>
|
||||
<p>In Evennia’s <code class="docutils literal notranslate"><span class="pre">contrib/</span></code> folder (<code class="docutils literal notranslate"><span class="pre">evennia/contrib/tutorial_examples/mirror.py</span></code>) is a handy little
|
||||
|
|
@ -447,12 +448,12 @@ the room it is in.</p>
|
|||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">create</span><span class="o">/</span><span class="n">drop</span> <span class="n">mirror</span><span class="p">:</span><span class="n">contrib</span><span class="o">.</span><span class="n">tutorial_examples</span><span class="o">.</span><span class="n">mirror</span><span class="o">.</span><span class="n">TutorialMirror</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Creating objects</p>
|
||||
<p>The <cite>create</cite> command was first used to create boxes in the
|
||||
<a class="reference external" href="Building-Quickstart">Building Stuff</a> tutorial. Note how it
|
||||
uses a “python-path” to describe where to load the mirror’s code from.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>A mirror should appear in your location.</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">look</span> <span class="n">mirror</span>
|
||||
<span class="n">mirror</span> <span class="n">shows</span> <span class="n">your</span> <span class="n">reflection</span><span class="p">:</span>
|
||||
|
|
@ -478,13 +479,13 @@ Make sure you are in the same location as the mirror and try:</p>
|
|||
</div>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">me.search("name")</span></code> will, by default, search and <em>return</em> an object with the given name found in <em>the same location</em>
|
||||
as the <code class="docutils literal notranslate"><span class="pre">me</span></code> object is. If it can’t find anything you’ll see an error.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Function returns</p>
|
||||
<p>Whereas a function like <cite>print</cite> only prints its arguments, it’s very common
|
||||
for functions/methods to <cite>return</cite> a result of some kind. Think of the function
|
||||
as a machine - you put something in and out comes a result you can use. In the case
|
||||
of <cite>me.search</cite>, it will perform a database search and spit out the object it finds.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">py</span> <span class="n">me</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s2">"dummy"</span><span class="p">)</span>
|
||||
<span class="n">Could</span> <span class="ow">not</span> <span class="n">find</span> <span class="s1">'dummy'</span><span class="o">.</span>
|
||||
</pre></div>
|
||||
|
|
@ -499,16 +500,16 @@ find that Evennia provides ample tools for tagging, searching and finding things
|
|||
</div>
|
||||
<p>The mirror is useful for testing because its <code class="docutils literal notranslate"><span class="pre">.msg</span></code> method just echoes whatever is sent to it back to the room. More common
|
||||
would be to talk to a player character, in which case the text you sent would have appeared in their game client.</p>
|
||||
</div>
|
||||
<div class="section" id="multi-line-py">
|
||||
</section>
|
||||
<section id="multi-line-py">
|
||||
<h2>Multi-line py<a class="headerlink" href="#multi-line-py" title="Permalink to this headline">¶</a></h2>
|
||||
<p>So far we have use <code class="docutils literal notranslate"><span class="pre">py</span></code> in single-line mode, using <code class="docutils literal notranslate"><span class="pre">;</span></code> to separate multiple inputs. This is very convenient
|
||||
when you want to do some quick testing. But you can also start a full multi-line Python interactive interpreter
|
||||
inside Evennia.</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">py</span>
|
||||
<span class="n">Evennia</span> <span class="n">Interactive</span> <span class="n">Python</span> <span class="n">mode</span>
|
||||
<span class="n">Python</span> <span class="mf">3.7</span><span class="o">.</span><span class="mi">1</span> <span class="p">(</span><span class="n">default</span><span class="p">,</span> <span class="n">Oct</span> <span class="mi">22</span> <span class="mi">2018</span><span class="p">,</span> <span class="mi">11</span><span class="p">:</span><span class="mi">21</span><span class="p">:</span><span class="mi">55</span><span class="p">)</span>
|
||||
<span class="p">[</span><span class="n">GCC</span> <span class="mf">8.2</span><span class="o">.</span><span class="mi">0</span><span class="p">]</span> <span class="n">on</span> <span class="n">Linux</span>
|
||||
<span class="n">Python</span> <span class="mf">3.7.1</span> <span class="p">(</span><span class="n">default</span><span class="p">,</span> <span class="n">Oct</span> <span class="mi">22</span> <span class="mi">2018</span><span class="p">,</span> <span class="mi">11</span><span class="p">:</span><span class="mi">21</span><span class="p">:</span><span class="mi">55</span><span class="p">)</span>
|
||||
<span class="p">[</span><span class="n">GCC</span> <span class="mf">8.2.0</span><span class="p">]</span> <span class="n">on</span> <span class="n">Linux</span>
|
||||
<span class="p">[</span><span class="n">py</span> <span class="n">mode</span> <span class="o">-</span> <span class="n">quit</span><span class="p">()</span> <span class="n">to</span> <span class="n">exit</span><span class="p">]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
|
|
@ -529,12 +530,12 @@ the <code class="docutils literal notranslate"><span class="pre">>>></s
|
|||
<span class="n">Closing</span> <span class="n">the</span> <span class="n">Python</span> <span class="n">console</span><span class="o">.</span>
|
||||
<span class="o">></span> <span class="n">py</span><span class="o">/</span><span class="n">noecho</span>
|
||||
<span class="n">Evennia</span> <span class="n">Interactive</span> <span class="n">Python</span> <span class="n">mode</span> <span class="p">(</span><span class="n">no</span> <span class="n">echoing</span> <span class="n">of</span> <span class="n">prompts</span><span class="p">)</span>
|
||||
<span class="n">Python</span> <span class="mf">3.7</span><span class="o">.</span><span class="mi">1</span> <span class="p">(</span><span class="n">default</span><span class="p">,</span> <span class="n">Oct</span> <span class="mi">22</span> <span class="mi">2018</span><span class="p">,</span> <span class="mi">11</span><span class="p">:</span><span class="mi">21</span><span class="p">:</span><span class="mi">55</span><span class="p">)</span>
|
||||
<span class="p">[</span><span class="n">GCC</span> <span class="mf">8.2</span><span class="o">.</span><span class="mi">0</span><span class="p">]</span> <span class="n">on</span> <span class="n">Linux</span>
|
||||
<span class="n">Python</span> <span class="mf">3.7.1</span> <span class="p">(</span><span class="n">default</span><span class="p">,</span> <span class="n">Oct</span> <span class="mi">22</span> <span class="mi">2018</span><span class="p">,</span> <span class="mi">11</span><span class="p">:</span><span class="mi">21</span><span class="p">:</span><span class="mi">55</span><span class="p">)</span>
|
||||
<span class="p">[</span><span class="n">GCC</span> <span class="mf">8.2.0</span><span class="p">]</span> <span class="n">on</span> <span class="n">Linux</span>
|
||||
<span class="p">[</span><span class="n">py</span> <span class="n">mode</span> <span class="o">-</span> <span class="n">quit</span><span class="p">()</span> <span class="n">to</span> <span class="n">exit</span><span class="p">]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">interactive py</p>
|
||||
<ul class="simple">
|
||||
<li><p>Start with <cite>py</cite>.</p></li>
|
||||
|
|
@ -542,7 +543,7 @@ the <code class="docutils literal notranslate"><span class="pre">>>></s
|
|||
<li><p>All your inputs will now be interpreted as Python code.</p></li>
|
||||
<li><p>Exit with <cite>quit()</cite>.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
<p>We can now enter multi-line Python code:</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">a</span> <span class="o">=</span> <span class="s2">"Test"</span>
|
||||
<span class="o">></span> <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"This is a </span><span class="si">{</span><span class="n">a</span><span class="si">}</span><span class="s2">."</span><span class="p">}</span>
|
||||
|
|
@ -586,8 +587,8 @@ string. Let’s combine this with searching for the mirror.</p>
|
|||
<span class="n">Closing</span> <span class="n">the</span> <span class="n">Python</span> <span class="n">console</span><span class="o">.</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="other-ways-to-test-python-code">
|
||||
</section>
|
||||
<section id="other-ways-to-test-python-code">
|
||||
<h2>Other ways to test Python code<a class="headerlink" href="#other-ways-to-test-python-code" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">py</span></code> command is very powerful for experimenting with Python in-game. It’s great for quick testing.
|
||||
But you are still limited to working over telnet or the webclient, interfaces that doesn’t know anything
|
||||
|
|
@ -612,7 +613,7 @@ We will cover more advanced searching later, but suffice to say, you put your ow
|
|||
get at the first of them (counting starts from 0).</p>
|
||||
</div></blockquote>
|
||||
<p>Use <code class="docutils literal notranslate"><span class="pre">Ctrl-D</span></code> (<code class="docutils literal notranslate"><span class="pre">Cmd-D</span></code> on Mac) or <code class="docutils literal notranslate"><span class="pre">quit()</span></code> to exit the Python console.</p>
|
||||
<div class="section" id="ipython">
|
||||
<section id="ipython">
|
||||
<h3>ipython<a class="headerlink" href="#ipython" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The default Python shell is quite limited and ugly. It’s <em>highly</em> recommended to install <code class="docutils literal notranslate"><span class="pre">ipython</span></code> instead. This
|
||||
is a much nicer, third-party Python interpreter with colors and many usability improvements.</p>
|
||||
|
|
@ -622,7 +623,7 @@ is a much nicer, third-party Python interpreter with colors and many usability i
|
|||
<p>If <code class="docutils literal notranslate"><span class="pre">ipython</span></code> is installed, <code class="docutils literal notranslate"><span class="pre">evennia</span> <span class="pre">shell</span></code> will use it automatically.</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">evennia</span> <span class="n">shell</span>
|
||||
<span class="o">...</span>
|
||||
<span class="n">IPython</span> <span class="mf">7.4</span><span class="o">.</span><span class="mi">0</span> <span class="o">--</span> <span class="n">An</span> <span class="n">enhanced</span> <span class="n">Interactive</span> <span class="n">Python</span><span class="o">.</span> <span class="n">Type</span> <span class="s1">'?'</span> <span class="k">for</span> <span class="n">help</span>
|
||||
<span class="n">IPython</span> <span class="mf">7.4.0</span> <span class="o">--</span> <span class="n">An</span> <span class="n">enhanced</span> <span class="n">Interactive</span> <span class="n">Python</span><span class="o">.</span> <span class="n">Type</span> <span class="s1">'?'</span> <span class="k">for</span> <span class="n">help</span>
|
||||
<span class="n">In</span> <span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
|
|
@ -647,9 +648,9 @@ want to see the entire source code.</p>
|
|||
be gone after you shut down the interpreter (but ipython will remember your input history). For making long-lasting
|
||||
Python code, we need to save it in a Python module, like we did for <cite>world/test.py</cite>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="conclusions">
|
||||
</section>
|
||||
</section>
|
||||
<section id="conclusions">
|
||||
<h2>Conclusions<a class="headerlink" href="#conclusions" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This covers quite a lot of basic Python usage. We printed and formatted strings, defined our own
|
||||
first function, fixed an error and even searched and talked to a mirror! Being able to access
|
||||
|
|
@ -657,8 +658,8 @@ python inside and outside of the game is an important skill for testing and debu
|
|||
practice you will be writing most your code in Python modules.</p>
|
||||
<p>To that end we also created a first new Python module in the <code class="docutils literal notranslate"><span class="pre">mygame/</span></code> game dir, then imported and used it.
|
||||
Now let’s look at the rest of the stuff you’ve got going on inside that <code class="docutils literal notranslate"><span class="pre">mygame/</span></code> folder …</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Python Classes and objects — 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" />
|
||||
|
|
@ -46,11 +47,11 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="python-classes-and-objects">
|
||||
<section id="python-classes-and-objects">
|
||||
<h1>Python Classes and objects<a class="headerlink" href="#python-classes-and-objects" title="Permalink to this headline">¶</a></h1>
|
||||
<p>We have now learned how to run some simple Python code from inside (and outside) your game server.
|
||||
We have also taken a look at what our game dir looks and what is where. Now we’ll start to use it.</p>
|
||||
<div class="section" id="importing-things">
|
||||
<section id="importing-things">
|
||||
<h2>Importing things<a class="headerlink" href="#importing-things" title="Permalink to this headline">¶</a></h2>
|
||||
<p>No one writes something as big as an online game in one single huge file. Instead one breaks up the
|
||||
code into separate files (modules). Each module is dedicated to different purposes. Not only does
|
||||
|
|
@ -74,12 +75,12 @@ Hello World!
|
|||
</div>
|
||||
<p>If you followed earlier tutorial lessons, the <code class="docutils literal notranslate"><span class="pre">mygame/world/test.py</span></code> file should look like this (if
|
||||
not, make it so):</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">who</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
||||
<span class="normal">2</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">who</span><span class="p">):</span>
|
||||
<span class="n">who</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"Hello World!"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Remember:</p>
|
||||
<ul class="simple">
|
||||
<li><p>Indentation matters in Python</p></li>
|
||||
|
|
@ -88,7 +89,7 @@ not, make it so):</p>
|
|||
<li><p>Empty lines are fine</p></li>
|
||||
<li><p>Anything on a line after a <cite>#</cite> is a <cite>comment</cite>, ignored by Python</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
<p>The <em>python_path</em> describes the relation between Python resources, both between and inside
|
||||
Python <em>modules</em> (that is, files ending with .py). A python-path separates each part of the
|
||||
path <code class="docutils literal notranslate"><span class="pre">.</span></code> and always skips the <code class="docutils literal notranslate"><span class="pre">.py</span></code> file endings. Also, Evennia already knows to start looking
|
||||
|
|
@ -141,8 +142,8 @@ easy to read as possible, and renaming adds another layer of potential confusion
|
|||
multi-line interpreter.</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">py</span>
|
||||
<span class="n">Evennia</span> <span class="n">Interactive</span> <span class="n">Python</span> <span class="n">mode</span>
|
||||
<span class="n">Python</span> <span class="mf">3.7</span><span class="o">.</span><span class="mi">1</span> <span class="p">(</span><span class="n">default</span><span class="p">,</span> <span class="n">Oct</span> <span class="mi">22</span> <span class="mi">2018</span><span class="p">,</span> <span class="mi">11</span><span class="p">:</span><span class="mi">21</span><span class="p">:</span><span class="mi">55</span><span class="p">)</span>
|
||||
<span class="p">[</span><span class="n">GCC</span> <span class="mf">8.2</span><span class="o">.</span><span class="mi">0</span><span class="p">]</span> <span class="n">on</span> <span class="n">Linux</span>
|
||||
<span class="n">Python</span> <span class="mf">3.7.1</span> <span class="p">(</span><span class="n">default</span><span class="p">,</span> <span class="n">Oct</span> <span class="mi">22</span> <span class="mi">2018</span><span class="p">,</span> <span class="mi">11</span><span class="p">:</span><span class="mi">21</span><span class="p">:</span><span class="mi">55</span><span class="p">)</span>
|
||||
<span class="p">[</span><span class="n">GCC</span> <span class="mf">8.2.0</span><span class="p">]</span> <span class="n">on</span> <span class="n">Linux</span>
|
||||
<span class="p">[</span><span class="n">py</span> <span class="n">mode</span> <span class="o">-</span> <span class="n">quit</span><span class="p">()</span> <span class="n">to</span> <span class="n">exit</span><span class="p">]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
|
|
@ -160,21 +161,21 @@ Closing the Python console.
|
|||
</div>
|
||||
<p>The same goes when writing code in a module - in most Python modules you will see a bunch of
|
||||
imports at the top, resources that are then used by all code in that module.</p>
|
||||
</div>
|
||||
<div class="section" id="on-classes-and-objects">
|
||||
</section>
|
||||
<section id="on-classes-and-objects">
|
||||
<h2>On classes and objects<a class="headerlink" href="#on-classes-and-objects" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Now that we know about imports, let look at a real Evennia module and try to understand it.</p>
|
||||
<p>Open <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/objects.py</span></code> in your text editor of choice.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||||
<span class="sd">module docstring</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultObject</span>
|
||||
|
|
@ -186,12 +187,12 @@ imports at the top, resources that are then used by all code in that module.</p>
|
|||
<span class="k">pass</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Docstrings vs Comments</p>
|
||||
<p>A docstring is not the same as a comment (created by <cite>#</cite>). A
|
||||
docstring is not ignored by Python but is an integral part of the thing
|
||||
it is documenting (the module and the class in this case).</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>The real file is much longer but we can ignore the multi-line strings (<code class="docutils literal notranslate"><span class="pre">"""</span> <span class="pre">...</span> <span class="pre">"""</span></code>). These serve
|
||||
as documentation-strings, or <em>docstrings</em> for the module (at the top) and the <code class="docutils literal notranslate"><span class="pre">class</span></code> below.</p>
|
||||
<p>Below the module doc string we have the import. In this case we are importing a resource
|
||||
|
|
@ -203,24 +204,24 @@ well, to pass and don’t do anything.</p>
|
|||
<p>We will get back to this module in the <a class="reference internal" href="Learning-Typeclasses.html"><span class="doc">next lesson</span></a>. First we need to do a
|
||||
little detour to understand what a ‘class’, an ‘object’ or ‘instance’ is. These are fundamental
|
||||
things to understand before you can use Evennia efficiently.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">OOP</p>
|
||||
<p>Classes, objects, instances and inheritance are fundamental to Python. This and some
|
||||
other concepts are often clumped together under the term Object-Oriented-Programming (OOP).</p>
|
||||
</div>
|
||||
<div class="section" id="classes-and-instances">
|
||||
</aside>
|
||||
<section id="classes-and-instances">
|
||||
<h3>Classes and instances<a class="headerlink" href="#classes-and-instances" title="Permalink to this headline">¶</a></h3>
|
||||
<p>A ‘class’ can be seen as a ‘template’ for a ‘type’ of object. The class describes the basic functionality
|
||||
of everyone of that class. For example, we could have a class <code class="docutils literal notranslate"><span class="pre">Monster</span></code> which has resources for moving itself
|
||||
from room to room.</p>
|
||||
<p>Open a new file <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/monsters.py</span></code>. Add the following simple class:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="k">class</span> <span class="nc">Monster</span><span class="p">:</span>
|
||||
|
||||
<span class="n">key</span> <span class="o">=</span> <span class="s2">"Monster"</span>
|
||||
|
|
@ -234,13 +235,13 @@ from room to room.</p>
|
|||
at least one argument (almost always written as <code class="docutils literal notranslate"><span class="pre">self</span></code> although you could in principle use
|
||||
another name), which is a reference back to itself. So when we print <code class="docutils literal notranslate"><span class="pre">self.key</span></code> we are referring
|
||||
back to the <code class="docutils literal notranslate"><span class="pre">key</span></code> on the class.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Terms</p>
|
||||
<ul class="simple">
|
||||
<li><p>A <cite>class</cite> is a code template describing a ‘type’ of something</p></li>
|
||||
<li><p>An <cite>object</cite> is an <cite>instance</cite> of a <cite>class</cite>. Like using a mold to cast tin soldiers, one class can be <cite>instantiated</cite> into any number of object-instances.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
<p>A class is just a template. Before it can be used, we must create an <em>instance</em> of the class. If
|
||||
<code class="docutils literal notranslate"><span class="pre">Monster</span></code> is a class, then an instance is Fluffy, the individual red dragon. You instantiate
|
||||
by <em>calling</em> the class, much like you would a function:</p>
|
||||
|
|
@ -272,14 +273,14 @@ Monster is moving!
|
|||
instance. We can have them move as many times as we want. But no matter how many dragons we
|
||||
create, they will all show the same printout since <code class="docutils literal notranslate"><span class="pre">key</span></code> is always fixed as “Monster”.</p>
|
||||
<p>Let’s make the class a little more flexible:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="k">class</span> <span class="nc">Monster</span><span class="p">:</span>
|
||||
|
||||
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
|
||||
|
|
@ -299,13 +300,13 @@ way:</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>Or you can use a separate terminal and restart from outside the game:</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">On reloading</p>
|
||||
<p>Reloading with the python mode gets a little annoying since you need to redo everything
|
||||
after every reload. Just keep in mind that during regular development you will not be
|
||||
working this way. The in-game python mode is practical for quick fixes and experiments like
|
||||
this, but actual code is normally written externally, in python modules.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ evennia reload (or restart)
|
||||
</pre></div>
|
||||
</div>
|
||||
|
|
@ -319,13 +320,13 @@ Fluffy is moving!
|
|||
</div>
|
||||
<p>Now we passed <code class="docutils literal notranslate"><span class="pre">"Fluffy"</span></code> as an argument to the class. This went into <code class="docutils literal notranslate"><span class="pre">__init__</span></code> and set <code class="docutils literal notranslate"><span class="pre">self.key</span></code>, which we
|
||||
later used to print with the right name! Again, note that we didn’t include <code class="docutils literal notranslate"><span class="pre">self</span></code> when calling.</p>
|
||||
</div>
|
||||
<div class="section" id="what-s-so-good-about-objects">
|
||||
</section>
|
||||
<section id="what-s-so-good-about-objects">
|
||||
<h3>What’s so good about objects?<a class="headerlink" href="#what-s-so-good-about-objects" title="Permalink to this headline">¶</a></h3>
|
||||
<p>So far all we’ve seen a class do is to behave our first <code class="docutils literal notranslate"><span class="pre">hello_world</span></code> function but more complex. We
|
||||
could just have made a function:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">monster_move_around</span><span class="p">(</span><span class="n">key</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
||||
<span class="normal">2</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="k">def</span> <span class="nf">monster_move_around</span><span class="p">(</span><span class="n">key</span><span class="p">):</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">key</span><span class="si">}</span><span class="s2"> is moving!"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
|
|
@ -350,38 +351,38 @@ objects in turn:</p>
|
|||
<li><p>A multi-dimenstional data-point for a complex economic simulation</p></li>
|
||||
<li><p>And so much more!</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="classes-can-have-children">
|
||||
</section>
|
||||
<section id="classes-can-have-children">
|
||||
<h3>Classes can have children<a class="headerlink" href="#classes-can-have-children" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Classes can <em>inherit</em> from each other. A “child” class will inherit everything from its “parent” class. But if
|
||||
the child adds something with the same name as its parent, it will <em>override</em> whatever it got from its parent.</p>
|
||||
<p>Let’s expand <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/monsters.py</span></code> with another class:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="k">class</span> <span class="nc">Monster</span><span class="p">:</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> This is a base class for Monster.</span>
|
||||
|
|
@ -413,12 +414,12 @@ the child adds something with the same name as its parent, it will <em>override<
|
|||
as exemplified for the new <code class="docutils literal notranslate"><span class="pre">firebreath</span></code> method.</p>
|
||||
<p>We created the new class <code class="docutils literal notranslate"><span class="pre">Dragon</span></code> but we also specified that <code class="docutils literal notranslate"><span class="pre">Monster</span></code> is the <em>parent</em> of <code class="docutils literal notranslate"><span class="pre">Dragon</span></code> but adding
|
||||
the parent in parenthesis. <code class="docutils literal notranslate"><span class="pre">class</span> <span class="pre">Classname(Parent)</span></code> is the way to do this.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Multi-inheritance</p>
|
||||
<p>It’s possible to add more comma-separated parents to a class. You should usually avoid
|
||||
this until you <cite>really</cite> know what you are doing. A single parent will be enough for almost
|
||||
every case you’ll need.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>Let’s try out our new class. First <code class="docutils literal notranslate"><span class="pre">reload</span></code> the server and the do</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>> py
|
||||
> from typeclasses.monsters import Dragon
|
||||
|
|
@ -435,15 +436,15 @@ available for <code class="docutils literal notranslate"><span class="pre">Drago
|
|||
can breathe fire.</p>
|
||||
<p>One can also force a class to use resources from the parent even if you are overriding some of it. This is done
|
||||
with the <code class="docutils literal notranslate"><span class="pre">super()</span></code> method. Modify your <code class="docutils literal notranslate"><span class="pre">Dragon</span></code> class as follows:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ... </span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ... </span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Dragon</span><span class="p">(</span><span class="n">Monster</span><span class="p">):</span>
|
||||
|
||||
|
|
@ -472,17 +473,17 @@ The world trembles.
|
|||
about the trembling world we added in the <code class="docutils literal notranslate"><span class="pre">Dragon</span></code> class.</p>
|
||||
<p>Inheritance is very powerful because it allows you to organize and re-use code while only adding the special things
|
||||
you want to change. Evennia uses this concept a lot.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="summary">
|
||||
</section>
|
||||
</section>
|
||||
<section id="summary">
|
||||
<h2>Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2>
|
||||
<p>We have created our first dragons from classes. We have learned a little about how you <em>instantiate</em> a class
|
||||
into an <em>object</em>. We have seen some examples of <em>inheritance</em> and we tested to <em>override</em> a method in the parent
|
||||
with one in the child class. We also used <code class="docutils literal notranslate"><span class="pre">super()</span></code> to good effect.</p>
|
||||
<p>We have used pretty much raw Python so far. In the coming lessons we’ll start to look at the extra bits that Evennia
|
||||
provides. But first we need to learn just where to find everything.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Searching for things — 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" />
|
||||
|
|
@ -46,23 +47,23 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="searching-for-things">
|
||||
<section id="searching-for-things">
|
||||
<h1>Searching for things<a class="headerlink" href="#searching-for-things" title="Permalink to this headline">¶</a></h1>
|
||||
<p>We have gone through how to create the various entities in Evennia. But creating something is of little use
|
||||
if we cannot find and use it afterwards.</p>
|
||||
<div class="section" id="main-search-functions">
|
||||
<section id="main-search-functions">
|
||||
<h2>Main search functions<a class="headerlink" href="#main-search-functions" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The base tools are the <code class="docutils literal notranslate"><span class="pre">evennia.search_*</span></code> functions, such as <code class="docutils literal notranslate"><span class="pre">evennia.search_object</span></code>.</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="n">rose</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">search_object</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="s2">"rose"</span><span class="p">)</span>
|
||||
<span class="n">acct</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">search_account</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="s2">"MyAccountName"</span><span class="p">,</span> <span class="n">email</span><span class="o">=</span><span class="s2">"foo@bar.com"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Querysets</p>
|
||||
<p>What is returned from the main search functions is actually a <cite>queryset</cite>. They can be
|
||||
treated like lists except that they can’t modified in-place. We’ll discuss querysets in
|
||||
the <cite>next lesson</cite> <Django-queries>`_.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>Strings are always case-insensitive, so searching for <code class="docutils literal notranslate"><span class="pre">"rose"</span></code>, <code class="docutils literal notranslate"><span class="pre">"Rose"</span></code> or <code class="docutils literal notranslate"><span class="pre">"rOsE"</span></code> give the same results.
|
||||
It’s important to remember that what is returned from these search methods is a <em>listing</em> of 0, one or more
|
||||
elements - all the matches to your search. To get the first match:</p>
|
||||
|
|
@ -83,8 +84,8 @@ more than one match is a sign of a problem and you need to handle this case your
|
|||
</div>
|
||||
<p>There are equivalent search functions for all the main resources. You can find a listing of them
|
||||
<a class="reference internal" href="../../../Evennia-API.html"><span class="doc">in the Search functions section</span></a> of the API frontpage.</p>
|
||||
</div>
|
||||
<div class="section" id="searching-using-object-search">
|
||||
</section>
|
||||
<section id="searching-using-object-search">
|
||||
<h2>Searching using Object.search<a class="headerlink" href="#searching-using-object-search" title="Permalink to this headline">¶</a></h2>
|
||||
<p>On the <code class="docutils literal notranslate"><span class="pre">DefaultObject</span></code> is a <code class="docutils literal notranslate"><span class="pre">.search</span></code> method which we have already tried out when we made Commands. For
|
||||
this to be used you must already have an object available:</p>
|
||||
|
|
@ -99,17 +100,17 @@ things in obj’s inventory or in the same room).</p></li>
|
|||
<li><p>On a no-match or multimatch, <code class="docutils literal notranslate"><span class="pre">.search</span></code> will automatically send an error message to <code class="docutils literal notranslate"><span class="pre">obj</span></code>.</p></li>
|
||||
</ul>
|
||||
<p>So this method handles error messaging for you. A very common way to use it is in commands:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">MyCommand</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
|
||||
|
|
@ -145,8 +146,8 @@ here’s how you’d find something only in your inventory:</p>
|
|||
</div>
|
||||
<p>With <code class="docutils literal notranslate"><span class="pre">quiet=True</span></code> the user will not be notified on zero or multi-match errors. Instead you are expected to handle this
|
||||
yourself and what you get back is now a list of zero, one or more matches!</p>
|
||||
</div>
|
||||
<div class="section" id="what-can-be-searched-for">
|
||||
</section>
|
||||
<section id="what-can-be-searched-for">
|
||||
<h2>What can be searched for<a class="headerlink" href="#what-can-be-searched-for" title="Permalink to this headline">¶</a></h2>
|
||||
<p>These are the main database entities one can search for:</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -159,11 +160,11 @@ yourself and what you get back is now a list of zero, one or more matches!</p>
|
|||
</ul>
|
||||
<p>Most of the time you’ll likely spend your time searching for Objects and the occasional Accounts.</p>
|
||||
<p>So to find an entity, what can be searched for?</p>
|
||||
<div class="section" id="search-by-key">
|
||||
<section id="search-by-key">
|
||||
<h3>Search by key<a class="headerlink" href="#search-by-key" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">key</span></code> is the name of the entity. Searching for this is always case-insensitive.</p>
|
||||
</div>
|
||||
<div class="section" id="search-by-aliases">
|
||||
</section>
|
||||
<section id="search-by-aliases">
|
||||
<h3>Search by aliases<a class="headerlink" href="#search-by-aliases" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Objects and Accounts can have any number of aliases. When searching for <code class="docutils literal notranslate"><span class="pre">key</span></code> these will searched too,
|
||||
you can’t easily search only for aliases.</p>
|
||||
|
|
@ -172,8 +173,8 @@ you can’t easily search only for aliases.</p>
|
|||
</div>
|
||||
<p>If the above <code class="docutils literal notranslate"><span class="pre">rose</span></code> has a <code class="docutils literal notranslate"><span class="pre">key</span></code> <code class="docutils literal notranslate"><span class="pre">"Rose"</span></code>, it can now also be found by searching for <code class="docutils literal notranslate"><span class="pre">flower</span></code>. In-game
|
||||
you can assign new aliases to things with the <code class="docutils literal notranslate"><span class="pre">alias</span></code> command.</p>
|
||||
</div>
|
||||
<div class="section" id="search-by-location">
|
||||
</section>
|
||||
<section id="search-by-location">
|
||||
<h3>Search by location<a class="headerlink" href="#search-by-location" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Only Objects (things inheriting from <code class="docutils literal notranslate"><span class="pre">evennia.DefaultObject</span></code>) has a location. This is usually a room.
|
||||
The <code class="docutils literal notranslate"><span class="pre">Object.search</span></code> method will automatically limit it search by location, but it also works for the
|
||||
|
|
@ -181,8 +182,8 @@ general search function. If we assume <code class="docutils literal notranslate"
|
|||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">chest</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">search_object</span><span class="p">(</span><span class="s2">"Treasure chest"</span><span class="p">,</span> <span class="n">location</span><span class="o">=</span><span class="n">room</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="search-by-tags">
|
||||
</section>
|
||||
<section id="search-by-tags">
|
||||
<h3>Search by Tags<a class="headerlink" href="#search-by-tags" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Think of a <a class="reference internal" href="../../../Components/Tags.html"><span class="doc">Tag</span></a> as the label the airport puts on your luggage when flying.
|
||||
Everyone going on the same plane gets a tag grouping them together so the airport can know what should
|
||||
|
|
@ -215,8 +216,8 @@ we can get all tagged entities within that category:</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>This gets all three books.</p>
|
||||
</div>
|
||||
<div class="section" id="search-by-attribute">
|
||||
</section>
|
||||
<section id="search-by-attribute">
|
||||
<h3>Search by Attribute<a class="headerlink" href="#search-by-attribute" title="Permalink to this headline">¶</a></h3>
|
||||
<p>We can also search by the <a class="reference internal" href="../../../Components/Attributes.html"><span class="doc">Attributes</span></a> associated with entities.</p>
|
||||
<p>For example, let’s give our rose thorns:</p>
|
||||
|
|
@ -234,8 +235,8 @@ we can get all tagged entities within that category:</p>
|
|||
<div><p>Searching by Attribute can be very practical. But if you plan to do a search very often, searching
|
||||
by-tag is generally faster.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="search-by-typeclass">
|
||||
</section>
|
||||
<section id="search-by-typeclass">
|
||||
<h3>Search by Typeclass<a class="headerlink" href="#search-by-typeclass" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Sometimes it’s useful to find all objects of a specific Typeclass. All of Evennia’s search tools support this.</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">all_roses</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">search_object</span><span class="p">(</span><span class="n">typeclass</span><span class="o">=</span><span class="s2">"typeclasses.flowers.Rose"</span><span class="p">)</span>
|
||||
|
|
@ -251,8 +252,8 @@ by-tag is generally faster.</p>
|
|||
</div>
|
||||
<p>This last way of searching is a simple form of a Django <em>query</em>. This is a way to express SQL queries using
|
||||
Python. We’ll cover this some more as an <a class="reference external" href="#Extra-Credits">Extra-credits</a> section at the end of this lesson.</p>
|
||||
</div>
|
||||
<div class="section" id="search-by-dbref">
|
||||
</section>
|
||||
<section id="search-by-dbref">
|
||||
<h3>Search by dbref<a class="headerlink" href="#search-by-dbref" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The database id or <code class="docutils literal notranslate"><span class="pre">#dbref</span></code> is unique and never-reused within each database table. In search methods you can
|
||||
replace the search for <code class="docutils literal notranslate"><span class="pre">key</span></code> with the dbref to search for. This must be written as a string <code class="docutils literal notranslate"><span class="pre">#dbref</span></code>:</p>
|
||||
|
|
@ -269,9 +270,9 @@ replace the search for <code class="docutils literal notranslate"><span class="p
|
|||
and tied to the exact layout of the database. In 99% of cases you should pass the actual objects
|
||||
around and search by key/tags/attribute instead.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="finding-objects-relative-each-other">
|
||||
</section>
|
||||
</section>
|
||||
<section id="finding-objects-relative-each-other">
|
||||
<h2>Finding objects relative each other<a class="headerlink" href="#finding-objects-relative-each-other" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Let’s consider a <code class="docutils literal notranslate"><span class="pre">chest</span></code> with a <code class="docutils literal notranslate"><span class="pre">coin</span></code> inside it. The chests stand in a room <code class="docutils literal notranslate"><span class="pre">dungeon</span></code>. In the dungeon is also
|
||||
a <code class="docutils literal notranslate"><span class="pre">door</span></code>. This is an exit leading outside.</p>
|
||||
|
|
@ -303,15 +304,15 @@ We can also find what is inside each object. This is a list of things.</p>
|
|||
<li><p><code class="docutils literal notranslate"><span class="pre">door.destination</span></code> is <code class="docutils literal notranslate"><span class="pre">outside</span></code> (or wherever the door leads)</p></li>
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">room.destination</span></code> is <code class="docutils literal notranslate"><span class="pre">None</span></code> (same for all the other non-exit objects)</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="summary">
|
||||
</section>
|
||||
<section id="summary">
|
||||
<h2>Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Knowing how to find things is important and the tools from this section will serve you well. For most of your needs
|
||||
these tools will be all you need …</p>
|
||||
<p>… but not always. In the next lesson we will dive further into more complex searching when we look at
|
||||
Django queries and querysets in earnest.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Starting Tutorial (Part 1) — 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" />
|
||||
|
|
@ -45,9 +46,9 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="starting-tutorial-part-1">
|
||||
<section id="starting-tutorial-part-1">
|
||||
<h1>Starting Tutorial (Part 1)<a class="headerlink" href="#starting-tutorial-part-1" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Tutorial Parts</p>
|
||||
<dl class="simple">
|
||||
<dt><strong>Part 1: What we have</strong></dt><dd><p>A tour of Evennia and how to use the tools, including an introduction to Python.</p>
|
||||
|
|
@ -61,12 +62,12 @@
|
|||
<dt>Part 5: <a class="reference external" href="../Part5/Starting-Part5.html">Showing the world</a></dt><dd><p>Taking our new game online and let players try it out</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</aside>
|
||||
<p>Welcome to Evennia! This multi-part Tutorial will help you get off the ground. It consists
|
||||
of five parts, each with several lessons. You can pick what seems interesting, but if you
|
||||
follow through to the end you will have created a little online game of your own to play
|
||||
and share with others!</p>
|
||||
<div class="section" id="lessons-of-part-1-what-we-have">
|
||||
<section id="lessons-of-part-1-what-we-have">
|
||||
<h2>Lessons of Part 1 - “What we have”<a class="headerlink" href="#lessons-of-part-1-what-we-have" title="Permalink to this headline">¶</a></h2>
|
||||
<ol class="simple">
|
||||
<li><p>Introduction (you are here)</p></li>
|
||||
|
|
@ -88,10 +89,10 @@ and how to find things we are looking for. We will also dive into some of things
|
|||
need to know to fully utilize the system, including giving you a brief rundown of Python concepts. If you are
|
||||
an experienced Python programmer, some sections may feel a bit basic, but you will at least not have seen
|
||||
these concepts in the context of Evennia before.</p>
|
||||
</div>
|
||||
<div class="section" id="things-you-will-need">
|
||||
</section>
|
||||
<section id="things-you-will-need">
|
||||
<h2>Things you will need<a class="headerlink" href="#things-you-will-need" title="Permalink to this headline">¶</a></h2>
|
||||
<div class="section" id="a-command-line">
|
||||
<section id="a-command-line">
|
||||
<h3>A Command line<a class="headerlink" href="#a-command-line" title="Permalink to this headline">¶</a></h3>
|
||||
<p>First of all, you need to know how to find your Terminal/Console in your OS. The Evennia server can be controlled
|
||||
from in-game, but you <em>will</em> need to use the command-line to get anywhere. Here are some starters:</p>
|
||||
|
|
@ -102,8 +103,8 @@ from in-game, but you <em>will</em> need to use the command-line to get anywhere
|
|||
<div><p>Note that we only use forward-slashes <code class="docutils literal notranslate"><span class="pre">/</span></code> to show file system paths in this documentation. Windows users need
|
||||
to convert this to back-slashes <code class="docutils literal notranslate"><span class="pre">\</span></code> in their heads.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="a-mud-client">
|
||||
</section>
|
||||
<section id="a-mud-client">
|
||||
<h3>A MUD client<a class="headerlink" href="#a-mud-client" title="Permalink to this headline">¶</a></h3>
|
||||
<p>You might already have a MUD-client you prefer. Check out the <a class="reference internal" href="../../../Setup/Client-Support-Grid.html"><span class="doc">grid of supported clients</span></a> for aid.
|
||||
If telnet’s not your thing, you can also just use Evennia’s web client in your browser.</p>
|
||||
|
|
@ -113,8 +114,8 @@ as labels to represent all the historically different forms of text-based multip
|
|||
like MUD, MUX, MUSH, MUCK, MOO and others. Evennia can be used to create all those game-styles
|
||||
and more.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="an-editor">
|
||||
</section>
|
||||
<section id="an-editor">
|
||||
<h3>An Editor<a class="headerlink" href="#an-editor" title="Permalink to this headline">¶</a></h3>
|
||||
<p>You need a text-editor to edit Python source files. Most everything that can edit and output raw
|
||||
text works (so not Word).</p>
|
||||
|
|
@ -127,8 +128,8 @@ Evennia is to a very large degree coded in VIM, but that’s not suitable for be
|
|||
<div><p>Hint: When setting up your editor, make sure that pressing TAB inserts <em>4 spaces</em> rather than a Tab-character. Since
|
||||
Python is whitespace-aware, this will make your life a lot easier.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="set-up-a-game-dir-for-the-tutorial">
|
||||
</section>
|
||||
<section id="set-up-a-game-dir-for-the-tutorial">
|
||||
<h3>Set up a game dir for the tutorial<a class="headerlink" href="#set-up-a-game-dir-for-the-tutorial" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Next you should make sure you have <a class="reference internal" href="../../../Setup/Setup-Quickstart.html"><span class="doc">installed Evennia</span></a>. If you followed the instructions
|
||||
you will already have created a game-dir. You could use that for this tutorial or you may want to do the
|
||||
|
|
@ -168,9 +169,9 @@ the log again just run</p>
|
|||
<p>You should now be good to go!</p>
|
||||
<div class="toctree-wrapper compound">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>The Tutorial World — 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" />
|
||||
|
|
@ -46,7 +47,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="the-tutorial-world">
|
||||
<section id="the-tutorial-world">
|
||||
<h1>The Tutorial World<a class="headerlink" href="#the-tutorial-world" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The <em>Tutorial World</em> is a small and functioning MUD-style game world shipped with Evennia.<br />It’s a small showcase of what is possible. It can also be useful for those who have an easier
|
||||
time learning by deconstructing existing code.</p>
|
||||
|
|
@ -65,7 +66,7 @@ to discover the whereabouts of a mythical weapon. Make sure you don’t play as
|
|||
</div>
|
||||
<p>Enter the new exit by writing <code class="docutils literal notranslate"><span class="pre">tutorial</span></code>. Enjoy! If you succeed you will eventually
|
||||
end up back in Limbo.</p>
|
||||
<div class="section" id="gameplay">
|
||||
<section id="gameplay">
|
||||
<h2>Gameplay<a class="headerlink" href="#gameplay" title="Permalink to this headline">¶</a></h2>
|
||||
<p><img alt="the castle off the moor" src="https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/22916c25-6299-453d-a221-446ec839f567/da2pmzu-46d63c6d-9cdc-41dd-87d6-1106db5a5e1a.jpg/v1/fill/w_600,h_849,q_75,strp/the_castle_off_the_moor_by_griatch_art_da2pmzu-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3siaGVpZ2h0IjoiPD04NDkiLCJwYXRoIjoiXC9mXC8yMjkxNmMyNS02Mjk5LTQ1M2QtYTIyMS00NDZlYzgzOWY1NjdcL2RhMnBtenUtNDZkNjNjNmQtOWNkYy00MWRkLTg3ZDYtMTEwNmRiNWE1ZTFhLmpwZyIsIndpZHRoIjoiPD02MDAifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.omuS3D1RmFiZCy9OSXiIita-HxVGrBok3_7asq0rflw" /></p>
|
||||
<p><em>To get into the mood of this miniature quest, imagine you are an adventurer out to find fame and
|
||||
|
|
@ -75,7 +76,7 @@ this is a chance to adventure that you cannot turn down!</em></p>
|
|||
<p><em>You reach the ocean in the midst of a raging thunderstorm. With wind and rain screaming in your
|
||||
face you stand where the moor meets the sea along a high, rocky coast …</em></p>
|
||||
<hr class="docutils" />
|
||||
<div class="section" id="hints">
|
||||
<section id="hints">
|
||||
<h3>Hints:<a class="headerlink" href="#hints" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Look at everything. While a demo, this is not necessarily trivial, depending on your experience with
|
||||
|
|
@ -95,9 +96,9 @@ which commands are available at any given time.</p></li>
|
|||
<li><p>Being defeated is a part of the experience. You can’t actually die, but getting knocked out
|
||||
means being left in the dark …</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="once-you-are-done-or-had-enough">
|
||||
</section>
|
||||
</section>
|
||||
<section id="once-you-are-done-or-had-enough">
|
||||
<h2>Once you are done (or had enough)<a class="headerlink" href="#once-you-are-done-or-had-enough" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Afterwards you’ll either have conquered the old ruin and returned in glory and triumph … or
|
||||
you returned limping and whimpering from the challenge through <code class="docutils literal notranslate"><span class="pre">telport</span> <span class="pre">limbo</span></code>.
|
||||
|
|
@ -118,7 +119,7 @@ Either way you should now be back in Limbo, able to reflect on the experience.</
|
|||
<li><p>Object spawning (the weapons in the barrel and the final weapoon is actually randomized)</p></li>
|
||||
<li><p>Teleporter trap rooms (if you fail the obelisk puzzle)</p></li>
|
||||
</ul>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Extra Credit</p>
|
||||
<p>If you have previous programming experience (or after you have gone
|
||||
through this Starter tutorial) it may be instructive to dig a little deeper into the Tutorial-world
|
||||
|
|
@ -129,10 +130,10 @@ the build-script is <a class="reference external" href="https://github.com/evenn
|
|||
specific goal in mind: to install easily and to not permanently modify the rest of the server. It therefore
|
||||
goes to some length to use only temporary solutions and to clean up after itself. This is not something
|
||||
you will usually need to worry about when making your own game.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>Quite a lot of stuff crammed in such a small area!</p>
|
||||
</div>
|
||||
<div class="section" id="uninstall-the-tutorial-world">
|
||||
</section>
|
||||
<section id="uninstall-the-tutorial-world">
|
||||
<h2>Uninstall the tutorial world<a class="headerlink" href="#uninstall-the-tutorial-world" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Once are done playing with the tutorial world, let’s uninstall it.
|
||||
Uninstalling the tutorial world basically means deleting all the rooms and objects it consists of.
|
||||
|
|
@ -153,8 +154,8 @@ command finishes.</p>
|
|||
<p>Even if the game-style of the Tutorial-world was not similar to the one you are interested in, it
|
||||
should hopefully have given you a little taste of some of the possibilities of Evennia. Now we’ll
|
||||
move on with how to access this power through code.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>On Planning a Game — 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" />
|
||||
|
|
@ -47,7 +48,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="on-planning-a-game">
|
||||
<section id="on-planning-a-game">
|
||||
<h1>On Planning a Game<a class="headerlink" href="#on-planning-a-game" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Last lesson we asked ourselves some questions about our motivation. In this one we’ll present
|
||||
some more technical questions to consider. In the next lesson we’ll answer them for the sake of
|
||||
|
|
@ -68,7 +69,7 @@ later than to code in isolation until you burn out, lose interest or your hard d
|
|||
<li><p>If the suggestions here seems boring or a chore to you, do it your way instead. Everyone’s different.</p></li>
|
||||
<li><p>Keep having <em>fun</em>. You must keep your motivation up, whichever way works for <em>you</em>.</p></li>
|
||||
</ul>
|
||||
<div class="section" id="the-steps">
|
||||
<section id="the-steps">
|
||||
<h2>The steps<a class="headerlink" href="#the-steps" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Here are the rough steps towards your goal.</p>
|
||||
<ol class="simple">
|
||||
|
|
@ -78,8 +79,8 @@ later than to code in isolation until you burn out, lose interest or your hard d
|
|||
<li><p>Release</p></li>
|
||||
<li><p>Celebrate</p></li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section" id="planning">
|
||||
</section>
|
||||
<section id="planning">
|
||||
<h2>Planning<a class="headerlink" href="#planning" title="Permalink to this headline">¶</a></h2>
|
||||
<p>You need to have at least a rough idea about what you want to create. Some like a lot of planning, others
|
||||
do it more seat-of-the-pants style. Regardless, while <em>some</em> planning is always good to do, it’s common
|
||||
|
|
@ -91,23 +92,23 @@ unfortunately, they are not enough to make your game. You need to figure out how
|
|||
Evennia.</p>
|
||||
<p>Below are some questions to get you going. In the next lesson we will try to answer them for our particular
|
||||
tutorial game. There are of course many more questions you could be asking yourself.</p>
|
||||
<div class="section" id="administration">
|
||||
<section id="administration">
|
||||
<h3>Administration<a class="headerlink" href="#administration" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Should your game rules be enforced by coded systems or by human game masters?</p></li>
|
||||
<li><p>What is the staff hierarchy in your game? Is vanilla Evennia roles enough or do you need something else?</p></li>
|
||||
<li><p>Should players be able to post out-of-characters on channels and via other means like bulletin-boards?</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="building">
|
||||
</section>
|
||||
<section id="building">
|
||||
<h3>Building<a class="headerlink" href="#building" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>How will the world be built? Traditionally (from in-game with build-commands) or externally (by batchcmds/code
|
||||
or directly with custom code)?</p></li>
|
||||
<li><p>Can only privileged Builders create things or should regular players also have limited build-capability?</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="systems">
|
||||
</section>
|
||||
<section id="systems">
|
||||
<h3>Systems<a class="headerlink" href="#systems" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Do you base your game off an existing RPG system or make up your own?</p></li>
|
||||
|
|
@ -118,8 +119,8 @@ or directly with custom code)?</p></li>
|
|||
<li><p>Do you have concepts like reputation and influence?</p></li>
|
||||
<li><p>Will your characters be known by their name or only by their physical appearance?</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="rooms">
|
||||
</section>
|
||||
<section id="rooms">
|
||||
<h3>Rooms<a class="headerlink" href="#rooms" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Is a simple room description enough or should the description be able to change (such as with time, by
|
||||
|
|
@ -129,8 +130,8 @@ dramatic weather, fire or magical effects? If so, how would this affect things i
|
|||
these things something admins/game masters should handle manually?</p></li>
|
||||
<li><p>Can objects be hidden in the room? Can a person hide in the room? How does the room display this?</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="objects-items">
|
||||
</section>
|
||||
<section id="objects-items">
|
||||
<h3>Objects / items<a class="headerlink" href="#objects-items" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>How numerous are your objects? Do you want large loot-lists or are objects just role playing props
|
||||
|
|
@ -145,8 +146,8 @@ created on demand?</p></li>
|
|||
<li><p>Are NPCs and mobs different entities? How do they differ?</p></li>
|
||||
<li><p>Should there be NPCs giving quests? If so, how do you track Quest status?</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="characters">
|
||||
</section>
|
||||
<section id="characters">
|
||||
<h3>Characters<a class="headerlink" href="#characters" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Can players have more than one Character active at a time or are they allowed to multi-play?</p></li>
|
||||
|
|
@ -163,19 +164,19 @@ enemies? Solving quests? By roleplaying?</p></li>
|
|||
can easily become overwhelming and it’s tempting to want <em>all</em> functionality right out of the door.
|
||||
Try to identify the basic things that “make” your game and focus <em>only</em> on them for your first
|
||||
release. Make a list. Keep future expansions in mind but limit yourself.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="coding-and-tech-demo">
|
||||
</section>
|
||||
</section>
|
||||
<section id="coding-and-tech-demo">
|
||||
<h2>Coding and Tech demo<a class="headerlink" href="#coding-and-tech-demo" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This is the actual work of creating the “game” part of your game. As you code and test systems you should
|
||||
build a little “tech demo” along the way.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Tech demo</p>
|
||||
<p>With “tech demo” we mean a small example of your code in-action: A room with a mob,
|
||||
a way to jump into and test character-creation etc. The tech demo need not be pretty, it’s
|
||||
there to test functionality. It’s not the beginning of your game world (unless you find that
|
||||
to be more fun).</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>Try to avoid going wild with building a huge game world before you have a tech-demo showing off all parts
|
||||
you expect to have in the first version of your game. Otherwise you run the risk of having to redo it all
|
||||
again.</p>
|
||||
|
|
@ -195,8 +196,8 @@ these days if you don’t want the world to learn your secrets. Not only version
|
|||
make it easy for your team to collaborate, it also means
|
||||
your work is backed up at all times. The page on <a class="reference internal" href="../../../Coding/Version-Control.html"><span class="doc">Version Control</span></a>
|
||||
will help you to setting up a sane developer environment with proper version control.</p>
|
||||
</div>
|
||||
<div class="section" id="world-building">
|
||||
</section>
|
||||
<section id="world-building">
|
||||
<h2>World Building<a class="headerlink" href="#world-building" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Up until this point we’ve only had a few tech-demo objects in the database. This step is the act of
|
||||
populating the database with a larger, thematic world. Too many would-be developers jump to this
|
||||
|
|
@ -216,8 +217,8 @@ be tested and roughly balanced. You can always add new areas later.</p>
|
|||
have made at this point. If Builders and coders are different people you also
|
||||
get a chance to hear if some things are hard to understand or non-intuitive. Make sure to respond
|
||||
to this feedback.</p>
|
||||
</div>
|
||||
<div class="section" id="alpha-release">
|
||||
</section>
|
||||
<section id="alpha-release">
|
||||
<h2>Alpha Release<a class="headerlink" href="#alpha-release" title="Permalink to this headline">¶</a></h2>
|
||||
<p>As mentioned, don’t hold onto your world more than necessary. <em>Get it out there</em> with a huge <em>Alpha</em>
|
||||
flag and let people try it!</p>
|
||||
|
|
@ -230,25 +231,25 @@ game visible online.</p>
|
|||
<p>If you hadn’t already, make sure to put up your game on the
|
||||
<a class="reference external" href="http://games.evennia.com/">Evennia game index</a> so people know it’s in the works (actually, even
|
||||
pre-alpha games are allowed in the index so don’t be shy)!</p>
|
||||
</div>
|
||||
<div class="section" id="beta-release-perpetual-beta">
|
||||
</section>
|
||||
<section id="beta-release-perpetual-beta">
|
||||
<h2>Beta Release/Perpetual Beta<a class="headerlink" href="#beta-release-perpetual-beta" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Once things stabilize in Alpha you can move to <em>Beta</em> and let more people in. Many MUDs are in
|
||||
<a class="reference external" href="http://en.wikipedia.org/wiki/Perpetual_beta">perpetual beta</a>, meaning they are never considered
|
||||
“finished”, but just repeat the cycle of Planning, Coding, Testing and Building over and over as new
|
||||
features get implemented or Players come with suggestions. As the game designer it is now up to you
|
||||
to gradually perfect your vision.</p>
|
||||
</div>
|
||||
<div class="section" id="congratulate-yourself">
|
||||
</section>
|
||||
<section id="congratulate-yourself">
|
||||
<h2>Congratulate yourself!<a class="headerlink" href="#congratulate-yourself" title="Permalink to this headline">¶</a></h2>
|
||||
<p>You are worthy of a celebration since at this point you have joined the small, exclusive crowd who
|
||||
have made their dream game a reality!</p>
|
||||
</div>
|
||||
<div class="section" id="planning-our-tutorial-game">
|
||||
</section>
|
||||
<section id="planning-our-tutorial-game">
|
||||
<h2>Planning our tutorial game<a class="headerlink" href="#planning-our-tutorial-game" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In the next lesson we’ll make use of these general points and try to plan out our tutorial game.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Planning the use of some useful contribs — 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" />
|
||||
|
|
@ -47,7 +48,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="planning-the-use-of-some-useful-contribs">
|
||||
<section id="planning-the-use-of-some-useful-contribs">
|
||||
<h1>Planning the use of some useful contribs<a class="headerlink" href="#planning-the-use-of-some-useful-contribs" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Evennia is deliberately bare-bones out of the box. The idea is that you should be as unrestricted as possible
|
||||
in designing your game. This is why you can easily replace the few defaults we have and why we don’t try to
|
||||
|
|
@ -70,7 +71,7 @@ are wise to read their doc-strings yourself for the details.</p>
|
|||
<li><p>Quests</p></li>
|
||||
<li><p>Combat (with players and against monsters)</p></li>
|
||||
</ul>
|
||||
<div class="section" id="barter-contrib">
|
||||
<section id="barter-contrib">
|
||||
<h2>Barter contrib<a class="headerlink" href="#barter-contrib" title="Permalink to this headline">¶</a></h2>
|
||||
<p><a class="reference external" href="../../../api/evennia.contrib.barter.html">source</a></p>
|
||||
<p>Reviewing this contrib suggests that it allows for safe trading between two parties. The basic principle
|
||||
|
|
@ -98,15 +99,15 @@ to run away with your money.</p>
|
|||
<p>We will use the barter contrib as an optional feature for player-player bartering. More importantly we can
|
||||
add it for NPC shopkeepers and expand it with a little AI, which allows them to potentially trade in other
|
||||
things than boring gold coin.</p>
|
||||
</div>
|
||||
<div class="section" id="character-generation-contrib">
|
||||
</section>
|
||||
<section id="character-generation-contrib">
|
||||
<h2>Character generation contrib<a class="headerlink" href="#character-generation-contrib" title="Permalink to this headline">¶</a></h2>
|
||||
<p><a class="reference external" href="../../../api/evennia.contrib.chargen.html">source</a></p>
|
||||
<p>This contrib is an example module for creating characters. Since we will be using <code class="docutils literal notranslate"><span class="pre">MULTISESSION_MODE=3</span></code> we will
|
||||
get a selection screen like this automatically. We also plan to use a proper menu to build our character, so
|
||||
we will <em>not</em> be using this contrib.</p>
|
||||
</div>
|
||||
<div class="section" id="clothing-contrib">
|
||||
</section>
|
||||
<section id="clothing-contrib">
|
||||
<h2>Clothing contrib<a class="headerlink" href="#clothing-contrib" title="Permalink to this headline">¶</a></h2>
|
||||
<p><a class="reference external" href="../../../api/evennia.contrib.clothing.html">source</a></p>
|
||||
<p>This contrib provides a full system primarily aimed at wearing clothes, but it could also work for armor. You wear
|
||||
|
|
@ -119,8 +120,8 @@ also add roleplaying flavor:</p>
|
|||
</div>
|
||||
<p>By default there are no ‘body locations’ in this contrib, we will need to expand on it a little to make it useful
|
||||
for things like armor. It’s a good contrib to build from though, so that’s what we’ll do.</p>
|
||||
</div>
|
||||
<div class="section" id="dice-contrib">
|
||||
</section>
|
||||
<section id="dice-contrib">
|
||||
<h2>Dice contrib<a class="headerlink" href="#dice-contrib" title="Permalink to this headline">¶</a></h2>
|
||||
<p><a class="reference external" href="../../../api/evennia.contrib.dice.html">source</a></p>
|
||||
<p>The dice contrib presents a general dice roller to use in game.</p>
|
||||
|
|
@ -139,8 +140,8 @@ we will emulate rolls for our rule system, we’ll do this as simply as possible
|
|||
module.</p>
|
||||
<p>So while this contrib is fun to have around for GMs or for players who want to get a random result
|
||||
or play a game, we will not need it for the core of our game.</p>
|
||||
</div>
|
||||
<div class="section" id="extended-room-contrib">
|
||||
</section>
|
||||
<section id="extended-room-contrib">
|
||||
<h2>Extended room contrib<a class="headerlink" href="#extended-room-contrib" title="Permalink to this headline">¶</a></h2>
|
||||
<p><a class="reference external" href="../../../api/evennia.contrib.extended_room.html">source</a></p>
|
||||
<p>This is a custom Room typeclass that changes its description based on time of day and season.</p>
|
||||
|
|
@ -154,8 +155,8 @@ get a description of the windows without there needing to be an actual <code cla
|
|||
like a normal room.</p>
|
||||
<p>The contrib is simple to add and provides a lot of optional flexibility, so we’ll add it to our
|
||||
game, why not!</p>
|
||||
</div>
|
||||
<div class="section" id="rp-system-contrib">
|
||||
</section>
|
||||
<section id="rp-system-contrib">
|
||||
<h2>RP-System contrib<a class="headerlink" href="#rp-system-contrib" title="Permalink to this headline">¶</a></h2>
|
||||
<p><a class="reference external" href="../../../api/evennia.contrib.rpsystem.html">source</a></p>
|
||||
<p>This contrib adds a full roleplaying subsystem to your game. It gives every character a “short-description”
|
||||
|
|
@ -193,14 +194,14 @@ like <code class="docutils literal notranslate"><span class="pre">a</span> <span
|
|||
<p>The RPSystem gives a lot of roleplaying power out of the box, so we will add it. There is also a separate
|
||||
<a class="reference external" href="../../../api/evennia.contrib.rplanguage.html">rplanguage</a> module that integrates with the spoken words in your emotes and garbles them if you don’t understand
|
||||
the language spoken. In order to restrict the scope we will not include languages for the tutorial game.</p>
|
||||
</div>
|
||||
<div class="section" id="talking-npc-contrib">
|
||||
</section>
|
||||
<section id="talking-npc-contrib">
|
||||
<h2>Talking NPC contrib<a class="headerlink" href="#talking-npc-contrib" title="Permalink to this headline">¶</a></h2>
|
||||
<p><a class="reference external" href="../../../api/evennia.contrib.talking_npc.html">source</a></p>
|
||||
<p>This exemplifies an NPC with a menu-driven dialogue tree. We will not use this contrib explicitly, but it’s
|
||||
good as inspiration for how we’ll do quest-givers later.</p>
|
||||
</div>
|
||||
<div class="section" id="traits-contrib">
|
||||
</section>
|
||||
<section id="traits-contrib">
|
||||
<h2>Traits contrib<a class="headerlink" href="#traits-contrib" title="Permalink to this headline">¶</a></h2>
|
||||
<p><a class="reference external" href="../../../api/evennia.contrib.traits.html">source</a></p>
|
||||
<p>An issue with dealing with roleplaying attributes like strength, dexterity, or skills like hunting, sword etc
|
||||
|
|
@ -249,8 +250,8 @@ effects of slow poisons and healing both.</p></li>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>Traits will be very practical to use for our character sheets.</p>
|
||||
</div>
|
||||
<div class="section" id="turnbattle-contrib">
|
||||
</section>
|
||||
<section id="turnbattle-contrib">
|
||||
<h2>Turnbattle contrib<a class="headerlink" href="#turnbattle-contrib" title="Permalink to this headline">¶</a></h2>
|
||||
<p><a class="reference external" href="../../../api/evennia.contrib.turnbattle.html">source</a></p>
|
||||
<p>This contrib consists of several implementations of a turn-based combat system, divivided into complexity:</p>
|
||||
|
|
@ -263,8 +264,8 @@ effects of slow poisons and healing both.</p></li>
|
|||
</ul>
|
||||
<p>The turnbattle system is comprehensive, but it’s meant as a base to start from rather than offer
|
||||
a complete system. It’s also not built with <em>Traits</em> in mind, so we will need to adjust it for that.</p>
|
||||
</div>
|
||||
<div class="section" id="conclusions">
|
||||
</section>
|
||||
<section id="conclusions">
|
||||
<h2>Conclusions<a class="headerlink" href="#conclusions" title="Permalink to this headline">¶</a></h2>
|
||||
<p>With some contribs selected, we have pieces to build from and don’t have to write everything from scratch.
|
||||
We will need Quests and will likely need to do a bunch of work on Combat to adapt the combat contrib
|
||||
|
|
@ -272,8 +273,8 @@ to our needs.</p>
|
|||
<p>We will now move into actually starting to implement our tutorial game
|
||||
in the next part of this tutorial series. When doing this for yourself, remember to refer
|
||||
back to your planning and adjust it as you learn what works and what does not.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Planning our tutorial game — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="planning-our-tutorial-game">
|
||||
<section id="planning-our-tutorial-game">
|
||||
<h1>Planning our tutorial game<a class="headerlink" href="#planning-our-tutorial-game" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Using the general plan from last lesson we’ll now establish what kind of game we want to create for this tutorial.
|
||||
Remembering that we need to keep the scope down, let’s establish some parameters.
|
||||
|
|
@ -61,9 +62,9 @@ and combat.</p></li>
|
|||
<li><p>We want some sort of quest system.</p></li>
|
||||
</ul>
|
||||
<p>Let’s answer the questions from the previous lesson and discuss some of the possibilities.</p>
|
||||
<div class="section" id="administration">
|
||||
<section id="administration">
|
||||
<h2>Administration<a class="headerlink" href="#administration" title="Permalink to this headline">¶</a></h2>
|
||||
<div class="section" id="should-your-game-rules-be-enforced-by-coded-systems-by-human-game-masters">
|
||||
<section id="should-your-game-rules-be-enforced-by-coded-systems-by-human-game-masters">
|
||||
<h3>Should your game rules be enforced by coded systems by human game masters?<a class="headerlink" href="#should-your-game-rules-be-enforced-by-coded-systems-by-human-game-masters" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Generally, the more work you expect human staffers/GMs to do, the less your code needs to work. To
|
||||
support GMs you’d need to design commands to support GM-specific actions and the type of game-mastering
|
||||
|
|
@ -79,8 +80,8 @@ involvement. Allowing for solo-play with the computer also allows players to hav
|
|||
players is low.</p>
|
||||
<p>We want EvAdventure to work entirely without depending on human GMs. That said, there’d be nothing
|
||||
stopping a GM from stepping in and run an adventure for some players should they want to.</p>
|
||||
</div>
|
||||
<div class="section" id="what-is-the-staff-hierarchy-in-your-game-is-vanilla-evennia-roles-enough-or-do-you-need-something-else">
|
||||
</section>
|
||||
<section id="what-is-the-staff-hierarchy-in-your-game-is-vanilla-evennia-roles-enough-or-do-you-need-something-else">
|
||||
<h3>What is the staff hierarchy in your game? Is vanilla Evennia roles enough or do you need something else?<a class="headerlink" href="#what-is-the-staff-hierarchy-in-your-game-is-vanilla-evennia-roles-enough-or-do-you-need-something-else" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The default hierarchy is</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -93,8 +94,8 @@ stopping a GM from stepping in and run an adventure for some players should they
|
|||
<p>There is also the <em>superuser</em>, the “owner” of the game you create when you first set up your database. This user
|
||||
goes outside the regular hierarchy and should usually only.</p>
|
||||
<p>We are okay with keeping this structure for our game.</p>
|
||||
</div>
|
||||
<div class="section" id="should-players-be-able-to-post-out-of-characters-on-channels-and-via-other-means-like-bulletin-boards">
|
||||
</section>
|
||||
<section id="should-players-be-able-to-post-out-of-characters-on-channels-and-via-other-means-like-bulletin-boards">
|
||||
<h3>Should players be able to post out-of-characters on channels and via other means like bulletin-boards?<a class="headerlink" href="#should-players-be-able-to-post-out-of-characters-on-channels-and-via-other-means-like-bulletin-boards" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Evennia’s <em>Channels</em> are by default only available between <em>Accounts</em>. That is, for players to communicate with each
|
||||
other. By default, the <code class="docutils literal notranslate"><span class="pre">public</span></code> channel is created for general discourse.
|
||||
|
|
@ -116,11 +117,11 @@ the messages are usually stored and are grouped into topics with replies. Evenni
|
|||
system.</p>
|
||||
<p>In EvAdventure we will just use the default inter-account channels. We will also not be implementing any
|
||||
bulletin boards.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="building">
|
||||
</section>
|
||||
</section>
|
||||
<section id="building">
|
||||
<h2>Building<a class="headerlink" href="#building" title="Permalink to this headline">¶</a></h2>
|
||||
<div class="section" id="how-will-the-world-be-built">
|
||||
<section id="how-will-the-world-be-built">
|
||||
<h3>How will the world be built?<a class="headerlink" href="#how-will-the-world-be-built" title="Permalink to this headline">¶</a></h3>
|
||||
<p>There are two main ways to handle this:</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -141,8 +142,8 @@ builder to have server access or to use version control to share their work with
|
|||
</ul>
|
||||
<p>In this tutorial, we will show examples of all these ways, but since we don’t have a team of builders we’ll
|
||||
build the brunt of things using Evennia’s Batchcode system.</p>
|
||||
</div>
|
||||
<div class="section" id="can-only-privileged-builders-create-things-or-should-regular-players-also-have-limited-build-capability">
|
||||
</section>
|
||||
<section id="can-only-privileged-builders-create-things-or-should-regular-players-also-have-limited-build-capability">
|
||||
<h3>Can only privileged Builders create things or should regular players also have limited build-capability?<a class="headerlink" href="#can-only-privileged-builders-create-things-or-should-regular-players-also-have-limited-build-capability" title="Permalink to this headline">¶</a></h3>
|
||||
<p>In some game styles, players have the ability to create objects and even script them. While giving regular users
|
||||
the ability to create objects with in-built commands is easy and safe, actual code-creation (aka <em>softcode</em> ) is
|
||||
|
|
@ -152,11 +153,11 @@ code (such as what you can do with the <code class="docutils literal notranslate
|
|||
it’s suggested that this is accomplished by adding more powerful build-commands for them to use.</p>
|
||||
<p>For our tutorial-game, we will only allow privileged builders to modify the world. The exception is crafting,
|
||||
which we will limit to repairing broken items by combining them with other repair-related items.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="systems">
|
||||
</section>
|
||||
</section>
|
||||
<section id="systems">
|
||||
<h2>Systems<a class="headerlink" href="#systems" title="Permalink to this headline">¶</a></h2>
|
||||
<div class="section" id="do-you-base-your-game-off-an-existing-rpg-system-or-make-up-your-own">
|
||||
<section id="do-you-base-your-game-off-an-existing-rpg-system-or-make-up-your-own">
|
||||
<h3>Do you base your game off an existing RPG system or make up your own?<a class="headerlink" href="#do-you-base-your-game-off-an-existing-rpg-system-or-make-up-your-own" title="Permalink to this headline">¶</a></h3>
|
||||
<p>We will make use of <a class="reference external" href="http://www.geekguild.com/openadventure/">Open Adventure</a>, a simple ‘old school’ RPG-system
|
||||
that is available for free under the Creative Commons license. We’ll only use a subset of the rules from
|
||||
|
|
@ -170,16 +171,16 @@ styles.</p></li>
|
|||
out a character, these will work the same as other bonuses and are thus not that instructive.</p></li>
|
||||
<li><p>We will add only a small number of items/weapons from the Open Adventure rulebook to show how it’s done.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="what-are-the-game-mechanics-how-do-you-decide-if-an-action-succeeds-or-fails">
|
||||
</section>
|
||||
<section id="what-are-the-game-mechanics-how-do-you-decide-if-an-action-succeeds-or-fails">
|
||||
<h3>What are the game mechanics? How do you decide if an action succeeds or fails?<a class="headerlink" href="#what-are-the-game-mechanics-how-do-you-decide-if-an-action-succeeds-or-fails" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Open Adventure’s conflict resolution is based on adding a trait (such as Strength) with a random number in
|
||||
order to beat a target. We will emulate this in code.</p>
|
||||
<p>Having a “skill” means getting a bonus to that roll for a more narrow action.
|
||||
Since the computer will need to know exactly what those skills are, we will add them more explicitly than
|
||||
in the rules, but we will only add the minimum to show off the functionality we need.</p>
|
||||
</div>
|
||||
<div class="section" id="does-the-flow-of-time-matter-in-your-game-does-night-and-day-change-what-about-seasons">
|
||||
</section>
|
||||
<section id="does-the-flow-of-time-matter-in-your-game-does-night-and-day-change-what-about-seasons">
|
||||
<h3>Does the flow of time matter in your game - does night and day change? What about seasons?<a class="headerlink" href="#does-the-flow-of-time-matter-in-your-game-does-night-and-day-change-what-about-seasons" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Most commonly, game-time runs faster than real-world time. There are
|
||||
a few advantages with this:</p>
|
||||
|
|
@ -197,25 +198,25 @@ particular times of their day. With a game-time drifting relative real-time, eve
|
|||
able to experience both day and night in the game.</p>
|
||||
<p>For this tutorial-game we will go with Evennia’s default, which is that the game-time runs two times faster
|
||||
than real time.</p>
|
||||
</div>
|
||||
<div class="section" id="do-you-want-changing-global-weather-or-should-weather-just-be-set-manually-in-roleplay">
|
||||
</section>
|
||||
<section id="do-you-want-changing-global-weather-or-should-weather-just-be-set-manually-in-roleplay">
|
||||
<h3>Do you want changing, global weather or should weather just be set manually in roleplay?<a class="headerlink" href="#do-you-want-changing-global-weather-or-should-weather-just-be-set-manually-in-roleplay" title="Permalink to this headline">¶</a></h3>
|
||||
<p>A weather system is a good example of a game-global system that affects a subset of game entities
|
||||
(outdoor rooms). We will not be doing any advanced weather simulation, but we’ll show how to do
|
||||
random weather changes happening across the game world.</p>
|
||||
</div>
|
||||
<div class="section" id="do-you-want-a-coded-world-economy-or-just-a-simple-barter-system-or-no-formal-economy-at-all">
|
||||
</section>
|
||||
<section id="do-you-want-a-coded-world-economy-or-just-a-simple-barter-system-or-no-formal-economy-at-all">
|
||||
<h3>Do you want a coded world-economy or just a simple barter system? Or no formal economy at all?<a class="headerlink" href="#do-you-want-a-coded-world-economy-or-just-a-simple-barter-system-or-no-formal-economy-at-all" title="Permalink to this headline">¶</a></h3>
|
||||
<p>We will allow for money and barter/trade between NPCs/Players and Player/Player, but will not care about
|
||||
inflation. A real economic simulation could do things like modify shop prices based on supply and demand.
|
||||
We will not go down that rabbit hole.</p>
|
||||
</div>
|
||||
<div class="section" id="do-you-have-concepts-like-reputation-and-influence">
|
||||
</section>
|
||||
<section id="do-you-have-concepts-like-reputation-and-influence">
|
||||
<h3>Do you have concepts like reputation and influence?<a class="headerlink" href="#do-you-have-concepts-like-reputation-and-influence" title="Permalink to this headline">¶</a></h3>
|
||||
<p>These are useful things for a more social-interaction heavy game. We will not include them for this
|
||||
tutorial however.</p>
|
||||
</div>
|
||||
<div class="section" id="will-your-characters-be-known-by-their-name-or-only-by-their-physical-appearance">
|
||||
</section>
|
||||
<section id="will-your-characters-be-known-by-their-name-or-only-by-their-physical-appearance">
|
||||
<h3>Will your characters be known by their name or only by their physical appearance?<a class="headerlink" href="#will-your-characters-be-known-by-their-name-or-only-by-their-physical-appearance" title="Permalink to this headline">¶</a></h3>
|
||||
<p>This is a common thing in RP-heavy games. Others will only see you as “The tall woman” until you
|
||||
introduce yourself and they ‘recognize’ you with a name. Linked to this is the concept of more complex
|
||||
|
|
@ -223,66 +224,66 @@ emoting and posing.</p>
|
|||
<p>Adding such a system from scratch is complex and way beyond the scope of this tutorial. However,
|
||||
there is an existing Evennia contrib that adds all of this functionality and more, so we will
|
||||
include that and explain briefly how it works.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="rooms">
|
||||
</section>
|
||||
</section>
|
||||
<section id="rooms">
|
||||
<h2>Rooms<a class="headerlink" href="#rooms" title="Permalink to this headline">¶</a></h2>
|
||||
<div class="section" id="is-a-simple-room-description-enough-or-should-the-description-be-able-to-change">
|
||||
<section id="is-a-simple-room-description-enough-or-should-the-description-be-able-to-change">
|
||||
<h3>Is a simple room description enough or should the description be able to change?<a class="headerlink" href="#is-a-simple-room-description-enough-or-should-the-description-be-able-to-change" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Changing room descriptions for day and night, winder and summer is actually quite easy to do, but looks
|
||||
very impressive. We happen to know there is also a contrib that helps with this, so we’ll show how to
|
||||
include that.</p>
|
||||
</div>
|
||||
<div class="section" id="should-the-room-have-different-statuses">
|
||||
</section>
|
||||
<section id="should-the-room-have-different-statuses">
|
||||
<h3>Should the room have different statuses?<a class="headerlink" href="#should-the-room-have-different-statuses" title="Permalink to this headline">¶</a></h3>
|
||||
<p>We will have different weather in outdoor rooms, but this will not have any gameplay effect - bow strings
|
||||
will not get wet and fireballs will not fizzle if it rains.</p>
|
||||
</div>
|
||||
<div class="section" id="can-objects-be-hidden-in-the-room-can-a-person-hide-in-the-room">
|
||||
</section>
|
||||
<section id="can-objects-be-hidden-in-the-room-can-a-person-hide-in-the-room">
|
||||
<h3>Can objects be hidden in the room? Can a person hide in the room?<a class="headerlink" href="#can-objects-be-hidden-in-the-room-can-a-person-hide-in-the-room" title="Permalink to this headline">¶</a></h3>
|
||||
<p>We will not model hiding and stealth. This will be a game of honorable face-to-face conflict.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="objects">
|
||||
</section>
|
||||
</section>
|
||||
<section id="objects">
|
||||
<h2>Objects<a class="headerlink" href="#objects" title="Permalink to this headline">¶</a></h2>
|
||||
<div class="section" id="how-numerous-are-your-objects-do-you-want-large-loot-lists-or-are-objects-just-role-playing-props">
|
||||
<section id="how-numerous-are-your-objects-do-you-want-large-loot-lists-or-are-objects-just-role-playing-props">
|
||||
<h3>How numerous are your objects? Do you want large loot-lists or are objects just role playing props?<a class="headerlink" href="#how-numerous-are-your-objects-do-you-want-large-loot-lists-or-are-objects-just-role-playing-props" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Since we are not going for a pure freeform RPG here, we will want objects with properties, like weapons
|
||||
and potions and such. Monsters should drop loot even though our list of objects will not be huge.</p>
|
||||
</div>
|
||||
<div class="section" id="is-each-coin-a-separate-object-or-do-you-just-store-a-bank-account-value">
|
||||
</section>
|
||||
<section id="is-each-coin-a-separate-object-or-do-you-just-store-a-bank-account-value">
|
||||
<h3>Is each coin a separate object or do you just store a bank account value?<a class="headerlink" href="#is-each-coin-a-separate-object-or-do-you-just-store-a-bank-account-value" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Since we will use bartering, placing coin objects on one side of the barter makes for a simple way to
|
||||
handle payments. So we will use coins as-objects.</p>
|
||||
</div>
|
||||
<div class="section" id="do-multiple-similar-objects-form-stacks-and-how-are-those-stacks-handled-in-that-case">
|
||||
</section>
|
||||
<section id="do-multiple-similar-objects-form-stacks-and-how-are-those-stacks-handled-in-that-case">
|
||||
<h3>Do multiple similar objects form stacks and how are those stacks handled in that case?<a class="headerlink" href="#do-multiple-similar-objects-form-stacks-and-how-are-those-stacks-handled-in-that-case" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Since we’ll use coins, it’s practical to have them and other items stack together. While Evennia does not
|
||||
do this natively, we will make use of a contrib for this.</p>
|
||||
</div>
|
||||
<div class="section" id="does-an-object-have-weight-or-volume-so-you-cannot-carry-an-infinite-amount-of-them">
|
||||
</section>
|
||||
<section id="does-an-object-have-weight-or-volume-so-you-cannot-carry-an-infinite-amount-of-them">
|
||||
<h3>Does an object have weight or volume (so you cannot carry an infinite amount of them)?<a class="headerlink" href="#does-an-object-have-weight-or-volume-so-you-cannot-carry-an-infinite-amount-of-them" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Limiting carrying weight is one way to stop players from hoarding. It also makes it more important
|
||||
for players to pick only the equipment they need. Carrying limits can easily come across as
|
||||
annoying to players though, so one needs to be careful with it.</p>
|
||||
<p>Open Adventure rules include weight limits, so we will include them.</p>
|
||||
</div>
|
||||
<div class="section" id="can-objects-be-broken-can-they-be-repaired">
|
||||
</section>
|
||||
<section id="can-objects-be-broken-can-they-be-repaired">
|
||||
<h3>Can objects be broken? Can they be repaired?<a class="headerlink" href="#can-objects-be-broken-can-they-be-repaired" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Item breakage is very useful for a game economy; breaking weapons adds tactical considerations (if it’s not
|
||||
too common, then it becomes annoying) and repairing things gives work for crafting players.</p>
|
||||
<p>We wanted a crafting system, so this is what we will limit it to - repairing items using some sort
|
||||
of raw materials.</p>
|
||||
</div>
|
||||
<div class="section" id="can-you-fight-with-a-chair-or-a-flower-or-must-you-use-a-special-weapon-kind-of-thing">
|
||||
</section>
|
||||
<section id="can-you-fight-with-a-chair-or-a-flower-or-must-you-use-a-special-weapon-kind-of-thing">
|
||||
<h3>Can you fight with a chair or a flower or must you use a special ‘weapon’ kind of thing?<a class="headerlink" href="#can-you-fight-with-a-chair-or-a-flower-or-must-you-use-a-special-weapon-kind-of-thing" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Traditionally, only ‘weapons’ could be used to fight with. In the past this was a useful
|
||||
simplification, but with Python classes and inheritance, it’s not actually more work to just
|
||||
let all items in game work as a weapon in a pinch.</p>
|
||||
<p>So for our game we will let a character use any item they want as a weapon. The difference will
|
||||
be that non-weapon items will do less damage and also break and become unusable much quicker.</p>
|
||||
</div>
|
||||
<div class="section" id="will-characters-be-able-to-craft-new-objects">
|
||||
</section>
|
||||
<section id="will-characters-be-able-to-craft-new-objects">
|
||||
<h3>Will characters be able to craft new objects?<a class="headerlink" href="#will-characters-be-able-to-craft-new-objects" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Crafting is a common feature in multiplayer games. In code it usually means using a skill-check
|
||||
to combine base ingredients from a fixed recipe in order to create a new item. The classic
|
||||
|
|
@ -291,8 +292,8 @@ A full-fledged crafting system could require multiple levels of crafting, includ
|
|||
for ore or cut down trees for wood.</p>
|
||||
<p>In our case we will limit our crafting to repairing broken items. To show how it’s done, we will require
|
||||
extra items (a recipe) in order to facilitate the repairs.</p>
|
||||
</div>
|
||||
<div class="section" id="should-mobs-npcs-have-some-sort-of-ai">
|
||||
</section>
|
||||
<section id="should-mobs-npcs-have-some-sort-of-ai">
|
||||
<h3>Should mobs/NPCs have some sort of AI?<a class="headerlink" href="#should-mobs-npcs-have-some-sort-of-ai" title="Permalink to this headline">¶</a></h3>
|
||||
<p>A rule of adding Artificial Intelligence is that with today’s technology you should not hope to fool
|
||||
anyone with it anytime soon. Unless you have a side-gig as an AI researcher, users will likely
|
||||
|
|
@ -300,23 +301,23 @@ not notice any practical difference between a simple state-machine and you spend
|
|||
how to train a neural net.</p>
|
||||
<p>For this tutorial, we will show how to add a simple state-machine for monsters. NPCs will only be
|
||||
shop-keepers and quest-gives so they won’t need any real AI to speak of.</p>
|
||||
</div>
|
||||
<div class="section" id="are-npcs-and-mobs-different-entities-how-do-they-differ">
|
||||
</section>
|
||||
<section id="are-npcs-and-mobs-different-entities-how-do-they-differ">
|
||||
<h3>Are NPCs and mobs different entities? How do they differ?<a class="headerlink" href="#are-npcs-and-mobs-different-entities-how-do-they-differ" title="Permalink to this headline">¶</a></h3>
|
||||
<p>“Mobs” or “mobiles” are things that move around. This is traditionally monsters you can fight with, but could
|
||||
also be city guards or the baker going to chat with the neighbor. Back in the day, they were often fundamentally
|
||||
different these days it’s often easier to just make NPCs and mobs essentially the same thing.</p>
|
||||
<p>In EvAdventure, both Monsters and NPCs will be the same type of thing; A monster could give you a quest
|
||||
and an NPC might fight you as a mob as well as trade with you.</p>
|
||||
</div>
|
||||
<div class="section" id="should-there-be-npcs-giving-quests-if-so-how-do-you-track-quest-status">
|
||||
</section>
|
||||
<section id="should-there-be-npcs-giving-quests-if-so-how-do-you-track-quest-status">
|
||||
<h3>_Should there be NPCs giving quests? If so, how do you track Quest status?<a class="headerlink" href="#should-there-be-npcs-giving-quests-if-so-how-do-you-track-quest-status" title="Permalink to this headline">¶</a></h3>
|
||||
<p>We will design a simple quest system to track the status of ongoing quests.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="characters">
|
||||
</section>
|
||||
</section>
|
||||
<section id="characters">
|
||||
<h2>Characters<a class="headerlink" href="#characters" title="Permalink to this headline">¶</a></h2>
|
||||
<div class="section" id="can-players-have-more-than-one-character-active-at-a-time-or-are-they-allowed-to-multi-play">
|
||||
<section id="can-players-have-more-than-one-character-active-at-a-time-or-are-they-allowed-to-multi-play">
|
||||
<h3>Can players have more than one Character active at a time or are they allowed to multi-play?<a class="headerlink" href="#can-players-have-more-than-one-character-active-at-a-time-or-are-they-allowed-to-multi-play" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Since Evennia differentiates between <code class="docutils literal notranslate"><span class="pre">Sessions</span></code> (the client-connection to the game), <code class="docutils literal notranslate"><span class="pre">Accounts</span></code>
|
||||
and <code class="docutils literal notranslate"><span class="pre">Character</span></code>s, it natively supports multi-play. This is controlled by the <code class="docutils literal notranslate"><span class="pre">MULTISESSION_MODE</span></code>
|
||||
|
|
@ -336,8 +337,8 @@ open, but only one client per Character.</p></li>
|
|||
can control each Character from multiple clients, seeing the same output from each Character.</p></li>
|
||||
</ul>
|
||||
<p>We will go with a multi-role game, so we will use <code class="docutils literal notranslate"><span class="pre">MULTISESSION_MODE=3</span></code> for this tutorial.</p>
|
||||
</div>
|
||||
<div class="section" id="how-does-the-character-generation-work">
|
||||
</section>
|
||||
<section id="how-does-the-character-generation-work">
|
||||
<h3>How does the character-generation work?<a class="headerlink" href="#how-does-the-character-generation-work" title="Permalink to this headline">¶</a></h3>
|
||||
<p>There are a few common ways to do character generation:</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -353,15 +354,15 @@ with a sequential menu.</p></li>
|
|||
</ul>
|
||||
<p>For the tutorial we will use a menu to let the user modify each section of their character sheet in any order
|
||||
until they are happy.</p>
|
||||
</div>
|
||||
<div class="section" id="how-do-you-implement-different-classes-or-races">
|
||||
</section>
|
||||
<section id="how-do-you-implement-different-classes-or-races">
|
||||
<h3>How do you implement different “classes” or “races”?<a class="headerlink" href="#how-do-you-implement-different-classes-or-races" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The way classes and races work in most RPGs (as well as in OpenAdventure) is that they act as static ‘templates’
|
||||
that inform which bonuses and special abilities you have. This means that all we need to store on the
|
||||
Character is <em>which</em> class and <em>which</em> race they have; the actual logic can sit in Python code and just
|
||||
be looked up when we need it.</p>
|
||||
</div>
|
||||
<div class="section" id="if-a-character-can-hide-in-a-room-what-skill-will-decide-if-they-are-detected">
|
||||
</section>
|
||||
<section id="if-a-character-can-hide-in-a-room-what-skill-will-decide-if-they-are-detected">
|
||||
<h3>If a Character can hide in a room, what skill will decide if they are detected?<a class="headerlink" href="#if-a-character-can-hide-in-a-room-what-skill-will-decide-if-they-are-detected" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Hiding means a few things.</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -373,8 +374,8 @@ find the person (probably based on skill checks).</p></li>
|
|||
<li><p>The room will also need to be involved, maybe with some modifier as to how easy it is to hide in the room.</p></li>
|
||||
</ul>
|
||||
<p>We will <em>not</em> be including a hide-mechanic in EvAdventure though.</p>
|
||||
</div>
|
||||
<div class="section" id="what-does-the-skill-tree-look-like-can-a-character-gain-experience-to-improve-by-killing-enemies-solving-quests-by-roleplaying">
|
||||
</section>
|
||||
<section id="what-does-the-skill-tree-look-like-can-a-character-gain-experience-to-improve-by-killing-enemies-solving-quests-by-roleplaying">
|
||||
<h3>What does the skill tree look like? Can a Character gain experience to improve? By killing enemies? Solving quests? By roleplaying?<a class="headerlink" href="#what-does-the-skill-tree-look-like-can-a-character-gain-experience-to-improve-by-killing-enemies-solving-quests-by-roleplaying" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Gaining experience points (XP) and improving one’s character is a staple of roleplaying games. There are many
|
||||
ways to implement this:</p>
|
||||
|
|
@ -396,8 +397,8 @@ you gain XP only for running when you run, XP for your axe skill when you fight
|
|||
</li>
|
||||
</ul>
|
||||
<p>For EvAdventure we will use Open Adventure’s rules for XP, which will be driven by kills and quest successes.</p>
|
||||
</div>
|
||||
<div class="section" id="may-player-characters-attack-each-other-pvp">
|
||||
</section>
|
||||
<section id="may-player-characters-attack-each-other-pvp">
|
||||
<h3>May player-characters attack each other (PvP)?<a class="headerlink" href="#may-player-characters-attack-each-other-pvp" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Deciding this affects the style of your entire game. PvP makes for exciting gameplay but it opens a whole new
|
||||
can of worms when it comes to “fairness”. Players will usually accept dying to an overpowered NPC dragon. They
|
||||
|
|
@ -408,8 +409,8 @@ a political game or gaining market share when selling their crafted merchandise.
|
|||
<p>For the EvAdventure we will support both Player-vs-environment combat and turn-based PvP. We will allow players
|
||||
to barter with each other (so potentially scam others?) but that’s the extent of it. We will focus on showing
|
||||
off techniques and will not focus on making a balanced game.</p>
|
||||
</div>
|
||||
<div class="section" id="what-are-the-penalties-of-defeat-permanent-death-quick-respawn-time-in-prison">
|
||||
</section>
|
||||
<section id="what-are-the-penalties-of-defeat-permanent-death-quick-respawn-time-in-prison">
|
||||
<h3>What are the penalties of defeat? Permanent death? Quick respawn? Time in prison?<a class="headerlink" href="#what-are-the-penalties-of-defeat-permanent-death-quick-respawn-time-in-prison" title="Permalink to this headline">¶</a></h3>
|
||||
<p>This is another big decision that strongly affects the mood and style of your game.</p>
|
||||
<p>Perma-death means that once your character dies, it’s gone and you have to make a new one.</p>
|
||||
|
|
@ -445,17 +446,17 @@ you die permanently.</p></li>
|
|||
</ul>
|
||||
<p>For our tutorial-game we will not be messing with perma-death; instead your defeat will mean you will re-spawn
|
||||
back at your home location with a fraction of your health.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="conclusions">
|
||||
</section>
|
||||
</section>
|
||||
<section id="conclusions">
|
||||
<h2>Conclusions<a class="headerlink" href="#conclusions" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Going through the questions has helped us get a little bit more of a feel for the game we want to do. There are
|
||||
many other things we could ask ourselves, but if we can cover these points we will be a good way towards a complete,
|
||||
playable game!</p>
|
||||
<p>Before starting to code in earnest a good coder should always do an inventory of all the stuff they <em>don’t</em> need
|
||||
to code themselves. So in the next lesson we will check out what help we have from Evennia’s <em>contribs</em>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Where do I begin? — 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" />
|
||||
|
|
@ -47,7 +48,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="where-do-i-begin">
|
||||
<section id="where-do-i-begin">
|
||||
<h1>Where do I begin?<a class="headerlink" href="#where-do-i-begin" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The good news is that following this Starting tutorial is a great way to begin making an Evennia game.</p>
|
||||
<p>The bad news is that everyone’s different and when it comes to starting your own game there is no
|
||||
|
|
@ -59,7 +60,7 @@ put some more realistic limits on how fast you can achieve your goals.</p>
|
|||
to learn Evennia. If you just want to follow along with the technical bits you can skip this lesson and
|
||||
come back later when you feel ready to take on making your own game.</p>
|
||||
</div></blockquote>
|
||||
<div class="section" id="what-is-your-motivation-for-doing-this">
|
||||
<section id="what-is-your-motivation-for-doing-this">
|
||||
<h2>What is your motivation for doing this?<a class="headerlink" href="#what-is-your-motivation-for-doing-this" title="Permalink to this headline">¶</a></h2>
|
||||
<p>So you want to make a game. First you need to make a few things clear to yourself.</p>
|
||||
<p>Making a multiplayer online game is a <em>big</em> undertaking. You will (if you are like most of us) be
|
||||
|
|
@ -95,8 +96,8 @@ those of a person who only creates as a hobby or for their own benefit. You may
|
|||
timeline for release.</p>
|
||||
<p>Whichever your motivation, you should at least have it clear in your own mind. It’s worth to make
|
||||
sure your eventual team is on the same page too.</p>
|
||||
</div>
|
||||
<div class="section" id="what-are-your-skills">
|
||||
</section>
|
||||
<section id="what-are-your-skills">
|
||||
<h2>What are your skills?<a class="headerlink" href="#what-are-your-skills" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Once you have your motivations straight you need to take a stock of your own skills and the skills
|
||||
available in your team, if you have any.</p>
|
||||
|
|
@ -105,7 +106,7 @@ available in your team, if you have any.</p>
|
|||
<li><p>The game engine / code base - Evennia in this case.</p></li>
|
||||
<li><p>The assets created for using the game engine (“the game world”)</p></li>
|
||||
</ul>
|
||||
<div class="section" id="the-game-engine">
|
||||
<section id="the-game-engine">
|
||||
<h3>The game engine<a class="headerlink" href="#the-game-engine" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The game engine is maintained and modified by programmers (coders). It represents the infrastructure
|
||||
that runs the game - the network code, the protocol support, the handling of commands, scripting and
|
||||
|
|
@ -122,8 +123,8 @@ to add development time. You will also be worse at predicting how ‘hard’ som
|
|||
expect to have to refer to external online tutorials - there are many details of Python that will not be
|
||||
covered.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="asset-creation">
|
||||
</section>
|
||||
<section id="asset-creation">
|
||||
<h3>Asset creation<a class="headerlink" href="#asset-creation" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Compared to the level of work needed to produce professional graphics for an MMORPG, detailed text
|
||||
assets for a mud are cheap to create. This is one of the many reasons muds are so well suited for a
|
||||
|
|
@ -140,9 +141,9 @@ same people (common for early testing), builders need to be able to collaborate
|
|||
and concise feedback.</p>
|
||||
<p>If you know your builders are not tech-savvy, you may need to spend more time making easier
|
||||
build-tools and commands for them.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="so-where-do-i-begin-then">
|
||||
</section>
|
||||
</section>
|
||||
<section id="so-where-do-i-begin-then">
|
||||
<h2>So, where do I begin, then?<a class="headerlink" href="#so-where-do-i-begin-then" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Right, after all this soul-searching and skill-inventory-checking, let’s go back to the original
|
||||
question. And maybe you’ll find that you have a better feeling for the answer yourself already:</p>
|
||||
|
|
@ -171,8 +172,8 @@ from a tutorial is the next step.</p></li>
|
|||
keep in mind that your game is not yet built! Don’t set your builders off on creating large zone projects.
|
||||
If they build anything at all, it should be small test areas to agree on a homogenous form, mood
|
||||
and literary style.</p>
|
||||
</div>
|
||||
<div class="section" id="conclusions">
|
||||
</section>
|
||||
<section id="conclusions">
|
||||
<h2>Conclusions<a class="headerlink" href="#conclusions" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Remember that what kills a hobby game project will usually be your own lack of
|
||||
motivation. So do whatever you can to keep that motivation burning strong! Even if it means
|
||||
|
|
@ -181,8 +182,8 @@ works best for you.</p>
|
|||
<p>In the next lesson we’ll go through some of the technical questions you need to consider. This should
|
||||
hopefully help you figure out more about the game you want to make. In the lesson following that we’ll
|
||||
then try to answer those questions for the sake of creating our little tutorial game.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Evennia Starting Tutorial (Part 2) — 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" />
|
||||
|
|
@ -46,9 +47,9 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="evennia-starting-tutorial-part-2">
|
||||
<section id="evennia-starting-tutorial-part-2">
|
||||
<h1>Evennia Starting Tutorial (Part 2)<a class="headerlink" href="#evennia-starting-tutorial-part-2" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Tutorial Parts</p>
|
||||
<dl class="simple">
|
||||
<dt>Part 1: <a class="reference external" href="../Part1/Starting-Part1.html">What we have</a></dt><dd><p>A tour of Evennia and how to use the tools, including an introduction to Python.</p>
|
||||
|
|
@ -62,8 +63,8 @@
|
|||
<dt>Part 5: <a class="reference external" href="../Part5/Starting-Part5.html">Showing the world</a></dt><dd><p>Taking our new game online and let players try it out</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="section" id="lessons-for-part-2">
|
||||
</aside>
|
||||
<section id="lessons-for-part-2">
|
||||
<h2>Lessons for Part 2<a class="headerlink" href="#lessons-for-part-2" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In Part two of the Starting tutorial we’ll step back and plan out the kind of tutorial
|
||||
game we want to make. This is a more ‘theoretical’ part where we won’t do any hands-on
|
||||
|
|
@ -78,8 +79,8 @@ programming.</p>
|
|||
and “what to think about” when creating a multiplayer online text game.</p>
|
||||
<div class="toctree-wrapper compound">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Making a sittable object — 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" />
|
||||
|
|
@ -38,7 +39,7 @@
|
|||
<div class="body" role="main">
|
||||
|
||||
<p><a class="reference internal" href="../../../Unimplemented.html"><span class="doc">prev lesson</span></a> | <a class="reference internal" href="../../../Unimplemented.html"><span class="doc">next lesson</span></a></p>
|
||||
<div class="section" id="making-a-sittable-object">
|
||||
<section id="making-a-sittable-object">
|
||||
<h1>Making a sittable object<a class="headerlink" href="#making-a-sittable-object" title="Permalink to this headline">¶</a></h1>
|
||||
<p>In this lesson we will go through how to make a chair you can sit on. Sounds easy, right?
|
||||
Well it is. But in the process of making the chair we will need to consider the various ways
|
||||
|
|
@ -60,25 +61,25 @@ which chair to sit on.</p></li>
|
|||
</ul>
|
||||
<p>Both of these are very useful to know about, so in this lesson we’ll try both. But first
|
||||
we need to handle some basics.</p>
|
||||
<div class="section" id="don-t-move-us-when-resting">
|
||||
<section id="don-t-move-us-when-resting">
|
||||
<h2>Don’t move us when resting<a class="headerlink" href="#don-t-move-us-when-resting" title="Permalink to this headline">¶</a></h2>
|
||||
<p>When you are sitting in a chair you can’t just walk off without first standing up.
|
||||
This requires a change to our Character typeclass. Open <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/characters.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="c1"># ...</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Character</span><span class="p">(</span><span class="n">DefaultCharacter</span><span class="p">):</span>
|
||||
|
|
@ -98,55 +99,55 @@ This requires a change to our Character typeclass. Open <code class="docutils li
|
|||
<p>When moving somewhere, <a class="reference external" href="Howto/Starting/Part3/api.objects.objects#Object.move_to">character.move_to</a> is called. This in turn
|
||||
will call <code class="docutils literal notranslate"><span class="pre">character.at_before_move</span></code>. Here we look for an Attribute <code class="docutils literal notranslate"><span class="pre">is_resting</span></code> (which we will assign below)
|
||||
to determine if we are stuck on the chair or not.</p>
|
||||
</div>
|
||||
<div class="section" id="making-the-chair-itself">
|
||||
</section>
|
||||
<section id="making-the-chair-itself">
|
||||
<h2>Making the Chair itself<a class="headerlink" href="#making-the-chair-itself" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Next we need the Chair itself, or rather a whole family of “things you can sit on” that we will call
|
||||
<em>sittables</em>. We can’t just use a default Object since we want a sittable to contain some custom code. We need
|
||||
a new, custom Typeclass. Create a new module <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/sittables.py</span></code> with the following content:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultObject</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Sittable</span><span class="p">(</span><span class="n">DefaultObject</span><span class="p">):</span>
|
||||
|
|
@ -201,53 +202,53 @@ a bunch of chairs for people to sit on. But it’s not perfect. The <code class=
|
|||
make an armchair. You sit “in” an armchair rather than “on” it. We <em>could</em> make a child class of <code class="docutils literal notranslate"><span class="pre">Sittable</span></code> named
|
||||
<code class="docutils literal notranslate"><span class="pre">SittableIn</span></code> that makes this change, but that feels excessive. Instead we will make it so that Sittables can
|
||||
modify this per-instance:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultObject</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Sittable</span><span class="p">(</span><span class="n">DefaultObject</span><span class="p">):</span>
|
||||
|
|
@ -309,89 +310,89 @@ sit down?</p>
|
|||
</div>
|
||||
<p>For this we need to allow some further customization. Let’s let the current strings be defaults that
|
||||
we can replace.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69
|
||||
70
|
||||
71
|
||||
72
|
||||
73
|
||||
74
|
||||
75
|
||||
76
|
||||
77
|
||||
78
|
||||
79
|
||||
80
|
||||
81
|
||||
82
|
||||
83</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span>
|
||||
<span class="normal">60</span>
|
||||
<span class="normal">61</span>
|
||||
<span class="normal">62</span>
|
||||
<span class="normal">63</span>
|
||||
<span class="normal">64</span>
|
||||
<span class="normal">65</span>
|
||||
<span class="normal">66</span>
|
||||
<span class="normal">67</span>
|
||||
<span class="normal">68</span>
|
||||
<span class="normal">69</span>
|
||||
<span class="normal">70</span>
|
||||
<span class="normal">71</span>
|
||||
<span class="normal">72</span>
|
||||
<span class="normal">73</span>
|
||||
<span class="normal">74</span>
|
||||
<span class="normal">75</span>
|
||||
<span class="normal">76</span>
|
||||
<span class="normal">77</span>
|
||||
<span class="normal">78</span>
|
||||
<span class="normal">79</span>
|
||||
<span class="normal">80</span>
|
||||
<span class="normal">81</span>
|
||||
<span class="normal">82</span>
|
||||
<span class="normal">83</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultObject</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Sittable</span><span class="p">(</span><span class="n">DefaultObject</span><span class="p">):</span>
|
||||
|
|
@ -512,8 +513,8 @@ rename the chair later, this will show in the messages automatically (since <cod
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>If you follow along and get a result like this, all seems to be working well!</p>
|
||||
</div>
|
||||
<div class="section" id="command-variant-1-commands-on-the-chair">
|
||||
</section>
|
||||
<section id="command-variant-1-commands-on-the-chair">
|
||||
<h2>Command variant 1: Commands on the chair<a class="headerlink" href="#command-variant-1-commands-on-the-chair" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This way to implement <code class="docutils literal notranslate"><span class="pre">sit</span></code> and <code class="docutils literal notranslate"><span class="pre">stand</span></code> puts new cmdsets on the Sittable itself.
|
||||
As we’ve learned before, commands on objects are made available to others in the room.
|
||||
|
|
@ -535,38 +536,38 @@ handle this for us and allow us to specify which one we want:</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>To keep things separate we’ll make a new module <code class="docutils literal notranslate"><span class="pre">mygame/commands/sittables.py</span></code>:</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Separate Commands and Typeclasses?</p>
|
||||
<p>You can organize these things as you like. If you wanted you could put the sit-command + cmdset
|
||||
together with the <cite>Sittable</cite> typeclass in <cite>mygame/typeclasses/sittables.py</cite>. That has the advantage of
|
||||
keeping everything related to sitting in one place. But there is also some organizational merit to
|
||||
keeping all Commands in one place as we do here.</p>
|
||||
</div>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span><span class="p">,</span> <span class="n">CmdSet</span>
|
||||
</aside>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span><span class="p">,</span> <span class="n">CmdSet</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdSit</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -599,19 +600,19 @@ do the rest.</p>
|
|||
<p>Why that <code class="docutils literal notranslate"><span class="pre">priority</span> <span class="pre">=</span> <span class="pre">1</span></code> on <code class="docutils literal notranslate"><span class="pre">CmdSetSit</span></code>? This makes same-named Commands from this cmdset merge with a bit higher
|
||||
priority than Commands from the Character-cmdset. Why this is a good idea will become clear shortly.</p>
|
||||
<p>We also need to make a change to our <code class="docutils literal notranslate"><span class="pre">Sittable</span></code> typeclass. Open <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/sittables.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultObject</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultObject</span>
|
||||
<span class="kn">from</span> <span class="nn">commands.sittables</span> <span class="kn">import</span> <span class="n">CmdSetSit</span> <span class="c1"># <- new </span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Sittable</span><span class="p">(</span><span class="n">DefaultObject</span><span class="p">):</span>
|
||||
|
|
@ -658,20 +659,20 @@ room without a Sittable object:</p>
|
|||
<p>This is practical but not so good-looking; it makes it harder for the user to know a <code class="docutils literal notranslate"><span class="pre">sit</span></code> action is at all
|
||||
possible. Here is a trick for fixing this. Let’s add <em>another</em> Command to the bottom
|
||||
of <code class="docutils literal notranslate"><span class="pre">mygame/commands/sittables.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ... </span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ... </span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdNoSitStand</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -692,16 +693,16 @@ added <code class="docutils literal notranslate"><span class="pre">stand</span><
|
|||
<em>actually used</em> to call this command. We use this to return different messages.</p>
|
||||
<p>We don’t need a separate CmdSet for this, instead we will add this
|
||||
to the default Character cmdset. Open <code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ... </span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ... </span>
|
||||
<span class="kn">from</span> <span class="nn">commands</span> <span class="kn">import</span> <span class="n">sittables</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CharacterCmdSet</span><span class="p">(</span><span class="n">CmdSet</span><span class="p">):</span>
|
||||
|
|
@ -755,18 +756,18 @@ sit on so we should only get <em>its</em> <code class="docutils literal notransl
|
|||
<p>We will fix this with a <code class="docutils literal notranslate"><span class="pre">lock</span></code> and a custom <code class="docutils literal notranslate"><span class="pre">lock</span> <span class="pre">function</span></code>. We want a lock on the <code class="docutils literal notranslate"><span class="pre">stand</span></code> Command that only
|
||||
makes it available when the caller is actually sitting on the chair the <code class="docutils literal notranslate"><span class="pre">stand</span></code> command is on.</p>
|
||||
<p>First let’s add the lock so we see what we want. Open <code class="docutils literal notranslate"><span class="pre">mygame/commands/sittables.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdStand</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -784,18 +785,18 @@ makes it available when the caller is actually sitting on the chair the <code cl
|
|||
the lock. The <code class="docutils literal notranslate"><span class="pre">cmd</span></code> means that it will check the lock when determining if a user has access to this command or not.
|
||||
What will be checked is the <code class="docutils literal notranslate"><span class="pre">sitsonthis</span></code> <em>lock function</em> which doesn’t exist yet.</p>
|
||||
<p>Open <code class="docutils literal notranslate"><span class="pre">mygame/server/conf/lockfuncs.py</span></code> to add it!</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">"""</span>
|
||||
<span class="sd">(module lockstring)</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="c1"># ... </span>
|
||||
|
|
@ -811,12 +812,12 @@ What will be checked is the <code class="docutils literal notranslate"><span cla
|
|||
</td></tr></table></div>
|
||||
<p>Evennia knows that all functions in <code class="docutils literal notranslate"><span class="pre">mygame/server/conf/lockfuncs</span></code> should be possible to use in a lock definition.
|
||||
The arguments are required and Evennia will pass all relevant objects to them:</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Lockfuncs</p>
|
||||
<p>Evennia provides a large number of default lockfuncs, such as checking permission-levels,
|
||||
if you are carrying or are inside the accessed object etc. There is no concept of ‘sitting’
|
||||
in default Evennia however, so this we need to specify ourselves.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<ul class="simple">
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">accessing_obj</span></code> is the one trying to access the lock. So us, in this case.</p></li>
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">accessed_obj</span></code> is the entity we are trying to gain a particular type of access to. So the chair.</p></li>
|
||||
|
|
@ -836,8 +837,8 @@ bypasses all locks - it can never get locked out, but it means it will also not
|
|||
<p>Adding a Command to the chair object like this is powerful and a good technique to know. It does come with some
|
||||
caveats though that one needs to keep in mind.</p>
|
||||
<p>We’ll now try another way to add the <code class="docutils literal notranslate"><span class="pre">sit/stand</span></code> commands.</p>
|
||||
</div>
|
||||
<div class="section" id="command-variant-2-command-on-character">
|
||||
</section>
|
||||
<section id="command-variant-2-command-on-character">
|
||||
<h2>Command variant 2: Command on Character<a class="headerlink" href="#command-variant-2-command-on-character" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Before we start with this, delete the chairs you’ve created (<code class="docutils literal notranslate"><span class="pre">del</span> <span class="pre">armchair</span></code> etc) and then do the following
|
||||
changes:</p>
|
||||
|
|
@ -859,42 +860,42 @@ chair to sit on. We can’t just do <code class="docutils literal notranslate"><
|
|||
<p>Open <code class="docutils literal notranslate"><span class="pre">mygame/commands.sittables.py</span></code> again. We’ll add a new sit-command. We name the class <code class="docutils literal notranslate"><span class="pre">CmdSit2</span></code> since
|
||||
we already have <code class="docutils literal notranslate"><span class="pre">CmdSit</span></code> from the previous example. We put everything at the end of the module to
|
||||
keep it separate.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span><span class="p">,</span> <span class="n">CmdSet</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span><span class="p">,</span> <span class="n">CmdSet</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">InterruptCommand</span> <span class="c1"># <- this is new</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdSit</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
|
|
@ -942,13 +943,13 @@ are run in sequence:</p>
|
|||
</ol>
|
||||
<p>So if we just <code class="docutils literal notranslate"><span class="pre">return</span></code> in <code class="docutils literal notranslate"><span class="pre">.parse</span></code>, <code class="docutils literal notranslate"><span class="pre">.func</span></code> will still run, which is not what we want. To immediately
|
||||
abort this sequence we need to <code class="docutils literal notranslate"><span class="pre">raise</span> <span class="pre">InterruptCommand</span></code>.</p>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Raising exceptions</p>
|
||||
<p>Raising an exception allows for immediately interrupting the current program flow. Python
|
||||
automatically raises error-exceptions when detecting problems with the code. It will be
|
||||
raised up through the sequence of called code (the ‘stack’) until it’s either <cite>caught</cite> with
|
||||
a <cite>try … except</cite> or reaches the outermost scope where it’ll be logged or displayed.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">InterruptCommand</span></code> is an <em>exception</em> that the Command-system catches with the understanding that we want
|
||||
to do a clean abort. In the <code class="docutils literal notranslate"><span class="pre">.parse</span></code> method we strip any whitespaces from the argument and
|
||||
sure there actuall <em>is</em> an argument. We abort immediately if there isn’t.</p>
|
||||
|
|
@ -959,11 +960,11 @@ a problem finding the target.</p>
|
|||
and there is no harm done if <code class="docutils literal notranslate"><span class="pre">at_post_func</span></code> runs since it’s empty.</p>
|
||||
</div></blockquote>
|
||||
<p>Next we call the found sittable’s <code class="docutils literal notranslate"><span class="pre">do_sit</span></code> method. Note that we wrap this call like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="k">try</span><span class="p">:</span>
|
||||
<span class="c1"># code </span>
|
||||
<span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
|
||||
|
|
@ -977,18 +978,18 @@ ask for forgiveness than for permission”. If <code class="docutils literal not
|
|||
We catch this with <code class="docutils literal notranslate"><span class="pre">try</span> <span class="pre">...</span> <span class="pre">except</span> <span class="pre">AttributeError</span></code> and convert it to a proper error message.</p>
|
||||
<p>While it’s useful to learn about <code class="docutils literal notranslate"><span class="pre">try</span> <span class="pre">...</span> <span class="pre">except</span></code>, there is also a way to leverage Evennia to do this without
|
||||
<code class="docutils literal notranslate"><span class="pre">try</span> <span class="pre">...</span> <span class="pre">except</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="c1"># ... </span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
|
|
@ -1002,46 +1003,46 @@ We catch this with <code class="docutils literal notranslate"><span class="pre">
|
|||
<span class="n">sittable</span><span class="o">.</span><span class="n">do_sit</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Continuing across multiple lines</p>
|
||||
<p>Note how the <cite>.search()</cite> method’s arguments are spread out over multiple
|
||||
lines. This works for all lists, tuples and other listings and is
|
||||
a good way to avoid very long and hard-to-read lines.</p>
|
||||
</div>
|
||||
</aside>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">caller.search</span></code> method has an keyword argument <code class="docutils literal notranslate"><span class="pre">typeclass</span></code> that can take either a python-path to a
|
||||
typeclass, the typeclass itself, or a list of either to widen the allowed options. In this case we know
|
||||
for sure that the <code class="docutils literal notranslate"><span class="pre">sittable</span></code> we get is actually a <code class="docutils literal notranslate"><span class="pre">Sittable</span></code> class and we can call <code class="docutils literal notranslate"><span class="pre">sittable.do_sit</span></code> without
|
||||
needing to worry about catching errors.</p>
|
||||
<p>Let’s do the <code class="docutils literal notranslate"><span class="pre">stand</span></code> command while we are at it. Again, since the Command is external to the chair we don’t
|
||||
know which object we are sitting in and have to search for it.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="k">class</span> <span class="nc">CmdStand2</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> Stand up.</span>
|
||||
|
|
@ -1078,17 +1079,17 @@ which should be set to us, the one sitting on/in the thing. Once we have that we
|
|||
and let the Typeclass handle the rest.</p>
|
||||
<p>All that is left now is to make this available to us. This type of Command should be available to us all the time
|
||||
so we can put it in the default Cmdset<code class="docutils literal notranslate"><span class="pre">on</span> <span class="pre">the</span> <span class="pre">Character.</span> <span class="pre">Open</span></code>mygame/default_cmdsets.py`</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ... </span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ... </span>
|
||||
<span class="kn">from</span> <span class="nn">commands</span> <span class="kn">import</span> <span class="n">sittables</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CharacterCmdSet</span><span class="p">(</span><span class="n">CmdSet</span><span class="p">):</span>
|
||||
|
|
@ -1110,8 +1111,8 @@ so we can put it in the default Cmdset<code class="docutils literal notranslate"
|
|||
<span class="n">You</span> <span class="n">stand</span> <span class="n">up</span> <span class="kn">from</span> <span class="nn">sofa.</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="conclusions">
|
||||
</section>
|
||||
<section id="conclusions">
|
||||
<h2>Conclusions<a class="headerlink" href="#conclusions" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In this lesson we accomplished quite a bit:</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -1123,8 +1124,8 @@ so we can put it in the default Cmdset<code class="docutils literal notranslate"
|
|||
together with the <code class="docutils literal notranslate"><span class="pre">sit</span></code> command sitting “on” the Character (variant 2). There is nothing stopping you from
|
||||
mixing them, or even try a third solution that better fits what you have in mind.</p>
|
||||
<p><a class="reference internal" href="../../../Unimplemented.html"><span class="doc">prev lesson</span></a> | <a class="reference internal" href="../../../Unimplemented.html"><span class="doc">next lesson</span></a></p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Implementing a game rule system — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="implementing-a-game-rule-system">
|
||||
<section id="implementing-a-game-rule-system">
|
||||
<h1>Implementing a game rule system<a class="headerlink" href="#implementing-a-game-rule-system" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The simplest way to create an online roleplaying game (at least from a code perspective) is to
|
||||
simply grab a paperback RPG rule book, get a staff of game masters together and start to run scenes
|
||||
|
|
@ -63,7 +64,7 @@ are those resulting from code. Such games are very common and include everything
|
|||
MUDs to various tactical simulations.</p>
|
||||
<p>So your first decision needs to be just what type of system you are aiming for. This page will try
|
||||
to give some ideas for how to organize the “coded” part of your system, however big that may be.</p>
|
||||
<div class="section" id="overall-system-infrastructure">
|
||||
<section id="overall-system-infrastructure">
|
||||
<h2>Overall system infrastructure<a class="headerlink" href="#overall-system-infrastructure" title="Permalink to this headline">¶</a></h2>
|
||||
<p>We strongly recommend that you code your rule system as stand-alone as possible. That is, don’t
|
||||
spread your skill check code, race bonus calculation, die modifiers or what have you all over your
|
||||
|
|
@ -88,9 +89,9 @@ complexity of your system.</p></li>
|
|||
<li><p>Make a clear <a class="reference external" href="http://en.wikipedia.org/wiki/Application_programming_interface">API</a> into your
|
||||
rules. That is, make methods/functions that you feed with, say, your Character and which skill you
|
||||
want to check. That is, you want something similar to this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="kn">from</span> <span class="nn">world</span> <span class="kn">import</span> <span class="n">rules</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="kn">from</span> <span class="nn">world</span> <span class="kn">import</span> <span class="n">rules</span>
|
||||
<span class="n">result</span> <span class="o">=</span> <span class="n">rules</span><span class="o">.</span><span class="n">roll_skill</span><span class="p">(</span><span class="n">character</span><span class="p">,</span> <span class="s2">"hunting"</span><span class="p">)</span>
|
||||
<span class="n">result</span> <span class="o">=</span> <span class="n">rules</span><span class="o">.</span><span class="n">roll_challenge</span><span class="p">(</span><span class="n">character1</span><span class="p">,</span> <span class="n">character2</span><span class="p">,</span> <span class="s2">"swords"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
|
@ -101,8 +102,8 @@ want to check. That is, you want something similar to this:</p>
|
|||
properties of the room might matter to the outcome of a roll (if the room is dark, burning etc).
|
||||
Establishing just what you need to send into your game mechanic module is a great way to also get a
|
||||
feel for what you need to add to your engine.</p>
|
||||
</div>
|
||||
<div class="section" id="coded-systems">
|
||||
</section>
|
||||
<section id="coded-systems">
|
||||
<h2>Coded systems<a class="headerlink" href="#coded-systems" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Inspired by tabletop role playing games, most game systems mimic some sort of die mechanic. To this
|
||||
end Evennia offers a full <a class="reference external" href="https://github.com/evennia/evennia/blob/master/evennia/contrib/dice.py">dice
|
||||
|
|
@ -123,8 +124,8 @@ informed they have increased a level.</p></li>
|
|||
weather, NPC artificial intelligence and game economy. Basically everything about the world that a
|
||||
Game master would control in a tabletop role playing game can be mimicked to some level by coded
|
||||
systems.</p>
|
||||
</div>
|
||||
<div class="section" id="example-of-rule-module">
|
||||
</section>
|
||||
<section id="example-of-rule-module">
|
||||
<h2>Example of Rule module<a class="headerlink" href="#example-of-rule-module" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Here is a simple example of a rule module. This is what we assume about our simple example game:</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -153,25 +154,25 @@ example we ignore weapons and assume <code class="docutils literal notranslate">
|
|||
reaches <code class="docutils literal notranslate"><span class="pre">(level</span> <span class="pre">+</span> <span class="pre">1)</span> <span class="pre">**</span> <span class="pre">2</span></code>, the Character levels up. When leveling up, the Character’s <code class="docutils literal notranslate"><span class="pre">combat</span></code>
|
||||
value goes up by 2 points and <code class="docutils literal notranslate"><span class="pre">STR</span></code> by one (this is a stand-in for a real progression system).</p></li>
|
||||
</ul>
|
||||
<div class="section" id="character">
|
||||
<section id="character">
|
||||
<h3>Character<a class="headerlink" href="#character" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The Character typeclass is simple. It goes in <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/characters.py</span></code>. There is already
|
||||
an empty <code class="docutils literal notranslate"><span class="pre">Character</span></code> class there that Evennia will look to and use.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultCharacter</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Character</span><span class="p">(</span><span class="n">DefaultCharacter</span><span class="p">):</span>
|
||||
|
|
@ -196,79 +197,79 @@ the following command:</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">examine</span> <span class="pre">self</span></code> command will now show the new Attributes.</p>
|
||||
</div>
|
||||
<div class="section" id="rule-module">
|
||||
</section>
|
||||
<section id="rule-module">
|
||||
<h3>Rule module<a class="headerlink" href="#rule-module" title="Permalink to this headline">¶</a></h3>
|
||||
<p>This is a module <code class="docutils literal notranslate"><span class="pre">mygame/world/rules.py</span></code>.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span>
|
||||
<span class="normal">60</span>
|
||||
<span class="normal">61</span>
|
||||
<span class="normal">62</span>
|
||||
<span class="normal">63</span>
|
||||
<span class="normal">64</span>
|
||||
<span class="normal">65</span>
|
||||
<span class="normal">66</span>
|
||||
<span class="normal">67</span>
|
||||
<span class="normal">68</span>
|
||||
<span class="normal">69</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">roll_hit</span><span class="p">():</span>
|
||||
<span class="s2">"Roll 1d100"</span>
|
||||
|
|
@ -347,30 +348,30 @@ function <code class="docutils literal notranslate"><span class="pre">roll_chall
|
|||
<p>In this example, the skill function actually does a lot - it not only rolls results, it also informs
|
||||
everyone of their results via <code class="docutils literal notranslate"><span class="pre">character.msg()</span></code> calls.</p>
|
||||
<p>Here is an example of usage in a game command:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
<span class="kn">from</span> <span class="nn">world</span> <span class="kn">import</span> <span class="n">rules</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdAttack</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
|
|
@ -401,9 +402,9 @@ number of Combat commands by just extending this functionality - you can easily
|
|||
pick different skills to check. And if you ever decided to, say, change how to determine hit chance,
|
||||
you don’t have to change every command, but need only change the single <code class="docutils literal notranslate"><span class="pre">roll_hit</span></code> function inside
|
||||
your <code class="docutils literal notranslate"><span class="pre">rules</span></code> module.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Evennia Starting Tutorial (Part 3) — 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" />
|
||||
|
|
@ -47,9 +48,9 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="evennia-starting-tutorial-part-3">
|
||||
<section id="evennia-starting-tutorial-part-3">
|
||||
<h1>Evennia Starting Tutorial (Part 3)<a class="headerlink" href="#evennia-starting-tutorial-part-3" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Tutorial Parts</p>
|
||||
<dl class="simple">
|
||||
<dt>Part 1: <a class="reference external" href="../Part1/Starting-Part1.html">What we have</a></dt><dd><p>A tour of Evennia and how to use the tools, including an introduction to Python.</p>
|
||||
|
|
@ -63,7 +64,7 @@
|
|||
<dt>Part 5: <a class="reference external" href="../Part5/Starting-Part5.html">Showing the world</a></dt><dd><p>Taking our new game online and let players try it out</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</aside>
|
||||
<p>In part three of the Evennia Starting tutorial we will go through the creation of several key parts
|
||||
of our tutorial game <em>EvAdventure</em>. As we go, we will test each part and create a simple “tech demo” to
|
||||
show off all the moving parts.</p>
|
||||
|
|
@ -87,7 +88,7 @@ with using Evennia. This be of much use when doing your own thing later.</p>
|
|||
<p><em>TODO</em></p>
|
||||
<div class="toctree-wrapper compound">
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Turn based Combat System — 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" />
|
||||
|
|
@ -37,12 +38,12 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="turn-based-combat-system">
|
||||
<section id="turn-based-combat-system">
|
||||
<h1>Turn based Combat System<a class="headerlink" href="#turn-based-combat-system" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This tutorial gives an example of a full, if simplified, combat system for Evennia. It was inspired
|
||||
by the discussions held on the <a class="reference external" href="https://groups.google.com/forum/#%21msg/evennia/wnJNM2sXSfs/-dbLRrgWnYMJ">mailing
|
||||
list</a>.</p>
|
||||
<div class="section" id="overview-of-combat-system-concepts">
|
||||
<section id="overview-of-combat-system-concepts">
|
||||
<h2>Overview of combat system concepts<a class="headerlink" href="#overview-of-combat-system-concepts" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Most MUDs will use some sort of combat system. There are several main variations:</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -70,8 +71,8 @@ example dice roller. To implement at twitch-based system you basically need a fe
|
|||
<a class="reference internal" href="../../../Components/Commands.html"><span class="doc">commands</span></a>, possibly ones with a <a class="reference internal" href="../../Command-Cooldown.html"><span class="doc">cooldown</span></a>. You also need a <a class="reference internal" href="Implementing-a-game-rule-system.html"><span class="doc">game rule
|
||||
module</span></a> that makes use of it. We will focus on the turn-based
|
||||
variety here.</p>
|
||||
</div>
|
||||
<div class="section" id="tutorial-overview">
|
||||
</section>
|
||||
<section id="tutorial-overview">
|
||||
<h2>Tutorial overview<a class="headerlink" href="#tutorial-overview" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This tutorial will implement the slightly more complex turn-based combat system. Our example has the
|
||||
following properties:</p>
|
||||
|
|
@ -110,8 +111,8 @@ combat resolution.</p></li>
|
|||
command set. It will create the combat handler and add the character(s) to it. It will also assign
|
||||
the combat command set to the characters.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="the-combat-handler">
|
||||
</section>
|
||||
<section id="the-combat-handler">
|
||||
<h2>The combat handler<a class="headerlink" href="#the-combat-handler" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The <em>combat handler</em> is implemented as a stand-alone <a class="reference internal" href="../../../Components/Scripts.html"><span class="doc">Script</span></a>. This Script is created when
|
||||
the first Character decides to attack another and is deleted when no one is fighting any more. Each
|
||||
|
|
@ -129,167 +130,167 @@ methods on the character or to implement a custom child of the TickerHandler cla
|
|||
Whereas the TickerHandler is easy to use, a Script offers more power in this case.</em></p>
|
||||
<p>Here is a basic combat handler. Assuming our game folder is named <code class="docutils literal notranslate"><span class="pre">mygame</span></code>, we store it in
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/combat_handler.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69
|
||||
70
|
||||
71
|
||||
72
|
||||
73
|
||||
74
|
||||
75
|
||||
76
|
||||
77
|
||||
78
|
||||
79
|
||||
80
|
||||
81
|
||||
82
|
||||
83
|
||||
84
|
||||
85
|
||||
86
|
||||
87
|
||||
88
|
||||
89
|
||||
90
|
||||
91
|
||||
92
|
||||
93
|
||||
94
|
||||
95
|
||||
96
|
||||
97
|
||||
98
|
||||
99
|
||||
100
|
||||
101
|
||||
102
|
||||
103
|
||||
104
|
||||
105
|
||||
106
|
||||
107
|
||||
108
|
||||
109
|
||||
110
|
||||
111
|
||||
112
|
||||
113
|
||||
114
|
||||
115
|
||||
116
|
||||
117
|
||||
118
|
||||
119
|
||||
120
|
||||
121
|
||||
122
|
||||
123
|
||||
124
|
||||
125
|
||||
126
|
||||
127
|
||||
128
|
||||
129
|
||||
130
|
||||
131
|
||||
132
|
||||
133
|
||||
134
|
||||
135
|
||||
136
|
||||
137
|
||||
138
|
||||
139
|
||||
140
|
||||
141
|
||||
142
|
||||
143
|
||||
144
|
||||
145
|
||||
146
|
||||
147
|
||||
148
|
||||
149
|
||||
150
|
||||
151
|
||||
152
|
||||
153
|
||||
154
|
||||
155
|
||||
156
|
||||
157
|
||||
158
|
||||
159
|
||||
160
|
||||
161</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/combat_handler.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal"> 37</span>
|
||||
<span class="normal"> 38</span>
|
||||
<span class="normal"> 39</span>
|
||||
<span class="normal"> 40</span>
|
||||
<span class="normal"> 41</span>
|
||||
<span class="normal"> 42</span>
|
||||
<span class="normal"> 43</span>
|
||||
<span class="normal"> 44</span>
|
||||
<span class="normal"> 45</span>
|
||||
<span class="normal"> 46</span>
|
||||
<span class="normal"> 47</span>
|
||||
<span class="normal"> 48</span>
|
||||
<span class="normal"> 49</span>
|
||||
<span class="normal"> 50</span>
|
||||
<span class="normal"> 51</span>
|
||||
<span class="normal"> 52</span>
|
||||
<span class="normal"> 53</span>
|
||||
<span class="normal"> 54</span>
|
||||
<span class="normal"> 55</span>
|
||||
<span class="normal"> 56</span>
|
||||
<span class="normal"> 57</span>
|
||||
<span class="normal"> 58</span>
|
||||
<span class="normal"> 59</span>
|
||||
<span class="normal"> 60</span>
|
||||
<span class="normal"> 61</span>
|
||||
<span class="normal"> 62</span>
|
||||
<span class="normal"> 63</span>
|
||||
<span class="normal"> 64</span>
|
||||
<span class="normal"> 65</span>
|
||||
<span class="normal"> 66</span>
|
||||
<span class="normal"> 67</span>
|
||||
<span class="normal"> 68</span>
|
||||
<span class="normal"> 69</span>
|
||||
<span class="normal"> 70</span>
|
||||
<span class="normal"> 71</span>
|
||||
<span class="normal"> 72</span>
|
||||
<span class="normal"> 73</span>
|
||||
<span class="normal"> 74</span>
|
||||
<span class="normal"> 75</span>
|
||||
<span class="normal"> 76</span>
|
||||
<span class="normal"> 77</span>
|
||||
<span class="normal"> 78</span>
|
||||
<span class="normal"> 79</span>
|
||||
<span class="normal"> 80</span>
|
||||
<span class="normal"> 81</span>
|
||||
<span class="normal"> 82</span>
|
||||
<span class="normal"> 83</span>
|
||||
<span class="normal"> 84</span>
|
||||
<span class="normal"> 85</span>
|
||||
<span class="normal"> 86</span>
|
||||
<span class="normal"> 87</span>
|
||||
<span class="normal"> 88</span>
|
||||
<span class="normal"> 89</span>
|
||||
<span class="normal"> 90</span>
|
||||
<span class="normal"> 91</span>
|
||||
<span class="normal"> 92</span>
|
||||
<span class="normal"> 93</span>
|
||||
<span class="normal"> 94</span>
|
||||
<span class="normal"> 95</span>
|
||||
<span class="normal"> 96</span>
|
||||
<span class="normal"> 97</span>
|
||||
<span class="normal"> 98</span>
|
||||
<span class="normal"> 99</span>
|
||||
<span class="normal">100</span>
|
||||
<span class="normal">101</span>
|
||||
<span class="normal">102</span>
|
||||
<span class="normal">103</span>
|
||||
<span class="normal">104</span>
|
||||
<span class="normal">105</span>
|
||||
<span class="normal">106</span>
|
||||
<span class="normal">107</span>
|
||||
<span class="normal">108</span>
|
||||
<span class="normal">109</span>
|
||||
<span class="normal">110</span>
|
||||
<span class="normal">111</span>
|
||||
<span class="normal">112</span>
|
||||
<span class="normal">113</span>
|
||||
<span class="normal">114</span>
|
||||
<span class="normal">115</span>
|
||||
<span class="normal">116</span>
|
||||
<span class="normal">117</span>
|
||||
<span class="normal">118</span>
|
||||
<span class="normal">119</span>
|
||||
<span class="normal">120</span>
|
||||
<span class="normal">121</span>
|
||||
<span class="normal">122</span>
|
||||
<span class="normal">123</span>
|
||||
<span class="normal">124</span>
|
||||
<span class="normal">125</span>
|
||||
<span class="normal">126</span>
|
||||
<span class="normal">127</span>
|
||||
<span class="normal">128</span>
|
||||
<span class="normal">129</span>
|
||||
<span class="normal">130</span>
|
||||
<span class="normal">131</span>
|
||||
<span class="normal">132</span>
|
||||
<span class="normal">133</span>
|
||||
<span class="normal">134</span>
|
||||
<span class="normal">135</span>
|
||||
<span class="normal">136</span>
|
||||
<span class="normal">137</span>
|
||||
<span class="normal">138</span>
|
||||
<span class="normal">139</span>
|
||||
<span class="normal">140</span>
|
||||
<span class="normal">141</span>
|
||||
<span class="normal">142</span>
|
||||
<span class="normal">143</span>
|
||||
<span class="normal">144</span>
|
||||
<span class="normal">145</span>
|
||||
<span class="normal">146</span>
|
||||
<span class="normal">147</span>
|
||||
<span class="normal">148</span>
|
||||
<span class="normal">149</span>
|
||||
<span class="normal">150</span>
|
||||
<span class="normal">151</span>
|
||||
<span class="normal">152</span>
|
||||
<span class="normal">153</span>
|
||||
<span class="normal">154</span>
|
||||
<span class="normal">155</span>
|
||||
<span class="normal">156</span>
|
||||
<span class="normal">157</span>
|
||||
<span class="normal">158</span>
|
||||
<span class="normal">159</span>
|
||||
<span class="normal">160</span>
|
||||
<span class="normal">161</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/combat_handler.py</span>
|
||||
|
||||
<span class="kn">import</span> <span class="nn">random</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultScript</span>
|
||||
|
|
@ -460,48 +461,48 @@ This allows for everything to go through the same mechanisms with minimal repeti
|
|||
<p>What is not present in this handler is a way for players to view the actions they set or to change
|
||||
their actions once they have been added (but before the last one has added theirs). We leave this as
|
||||
an exercise.</p>
|
||||
</div>
|
||||
<div class="section" id="combat-commands">
|
||||
</section>
|
||||
<section id="combat-commands">
|
||||
<h2>Combat commands<a class="headerlink" href="#combat-commands" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Our combat commands - the commands that are to be available to us during the combat - are (in our
|
||||
example) very simple. In a full implementation the commands available might be determined by the
|
||||
weapon(s) held by the player or by which skills they know.</p>
|
||||
<p>We create them in <code class="docutils literal notranslate"><span class="pre">mygame/commands/combat.py</span></code>.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/commands/combat.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/commands/combat.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||||
|
||||
|
|
@ -542,26 +543,26 @@ weapon(s) held by the player or by which skills they know.</p>
|
|||
We should also add a custom <code class="docutils literal notranslate"><span class="pre">help</span></code> command to list all the available combat commands and what they
|
||||
do.</p>
|
||||
<p>We just need to put them all in a cmdset. We do this at the end of the same module:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/commands/combat.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/commands/combat.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">CmdSet</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span>
|
||||
|
|
@ -583,8 +584,8 @@ do.</p>
|
|||
<span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">CmdSay</span><span class="p">())</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="rules-module">
|
||||
</section>
|
||||
<section id="rules-module">
|
||||
<h2>Rules module<a class="headerlink" href="#rules-module" title="Permalink to this headline">¶</a></h2>
|
||||
<p>A general way to implement a rule module is found in the [rule system tutorial](Implementing-a-game-
|
||||
rule-system). Proper resolution would likely require us to change our Characters to store things
|
||||
|
|
@ -610,82 +611,82 @@ subsequent attack and so on …</em></p>
|
|||
<li><p><code class="docutils literal notranslate"><span class="pre">flee/disengage</span></code> must succeed two times in a row (i.e. not beaten by a <code class="docutils literal notranslate"><span class="pre">hit</span></code> once during the
|
||||
turn). If so the character leaves combat.</p></li>
|
||||
</ul>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69
|
||||
70
|
||||
71
|
||||
72
|
||||
73
|
||||
74
|
||||
75
|
||||
76</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/world/rules.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span>
|
||||
<span class="normal">60</span>
|
||||
<span class="normal">61</span>
|
||||
<span class="normal">62</span>
|
||||
<span class="normal">63</span>
|
||||
<span class="normal">64</span>
|
||||
<span class="normal">65</span>
|
||||
<span class="normal">66</span>
|
||||
<span class="normal">67</span>
|
||||
<span class="normal">68</span>
|
||||
<span class="normal">69</span>
|
||||
<span class="normal">70</span>
|
||||
<span class="normal">71</span>
|
||||
<span class="normal">72</span>
|
||||
<span class="normal">73</span>
|
||||
<span class="normal">74</span>
|
||||
<span class="normal">75</span>
|
||||
<span class="normal">76</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/world/rules.py</span>
|
||||
|
||||
<span class="kn">import</span> <span class="nn">random</span>
|
||||
|
||||
|
|
@ -768,48 +769,48 @@ twice - first when it gets to each character and then again when handling the ta
|
|||
use the combat handler’s <code class="docutils literal notranslate"><span class="pre">msg_all</span></code> method here, the system will get pretty spammy. To clean it up,
|
||||
one could imagine tracking all the possible interactions to make sure each pair is only handled and
|
||||
reported once.</p>
|
||||
</div>
|
||||
<div class="section" id="combat-initiator-command">
|
||||
</section>
|
||||
<section id="combat-initiator-command">
|
||||
<h2>Combat initiator command<a class="headerlink" href="#combat-initiator-command" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This is the last component we need, a command to initiate combat. This will tie everything together.
|
||||
We store this with the other combat commands.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/commands/combat.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/commands/combat.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">create_script</span>
|
||||
|
||||
|
|
@ -850,8 +851,8 @@ We store this with the other combat commands.</p>
|
|||
</td></tr></table></div>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">attack</span></code> command will not go into the combat cmdset but rather into the default cmdset. See e.g.
|
||||
the <a class="reference internal" href="../Part1/Adding-Commands.html"><span class="doc">Adding Command Tutorial</span></a> if you are unsure about how to do this.</p>
|
||||
</div>
|
||||
<div class="section" id="expanding-the-example">
|
||||
</section>
|
||||
<section id="expanding-the-example">
|
||||
<h2>Expanding the example<a class="headerlink" href="#expanding-the-example" title="Permalink to this headline">¶</a></h2>
|
||||
<p>At this point you should have a simple but flexible turn-based combat system. We have taken several
|
||||
shortcuts and simplifications in this example. The output to the players is likely too verbose
|
||||
|
|
@ -861,8 +862,8 @@ play testing for each game and style. There is also currently no information dis
|
|||
people happening to be in the same room as the combat - some less detailed information should
|
||||
probably be echoed to the room to
|
||||
show others what’s going on.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Tutorial for basic MUSH like game — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="tutorial-for-basic-mush-like-game">
|
||||
<section id="tutorial-for-basic-mush-like-game">
|
||||
<h1>Tutorial for basic MUSH like game<a class="headerlink" href="#tutorial-for-basic-mush-like-game" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This tutorial lets you code a small but complete and functioning MUSH-like game in Evennia. A
|
||||
<a class="reference external" href="http://en.wikipedia.org/wiki/MUSH">MUSH</a> is, for our purposes, a class of roleplay-centric games
|
||||
|
|
@ -64,7 +65,7 @@ controlling code).</p></li>
|
|||
</ul>
|
||||
<p>In this tutorial we will assume you are starting from an empty database without any previous
|
||||
modifications.</p>
|
||||
<div class="section" id="server-settings">
|
||||
<section id="server-settings">
|
||||
<h2>Server Settings<a class="headerlink" href="#server-settings" title="Permalink to this headline">¶</a></h2>
|
||||
<p>To emulate a MUSH, the default <code class="docutils literal notranslate"><span class="pre">MULTISESSION_MODE=0</span></code> is enough (one unique session per
|
||||
account/character). This is the default so you don’t need to change anything. You will still be able
|
||||
|
|
@ -72,24 +73,24 @@ to puppet/unpuppet objects you have permission to, but there is no character sel
|
|||
box in this mode.</p>
|
||||
<p>We will assume our game folder is called <code class="docutils literal notranslate"><span class="pre">mygame</span></code> henceforth. You should be fine with the default
|
||||
SQLite3 database.</p>
|
||||
</div>
|
||||
<div class="section" id="creating-the-character">
|
||||
</section>
|
||||
<section id="creating-the-character">
|
||||
<h2>Creating the Character<a class="headerlink" href="#creating-the-character" title="Permalink to this headline">¶</a></h2>
|
||||
<p>First thing is to choose how our Character class works. We don’t need to define a special NPC object
|
||||
– an NPC is after all just a Character without an Account currently controlling them.</p>
|
||||
<p>Make your changes in the <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/characters.py</span></code> file:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/characters.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/characters.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultCharacter</span>
|
||||
|
||||
|
|
@ -121,8 +122,8 @@ accidentally), this means that <code class="docutils literal notranslate"><span
|
|||
set on yourself by <code class="docutils literal notranslate"><span class="pre">at_object_creation</span></code>. If you don’t, first make sure you <code class="docutils literal notranslate"><span class="pre">@reload</span></code>ed into the new
|
||||
code, next look at your server log (in the terminal/console) to see if there were any syntax errors
|
||||
in your code that may have stopped your new code from loading correctly.</p>
|
||||
</div>
|
||||
<div class="section" id="character-generation">
|
||||
</section>
|
||||
<section id="character-generation">
|
||||
<h2>Character Generation<a class="headerlink" href="#character-generation" title="Permalink to this headline">¶</a></h2>
|
||||
<p>We assume in this example that Accounts first connect into a “character generation area”. Evennia
|
||||
also supports full OOC menu-driven character generation, but for this example, a simple start room
|
||||
|
|
@ -138,7 +139,7 @@ check it. Using this method however will make it easy to add more functionality
|
|||
<li><p>A custom <code class="docutils literal notranslate"><span class="pre">ChargenRoom</span></code> type that makes this set of commands available to players in such rooms.</p></li>
|
||||
<li><p>One such room to test things in.</p></li>
|
||||
</ul>
|
||||
<div class="section" id="the-setpower-command">
|
||||
<section id="the-setpower-command">
|
||||
<h3>The +setpower command<a class="headerlink" href="#the-setpower-command" title="Permalink to this headline">¶</a></h3>
|
||||
<p>For this tutorial we will add all our new commands to <code class="docutils literal notranslate"><span class="pre">mygame/commands/command.py</span></code> but you could
|
||||
split your commands into multiple module if you prefered.</p>
|
||||
|
|
@ -152,40 +153,40 @@ Character s “power” stat. It will be called on the following MUSH-like form:
|
|||
<code class="docutils literal notranslate"><span class="pre">MuxCommand</span></code> class offers some extra features like stripping whitespace that may be useful - if so,
|
||||
just import from that instead.</p>
|
||||
<p>Add the following to the end of the <code class="docutils literal notranslate"><span class="pre">command.py</span></code> file:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># end of command.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># end of command.py</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span> <span class="c1"># just for clarity; already imported above</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdSetPower</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
|
|
@ -228,23 +229,23 @@ in the help list.</p>
|
|||
chargen system you would of course have more than one command here).</p>
|
||||
<p>Open <code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code> and import your <code class="docutils literal notranslate"><span class="pre">command.py</span></code> module at the top. We also
|
||||
import the default <code class="docutils literal notranslate"><span class="pre">CmdSet</span></code> class for the next step:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">CmdSet</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
||||
<span class="normal">2</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">CmdSet</span>
|
||||
<span class="kn">from</span> <span class="nn">commands</span> <span class="kn">import</span> <span class="n">command</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>Next scroll down and define a new command set (based on the base <code class="docutils literal notranslate"><span class="pre">CmdSet</span></code> class we just imported at
|
||||
the end of this file, to hold only our chargen-specific command(s):</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># end of default_cmdsets.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># end of default_cmdsets.py</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">ChargenCmdset</span><span class="p">(</span><span class="n">CmdSet</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -260,24 +261,24 @@ the end of this file, to hold only our chargen-specific command(s):</p>
|
|||
system as you desire. Now we need to actually put that cmdset on something so it’s made available to
|
||||
users. We could put it directly on the Character, but that would make it available all the time.
|
||||
It’s cleaner to put it on a room, so it’s only available when players are in that room.</p>
|
||||
</div>
|
||||
<div class="section" id="chargen-areas">
|
||||
</section>
|
||||
<section id="chargen-areas">
|
||||
<h3>Chargen areas<a class="headerlink" href="#chargen-areas" title="Permalink to this headline">¶</a></h3>
|
||||
<p>We will create a simple Room typeclass to act as a template for all our Chargen areas. Edit
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/rooms.py</span></code> next:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">commands.default_cmdsets</span> <span class="kn">import</span> <span class="n">ChargenCmdset</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">commands.default_cmdsets</span> <span class="kn">import</span> <span class="n">ChargenCmdset</span>
|
||||
|
||||
<span class="c1"># ... </span>
|
||||
<span class="c1"># down at the end of rooms.py</span>
|
||||
|
|
@ -296,8 +297,8 @@ It’s cleaner to put it on a room, so it’s only available when players are in
|
|||
Don’t forget the <code class="docutils literal notranslate"><span class="pre">permanent=True</span></code> keyword or you will lose the cmdset after a server reload. For
|
||||
more information about <a class="reference internal" href="../../../Components/Command-Sets.html"><span class="doc">Command Sets</span></a> and <a class="reference internal" href="../../../Components/Commands.html"><span class="doc">Commands</span></a>, see the respective
|
||||
links.</p>
|
||||
</div>
|
||||
<div class="section" id="testing-chargen">
|
||||
</section>
|
||||
<section id="testing-chargen">
|
||||
<h3>Testing chargen<a class="headerlink" href="#testing-chargen" title="Permalink to this headline">¶</a></h3>
|
||||
<p>First, make sure you have <code class="docutils literal notranslate"><span class="pre">@reload</span></code>ed the server (or use <code class="docutils literal notranslate"><span class="pre">evennia</span> <span class="pre">reload</span></code> from the terminal) to have
|
||||
your new python code added to the game. Check your terminal and fix any errors you see - the error
|
||||
|
|
@ -328,14 +329,14 @@ user) to check so the <code class="docutils literal notranslate"><span class="pr
|
|||
<p>If things are not working, make sure your typeclasses and commands are free of bugs and that you
|
||||
have entered the paths to the various command sets and commands correctly. Check the logs or command
|
||||
line for tracebacks and errors.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="combat-system">
|
||||
</section>
|
||||
</section>
|
||||
<section id="combat-system">
|
||||
<h2>Combat System<a class="headerlink" href="#combat-system" title="Permalink to this headline">¶</a></h2>
|
||||
<p>We will add our combat command to the default command set, meaning it will be available to everyone
|
||||
at all times. The combat system consists of a <code class="docutils literal notranslate"><span class="pre">+attack</span></code> command to get how successful our attack is.
|
||||
We also change the default <code class="docutils literal notranslate"><span class="pre">look</span></code> command to display the current combat score.</p>
|
||||
<div class="section" id="attacking-with-the-attack-command">
|
||||
<section id="attacking-with-the-attack-command">
|
||||
<h3>Attacking with the +attack command<a class="headerlink" href="#attacking-with-the-attack-command" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Attacking in this simple system means rolling a random “combat score” influenced by the <code class="docutils literal notranslate"><span class="pre">power</span></code> stat
|
||||
set during Character generation:</p>
|
||||
|
|
@ -344,40 +345,40 @@ You +attack with a combat score of 12!
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>Go back to <code class="docutils literal notranslate"><span class="pre">mygame/commands/command.py</span></code> and add the command to the end like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">random</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">random</span>
|
||||
|
||||
<span class="c1"># ... </span>
|
||||
|
||||
|
|
@ -418,13 +419,13 @@ function. We then store that and echo the result to everyone involved.</p>
|
|||
<p>To make the <code class="docutils literal notranslate"><span class="pre">+attack</span></code> command available to you in game, go back to
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/commands/default_cmdsets.py</span></code> and scroll down to the <code class="docutils literal notranslate"><span class="pre">CharacterCmdSet</span></code> class. At the correct
|
||||
place add this line:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">command</span><span class="o">.</span><span class="n">CmdAttack</span><span class="p">())</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">command</span><span class="o">.</span><span class="n">CmdAttack</span><span class="p">())</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">@reload</span></code> Evennia and the <code class="docutils literal notranslate"><span class="pre">+attack</span></code> command should be available to you. Run it and use e.g. <code class="docutils literal notranslate"><span class="pre">@ex</span></code> to
|
||||
make sure the <code class="docutils literal notranslate"><span class="pre">combat_score</span></code> attribute is saved correctly.</p>
|
||||
</div>
|
||||
<div class="section" id="have-look-show-combat-scores">
|
||||
</section>
|
||||
<section id="have-look-show-combat-scores">
|
||||
<h3>Have “look” show combat scores<a class="headerlink" href="#have-look-show-combat-scores" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Players should be able to view all current combat scores in the room. We could do this by simply
|
||||
adding a second command named something like <code class="docutils literal notranslate"><span class="pre">+combatscores</span></code>, but we will instead let the default
|
||||
|
|
@ -449,30 +450,30 @@ implementation of <code class="docutils literal notranslate"><span class="pre">r
|
|||
<a class="reference external" href="https://github.com/evennia/evennia/blob/master/evennia/objects/objects.py#L1438">here</a>). If you
|
||||
want to make bigger changes you could copy & paste the whole default thing into our overloading
|
||||
method. In our case the change is small though:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Character</span><span class="p">(</span><span class="n">DefaultCharacter</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Character</span><span class="p">(</span><span class="n">DefaultCharacter</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> [...]</span>
|
||||
<span class="sd"> """</span>
|
||||
|
|
@ -509,9 +510,9 @@ of the <code class="docutils literal notranslate"><span class="pre">Room</span><
|
|||
combat scores of all present Characters at the same time as looking at the room. We leave this as an
|
||||
exercise.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="npc-system">
|
||||
</section>
|
||||
</section>
|
||||
<section id="npc-system">
|
||||
<h2>NPC system<a class="headerlink" href="#npc-system" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Here we will re-use the Character class by introducing a command that can create NPC objects. We
|
||||
should also be able to set its Power and order it around.</p>
|
||||
|
|
@ -520,7 +521,7 @@ and put a custom NPC-specific cmdset on all NPCs. This cmdset could hold all man
|
|||
Since we expect NPC manipulation to be a common occurrence among the user base however, we will
|
||||
instead put all relevant NPC commands in the default command set and limit eventual access with
|
||||
<a class="reference external" href="Components/Locks.html#Permissions">Permissions and Locks</a>.</p>
|
||||
<div class="section" id="creating-an-npc-with-createnpc">
|
||||
<section id="creating-an-npc-with-createnpc">
|
||||
<h3>Creating an NPC with +createNPC<a class="headerlink" href="#creating-an-npc-with-createnpc" title="Permalink to this headline">¶</a></h3>
|
||||
<p>We need a command for creating the NPC, this is a very straightforward command:</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="o">+</span><span class="n">createnpc</span> <span class="n">Anna</span>
|
||||
|
|
@ -528,44 +529,44 @@ instead put all relevant NPC commands in the default command set and limit event
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>At the end of <code class="docutils literal notranslate"><span class="pre">command.py</span></code>, create our new command:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">create_object</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">create_object</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">CmdCreateNPC</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -617,8 +618,8 @@ to the <code class="docutils literal notranslate"><span class="pre">create_objec
|
|||
as the Character creating them, this might be a security risk though.</p>
|
||||
<p>Add this command to your default cmdset the same way you did the <code class="docutils literal notranslate"><span class="pre">+attack</span></code> command earlier.
|
||||
<code class="docutils literal notranslate"><span class="pre">@reload</span></code> and it will be available to test.</p>
|
||||
</div>
|
||||
<div class="section" id="editing-the-npc-with-editnpc">
|
||||
</section>
|
||||
<section id="editing-the-npc-with-editnpc">
|
||||
<h3>Editing the NPC with +editNPC<a class="headerlink" href="#editing-the-npc-with-editnpc" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Since we re-used our custom character typeclass, our new NPC already has a <em>Power</em> value - it
|
||||
defaults to 1. How do we change this?</p>
|
||||
|
|
@ -637,78 +638,78 @@ principle re-work our old <code class="docutils literal notranslate"><span class
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>This is a slightly more complex command. It goes at the end of your <code class="docutils literal notranslate"><span class="pre">command.py</span></code> file as before.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69
|
||||
70
|
||||
71
|
||||
72</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CmdEditNPC</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span>
|
||||
<span class="normal">60</span>
|
||||
<span class="normal">61</span>
|
||||
<span class="normal">62</span>
|
||||
<span class="normal">63</span>
|
||||
<span class="normal">64</span>
|
||||
<span class="normal">65</span>
|
||||
<span class="normal">66</span>
|
||||
<span class="normal">67</span>
|
||||
<span class="normal">68</span>
|
||||
<span class="normal">69</span>
|
||||
<span class="normal">70</span>
|
||||
<span class="normal">71</span>
|
||||
<span class="normal">72</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CmdEditNPC</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> edit an existing NPC</span>
|
||||
|
||||
|
|
@ -791,8 +792,8 @@ able to view the properties on the given NPC. It’s up to each game if this is
|
|||
name (the <code class="docutils literal notranslate"><span class="pre">key</span></code> property), you’d need to modify the command since “key” is not an Attribute (it is
|
||||
not retrievable via <code class="docutils literal notranslate"><span class="pre">npc.attributes.get</span></code> but directly via <code class="docutils literal notranslate"><span class="pre">npc.key</span></code>). We leave this as an optional
|
||||
exercise.</em></p>
|
||||
</div>
|
||||
<div class="section" id="making-the-npc-do-stuff-the-npc-command">
|
||||
</section>
|
||||
<section id="making-the-npc-do-stuff-the-npc-command">
|
||||
<h3>Making the NPC do stuff - the +npc command<a class="headerlink" href="#making-the-npc-do-stuff-the-npc-command" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Finally, we will make a command to order our NPC around. For now, we will limit this command to only
|
||||
be usable by those having the “edit” permission on the NPC. This can be changed if it’s possible for
|
||||
|
|
@ -806,43 +807,43 @@ Anna says, 'Hello!'
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>Again, add to the end of your <code class="docutils literal notranslate"><span class="pre">command.py</span></code> module:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CmdNPC</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CmdNPC</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> controls an NPC</span>
|
||||
|
||||
|
|
@ -884,16 +885,16 @@ Anna says, 'Hello!'
|
|||
<p>Note that if you give an erroneous command, you will not see any error message, since that error
|
||||
will be returned to the npc object, not to you. If you want players to see this, you can give the
|
||||
caller’s session ID to the <code class="docutils literal notranslate"><span class="pre">execute_cmd</span></code> call, like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="n">npc</span><span class="o">.</span><span class="n">execute_cmd</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cmdname</span><span class="p">,</span> <span class="n">sessid</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">sessid</span><span class="p">)</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="n">npc</span><span class="o">.</span><span class="n">execute_cmd</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cmdname</span><span class="p">,</span> <span class="n">sessid</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">sessid</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>Another thing to remember is however that this is a very simplistic way to control NPCs. Evennia
|
||||
supports full puppeting very easily. An Account (assuming the “puppet” permission was set correctly)
|
||||
could simply do <code class="docutils literal notranslate"><span class="pre">@ic</span> <span class="pre">mynpc</span></code> and be able to play the game “as” that NPC. This is in fact just what
|
||||
happens when an Account takes control of their normal Character as well.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="concluding-remarks">
|
||||
</section>
|
||||
</section>
|
||||
<section id="concluding-remarks">
|
||||
<h2>Concluding remarks<a class="headerlink" href="#concluding-remarks" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This ends the tutorial. It looks like a lot of text but the amount of code you have to write is
|
||||
actually relatively short. At this point you should have a basic skeleton of a game and a feel for
|
||||
|
|
@ -907,8 +908,8 @@ specific player (or npc) and automatically compare their relevant attributes to
|
|||
<p>To continue from here, you can take a look at the <a class="reference internal" href="../Part1/Tutorial-World-Introduction.html"><span class="doc">Tutorial World</span></a>. For
|
||||
more specific ideas, see the <a class="reference internal" href="../../Howto-Overview.html"><span class="doc">other tutorials and hints</span></a> as well
|
||||
as the <a class="reference internal" href="../../../Components/Components-Overview.html"><span class="doc">Evennia Component overview</span></a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Evennia Starting Tutorial (Part 4) — 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" />
|
||||
|
|
@ -37,9 +38,9 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="evennia-starting-tutorial-part-4">
|
||||
<section id="evennia-starting-tutorial-part-4">
|
||||
<h1>Evennia Starting Tutorial (Part 4)<a class="headerlink" href="#evennia-starting-tutorial-part-4" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Tutorial Parts</p>
|
||||
<dl class="simple">
|
||||
<dt>Part 1: <a class="reference external" href="../Part1/Starting-Part1.html">What we have</a></dt><dd><p>A tour of Evennia and how to use the tools, including an introduction to Python.</p>
|
||||
|
|
@ -53,14 +54,14 @@
|
|||
<dt>Part 5: <a class="reference external" href="../Part5/Starting-Part5.html">Showing the world</a></dt><dd><p>Taking our new game online and let players try it out</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</aside>
|
||||
<p>We now have the code underpinnings of everything we need. We have also tested the various components
|
||||
and has a simple tech-demo to show it all works together. But there is no real coherence to it at this
|
||||
point - we need to actually make a world.
|
||||
In part four we will expand our tech demo into a more full-fledged (if small) game by use of batchcommand
|
||||
and batchcode processors.</p>
|
||||
<p><em>TODO</em></p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Add a simple new web page — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="add-a-simple-new-web-page">
|
||||
<section id="add-a-simple-new-web-page">
|
||||
<h1>Add a simple new web page<a class="headerlink" href="#add-a-simple-new-web-page" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Evennia leverages <a class="reference external" href="https://docs.djangoproject.com">Django</a> which is a web development framework.
|
||||
Huge professional websites are made in Django and there is extensive documentation (and books) on it
|
||||
|
|
@ -47,7 +48,7 @@ introduction for how things hang together, to get you started.</p>
|
|||
box. You can get to that by entering <code class="docutils literal notranslate"><span class="pre">http://localhost:4001</span></code> in your web browser - you should see a
|
||||
welcome page with some game statistics and a link to the web client. Let us add a new page that you
|
||||
can get to by going to <code class="docutils literal notranslate"><span class="pre">http://localhost:4001/story</span></code>.</p>
|
||||
<div class="section" id="create-the-view">
|
||||
<section id="create-the-view">
|
||||
<h2>Create the view<a class="headerlink" href="#create-the-view" title="Permalink to this headline">¶</a></h2>
|
||||
<p>A django “view” is a normal Python function that django calls to render the HTML page you will see
|
||||
in the web browser. Here we will just have it spit back the raw html, but Django can do all sorts of
|
||||
|
|
@ -55,12 +56,12 @@ cool stuff with the page in the view, like adding dynamic content or change it o
|
|||
<code class="docutils literal notranslate"><span class="pre">mygame/web</span></code> folder and add a new module there named <code class="docutils literal notranslate"><span class="pre">story.py</span></code> (you could also put it in its own
|
||||
folder if you wanted to be neat. Don’t forget to add an empty <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code> file if you do, to tell
|
||||
Python you can import from the new folder). Here’s how it looks:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/web/story.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/web/story.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">render</span>
|
||||
|
||||
|
|
@ -70,25 +71,25 @@ Python you can import from the new folder). Here’s how it looks:</p>
|
|||
</td></tr></table></div>
|
||||
<p>This view takes advantage of a shortcut provided to use by Django, <em>render</em>. This shortcut gives the
|
||||
template some information from the request, for instance, the game name, and then renders it.</p>
|
||||
</div>
|
||||
<div class="section" id="the-html-page">
|
||||
</section>
|
||||
<section id="the-html-page">
|
||||
<h2>The HTML page<a class="headerlink" href="#the-html-page" title="Permalink to this headline">¶</a></h2>
|
||||
<p>We need to find a place where Evennia (and Django) looks for html files (called <em>templates</em> in
|
||||
Django parlance). You can specify such places in your settings (see the <code class="docutils literal notranslate"><span class="pre">TEMPLATES</span></code> variable in
|
||||
<code class="docutils literal notranslate"><span class="pre">default_settings.py</span></code> for more info), but here we’ll use an existing one. Go to
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/template/overrides/website/</span></code> and create a page <code class="docutils literal notranslate"><span class="pre">story.html</span></code> there.</p>
|
||||
<p>This is not a HTML tutorial, so we’ll go simple:</p>
|
||||
<div class="highlight-html notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11</pre></div></td><td class="code"><div class="highlight"><pre><span></span>{% extends "base.html" %}
|
||||
<div class="highlight-html notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<span class="p"><</span><span class="nt">div</span> <span class="na">class</span><span class="o">=</span><span class="s">"row"</span><span class="p">></span>
|
||||
<span class="p"><</span><span class="nt">div</span> <span class="na">class</span><span class="o">=</span><span class="s">"col"</span><span class="p">></span>
|
||||
|
|
@ -103,13 +104,13 @@ Django parlance). You can specify such places in your settings (see the <code cl
|
|||
</td></tr></table></div>
|
||||
<p>Since we’ve used the <em>render</em> shortcut, Django will allow us to extend our base styles easily.</p>
|
||||
<p>If you’d rather not take advantage of Evennia’s base styles, you can do something like this instead:</p>
|
||||
<div class="highlight-html notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="p"><</span><span class="nt">html</span><span class="p">></span>
|
||||
<div class="highlight-html notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="p"><</span><span class="nt">html</span><span class="p">></span>
|
||||
<span class="p"><</span><span class="nt">body</span><span class="p">></span>
|
||||
<span class="p"><</span><span class="nt">h1</span><span class="p">></span>A story about a tree<span class="p"></</span><span class="nt">h1</span><span class="p">></span>
|
||||
<span class="p"><</span><span class="nt">p</span><span class="p">></span>
|
||||
|
|
@ -118,8 +119,8 @@ Django parlance). You can specify such places in your settings (see the <code cl
|
|||
<span class="p"></</span><span class="nt">html</span><span class="p">></span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="the-url">
|
||||
</section>
|
||||
<section id="the-url">
|
||||
<h2>The URL<a class="headerlink" href="#the-url" title="Permalink to this headline">¶</a></h2>
|
||||
<p>When you enter the address <code class="docutils literal notranslate"><span class="pre">http://localhost:4001/story</span></code> in your web browser, Django will parse that
|
||||
field to figure out which page you want to go to. You tell it which patterns are relevant in the
|
||||
|
|
@ -129,13 +130,13 @@ Open it now.</p>
|
|||
<p>Django looks for the variable <code class="docutils literal notranslate"><span class="pre">urlpatterns</span></code> in this file. You want to add your new pattern to the
|
||||
<code class="docutils literal notranslate"><span class="pre">custom_patterns</span></code> list we have prepared - that is then merged with the default <code class="docutils literal notranslate"><span class="pre">urlpatterns</span></code>. Here’s
|
||||
how it could look:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">web</span> <span class="kn">import</span> <span class="n">story</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">web</span> <span class="kn">import</span> <span class="n">story</span>
|
||||
|
||||
<span class="c1"># ...</span>
|
||||
|
||||
|
|
@ -149,8 +150,8 @@ instance. The first argument to <code class="docutils literal notranslate"><span
|
|||
a regular expression if you are familiar with those) and then our view function we want to direct
|
||||
to.</p>
|
||||
<p>That should be it. Reload Evennia and you should be able to browse to your new story page!</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Evennia Starting Tutorial (part 5) — 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" />
|
||||
|
|
@ -37,9 +38,9 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="evennia-starting-tutorial-part-5">
|
||||
<section id="evennia-starting-tutorial-part-5">
|
||||
<h1>Evennia Starting Tutorial (part 5)<a class="headerlink" href="#evennia-starting-tutorial-part-5" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="sidebar">
|
||||
<aside class="sidebar">
|
||||
<p class="sidebar-title">Tutorial Parts</p>
|
||||
<dl class="simple">
|
||||
<dt>Part 1: <a class="reference external" href="../Part1/Starting-Part1.html">What we have</a></dt><dd><p>A tour of Evennia and how to use the tools, including an introduction to Python.</p>
|
||||
|
|
@ -53,12 +54,12 @@
|
|||
<dt><strong>Part 5: Showing the world</strong></dt><dd><p>Taking our new game online and let players try it out</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</aside>
|
||||
<p>You have a working game! In part five we will look at the web-components of Evennia and how to modify them
|
||||
to fit your game. We will also look at hosting your game and if you feel up to it we’ll also go through how
|
||||
to bring your game online so you can invite your first players.</p>
|
||||
<p><em>TODO</em></p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Web Tutorial — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="web-tutorial">
|
||||
<section id="web-tutorial">
|
||||
<h1>Web Tutorial<a class="headerlink" href="#web-tutorial" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Evennia uses the <a class="reference external" href="https://www.djangoproject.com/">Django</a> web framework as the basis of both its
|
||||
database configuration and the website it provides. While a full understanding of Django requires
|
||||
|
|
@ -45,7 +46,7 @@ reading the Django documentation, we have provided this tutorial to get you runn
|
|||
and how they pertain to Evennia. This text details getting everything set up. The
|
||||
<a class="reference internal" href="../../Web-Character-View-Tutorial.html"><span class="doc">Web-based Character view Tutorial</span></a> gives a more explicit example of making a
|
||||
custom web page connected to your game, and you may want to read that after finishing this guide.</p>
|
||||
<div class="section" id="a-basic-overview">
|
||||
<section id="a-basic-overview">
|
||||
<h2>A Basic Overview<a class="headerlink" href="#a-basic-overview" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Django is a web framework. It gives you a set of development tools for building a website quickly
|
||||
and easily.</p>
|
||||
|
|
@ -64,8 +65,8 @@ for storing information in the database. We will not change any models here, tak
|
|||
<p>There is also a root <code class="docutils literal notranslate"><span class="pre">urls.py</span></code> that determines the URL structure for the entire project. A starter
|
||||
<code class="docutils literal notranslate"><span class="pre">urls.py</span></code> is included in the default game template, and automatically imports all of Evennia’s
|
||||
default URLs for you. This is located in <code class="docutils literal notranslate"><span class="pre">web/urls.py</span></code>.</p>
|
||||
</div>
|
||||
<div class="section" id="changing-the-logo-on-the-front-page">
|
||||
</section>
|
||||
<section id="changing-the-logo-on-the-front-page">
|
||||
<h2>Changing the logo on the front page<a class="headerlink" href="#changing-the-logo-on-the-front-page" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Evennia’s default logo is a fun little googly-eyed snake wrapped around a gear globe. As cute as it
|
||||
is, it probably doesn’t represent your game. So one of the first things you may wish to do is
|
||||
|
|
@ -113,8 +114,8 @@ overridden files aren’t getting copied over the defaults, try removing the tar
|
|||
everything) in the <code class="docutils literal notranslate"><span class="pre">web/static</span></code> directory, and re-running <code class="docutils literal notranslate"><span class="pre">collectstatic</span></code> to gather everything from
|
||||
scratch.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="changing-the-front-page-s-text">
|
||||
</section>
|
||||
<section id="changing-the-front-page-s-text">
|
||||
<h2>Changing the Front Page’s Text<a class="headerlink" href="#changing-the-front-page-s-text" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The default front page for Evennia contains information about the Evennia project. You’ll probably
|
||||
want to replace this information with information about your own project. Changing the page template
|
||||
|
|
@ -135,16 +136,16 @@ copy our replacement template named <code class="docutils literal notranslate"><
|
|||
web/template_overrides<code class="docutils literal notranslate"><span class="pre">if</span> <span class="pre">it</span> <span class="pre">does</span> <span class="pre">not</span> <span class="pre">exist,</span> <span class="pre">first).</span> <span class="pre">The</span> <span class="pre">final</span> <span class="pre">path</span> <span class="pre">to</span> <span class="pre">the</span> <span class="pre">file</span> <span class="pre">should</span> <span class="pre">thus</span> <span class="pre">be:</span></code>web/template_overrides/website/index.html` within your game directory.</p>
|
||||
<p>Note that it is usually easier to just copy the original template over and edit it in place. The
|
||||
original file already has all the markup and tags, ready for editing.</p>
|
||||
</div>
|
||||
<div class="section" id="further-reading">
|
||||
</section>
|
||||
<section id="further-reading">
|
||||
<h2>Further reading<a class="headerlink" href="#further-reading" title="Permalink to this headline">¶</a></h2>
|
||||
<p>For further hints on working with the web presence, you could now continue to the
|
||||
<a class="reference internal" href="../../Web-Character-View-Tutorial.html"><span class="doc">Web-based Character view Tutorial</span></a> where you learn to make a web page that
|
||||
displays in-game character stats. You can also look at <a class="reference external" href="https://docs.djangoproject.com/en/1.7/intro/tutorial01/">Django’s own
|
||||
tutorial</a> to get more insight in how Django
|
||||
works and what possibilities exist.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Tutorial Aggressive NPCs — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="tutorial-aggressive-npcs">
|
||||
<section id="tutorial-aggressive-npcs">
|
||||
<h1>Tutorial Aggressive NPCs<a class="headerlink" href="#tutorial-aggressive-npcs" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This tutorial shows the implementation of an NPC object that responds to characters entering their
|
||||
location. In this example the NPC has the option to respond aggressively or not, but any actions
|
||||
|
|
@ -55,21 +56,21 @@ the <a class="reference internal" href="Starting/Part3/Tutorial-for-basic-MUSH-l
|
|||
</ul>
|
||||
<p>To begin with, we need to create an NPC typeclass. Create a new file inside of your typeclasses
|
||||
folder and name it <code class="docutils literal notranslate"><span class="pre">npcs.py</span></code> and then add the following code:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typeclasses.characters</span> <span class="kn">import</span> <span class="n">Character</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typeclasses.characters</span> <span class="kn">import</span> <span class="n">Character</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">NPC</span><span class="p">(</span><span class="n">Character</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
|
|
@ -92,21 +93,21 @@ player enters that room. You’ll notice that right now, the NPC merely speaks.
|
|||
part as you like and trigger all sorts of effects here (like combat code, fleeing, bartering or
|
||||
quest-giving) as your game design dictates.</p>
|
||||
<p>Now your <code class="docutils literal notranslate"><span class="pre">typeclasses.rooms</span></code> module needs to have the following added:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># Add this import to the top of your file.</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># Add this import to the top of your file.</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">utils</span>
|
||||
|
||||
<span class="c1"># Add this hook in any empty area within your Room class.</span>
|
||||
|
|
@ -142,14 +143,14 @@ contents and inform any <code class="docutils literal notranslate"><span class="
|
|||
overload. This means that a character entering would see the NPC perform its actions before the
|
||||
‘look’ command. Deactivate the look command in the default <code class="docutils literal notranslate"><span class="pre">Character</span></code> class within the
|
||||
<code class="docutils literal notranslate"><span class="pre">typeclasses.characters</span></code> module:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="c1"># Add this hook in any blank area within your Character class.</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="c1"># Add this hook in any blank area within your Character class.</span>
|
||||
<span class="k">def</span> <span class="nf">at_after_move</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source_location</span><span class="p">):</span>
|
||||
<span class="sd">"""</span>
|
||||
<span class="sd"> Default is to look around after a move </span>
|
||||
|
|
@ -182,7 +183,7 @@ AI code).</p>
|
|||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Orc</span> <span class="n">says</span><span class="p">,</span> <span class="s2">"Graaah, die, Anna!"</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Tutorial NPCs listening — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="tutorial-npcs-listening">
|
||||
<section id="tutorial-npcs-listening">
|
||||
<h1>Tutorial NPCs listening<a class="headerlink" href="#tutorial-npcs-listening" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This tutorial shows the implementation of an NPC object that responds to characters speaking in
|
||||
their location. In this example the NPC parrots what is said, but any actions could be triggered
|
||||
|
|
@ -45,25 +46,25 @@ this way.</p>
|
|||
<p>It is assumed that you already know how to create custom room and character typeclasses, please see
|
||||
the <a class="reference internal" href="Starting/Part3/Tutorial-for-basic-MUSH-like-game.html"><span class="doc">Basic Game tutorial</span></a> if you haven’t already done this.</p>
|
||||
<p>What we will need is simply a new NPC typeclass that can react when someone speaks.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/npc.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/npc.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">characters</span> <span class="kn">import</span> <span class="n">Character</span>
|
||||
<span class="k">class</span> <span class="nc">Npc</span><span class="p">(</span><span class="n">Character</span><span class="p">):</span>
|
||||
|
|
@ -86,34 +87,34 @@ the <a class="reference internal" href="Starting/Part3/Tutorial-for-basic-MUSH-l
|
|||
</td></tr></table></div>
|
||||
<p>When someone in the room speaks to this NPC, its <code class="docutils literal notranslate"><span class="pre">msg</span></code> method will be called. We will modify the
|
||||
NPCs <code class="docutils literal notranslate"><span class="pre">.msg</span></code> method to catch says so the NPC can respond.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/npc.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/typeclasses/npc.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">characters</span> <span class="kn">import</span> <span class="n">Character</span>
|
||||
<span class="k">class</span> <span class="nc">Npc</span><span class="p">(</span><span class="n">Character</span><span class="p">):</span>
|
||||
|
|
@ -173,7 +174,7 @@ folder automatically so this is a little shorter).</p>
|
|||
<span class="n">Guild</span> <span class="n">Master</span> <span class="n">says</span><span class="p">,</span> <span class="s2">"Anna said: 'hi'"</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="section" id="assorted-notes">
|
||||
<section id="assorted-notes">
|
||||
<h2>Assorted notes<a class="headerlink" href="#assorted-notes" title="Permalink to this headline">¶</a></h2>
|
||||
<p>There are many ways to implement this kind of functionality. An alternative example to overriding
|
||||
<code class="docutils literal notranslate"><span class="pre">msg</span></code> would be to modify the <code class="docutils literal notranslate"><span class="pre">at_say</span></code> hook on the <em>Character</em> instead. It could detect that it’s
|
||||
|
|
@ -181,8 +182,8 @@ sending to an NPC and call the <code class="docutils literal notranslate"><span
|
|||
<p>While the tutorial solution has the advantage of being contained only within the NPC class,
|
||||
combining this with using the Character class gives more direct control over how the NPC will react.
|
||||
Which way to go depends on the design requirements of your particular game.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Tutorial Tweeting Game Stats — 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" />
|
||||
|
|
@ -37,80 +38,80 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="tutorial-tweeting-game-stats">
|
||||
<section id="tutorial-tweeting-game-stats">
|
||||
<h1>Tutorial Tweeting Game Stats<a class="headerlink" href="#tutorial-tweeting-game-stats" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This tutorial will create a simple script that will send a tweet to your already configured twitter
|
||||
account. Please see: <a class="reference internal" href="../Setup/How-to-connect-Evennia-to-Twitter.html"><span class="doc">How to connect Evennia to Twitter</span></a> if you
|
||||
haven’t already done so.</p>
|
||||
<p>The script could be expanded to cover a variety of statistics you might wish to tweet about
|
||||
regularly, from player deaths to how much currency is in the economy etc.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># evennia/typeclasses/tweet_stats.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span>
|
||||
<span class="normal">60</span>
|
||||
<span class="normal">61</span>
|
||||
<span class="normal">62</span>
|
||||
<span class="normal">63</span>
|
||||
<span class="normal">64</span>
|
||||
<span class="normal">65</span>
|
||||
<span class="normal">66</span>
|
||||
<span class="normal">67</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># evennia/typeclasses/tweet_stats.py</span>
|
||||
|
||||
<span class="kn">import</span> <span class="nn">twitter</span>
|
||||
<span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">randint</span>
|
||||
|
|
@ -195,7 +196,7 @@ as <code class="docutils literal notranslate"><span class="pre">mygame/typeclass
|
|||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@script</span> <span class="n">Here</span> <span class="o">=</span> <span class="n">tweet_stats</span><span class="o">.</span><span class="n">TweetStats</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Tutorial Vehicles — 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" />
|
||||
|
|
@ -37,32 +38,32 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="tutorial-vehicles">
|
||||
<section id="tutorial-vehicles">
|
||||
<h1>Tutorial Vehicles<a class="headerlink" href="#tutorial-vehicles" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This tutorial explains how you can create vehicles that can move around in your world. The tutorial
|
||||
will explain how to create a train, but this can be equally applied to create other kind of vehicles
|
||||
(cars, planes, boats, spaceships, submarines, …).</p>
|
||||
<div class="section" id="how-it-works">
|
||||
<section id="how-it-works">
|
||||
<h2>How it works<a class="headerlink" href="#how-it-works" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Objects in Evennia have an interesting property: you can put any object inside another object. This
|
||||
is most obvious in rooms: a room in Evennia is just like any other game object (except rooms tend to
|
||||
not themselves be inside anything else).</p>
|
||||
<p>Our train will be similar: it will be an object that other objects can get inside. We then simply
|
||||
move the Train, which brings along everyone inside it.</p>
|
||||
</div>
|
||||
<div class="section" id="creating-our-train-object">
|
||||
</section>
|
||||
<section id="creating-our-train-object">
|
||||
<h2>Creating our train object<a class="headerlink" href="#creating-our-train-object" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The first step we need to do is create our train object, including a new typeclass. To do this,
|
||||
create a new file, for instance in <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/train.py</span></code> with the following content:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/typeclasses/train.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/typeclasses/train.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultObject</span>
|
||||
|
||||
|
|
@ -83,8 +84,8 @@ and back (assuming we created it in limbo).</p>
|
|||
<span class="nd">@tel</span> <span class="n">limbo</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="entering-and-leaving-the-train">
|
||||
</section>
|
||||
<section id="entering-and-leaving-the-train">
|
||||
<h2>Entering and leaving the train<a class="headerlink" href="#entering-and-leaving-the-train" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Using the <code class="docutils literal notranslate"><span class="pre">@tel</span></code>command like shown above is obviously not what we want. <code class="docutils literal notranslate"><span class="pre">@tel</span></code> is an admin command
|
||||
and normal players will thus never be able to enter the train! It is also not really a good idea to
|
||||
|
|
@ -99,56 +100,56 @@ solution.</p>
|
|||
another for leaving it again. These will be stored <em>on the train object</em> and will thus be made
|
||||
available to whomever is either inside it or in the same room as the train.</p>
|
||||
<p>Let’s create a new command module as <code class="docutils literal notranslate"><span class="pre">mygame/commands/train.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/commands/train.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># mygame/commands/train.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span><span class="p">,</span> <span class="n">CmdSet</span>
|
||||
|
||||
|
|
@ -207,15 +208,15 @@ player to inside the train and <code class="docutils literal notranslate"><span
|
|||
current location of the train (back outside to its current location). We stacked them in a
|
||||
<a class="reference internal" href="../Components/Command-Sets.html"><span class="doc">cmdset</span></a> <code class="docutils literal notranslate"><span class="pre">CmdSetTrain</span></code> so they can be used.</p>
|
||||
<p>To make the commands work we need to add this cmdset to our train typeclass:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/typeclasses/train.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/typeclasses/train.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultObject</span>
|
||||
<span class="kn">from</span> <span class="nn">commands.train</span> <span class="kn">import</span> <span class="n">CmdSetTrain</span>
|
||||
|
|
@ -238,8 +239,8 @@ and leave the train:</p>
|
|||
object the same typeclass we already have. The <code class="docutils literal notranslate"><span class="pre">/reset</span></code> re-triggers the typeclass’
|
||||
<code class="docutils literal notranslate"><span class="pre">at_object_creation()</span></code> hook (which is otherwise only called the very first an instance is created).
|
||||
As seen above, when this hook is called on our train, our new cmdset will be loaded.</p>
|
||||
</div>
|
||||
<div class="section" id="locking-down-the-commands">
|
||||
</section>
|
||||
<section id="locking-down-the-commands">
|
||||
<h2>Locking down the commands<a class="headerlink" href="#locking-down-the-commands" title="Permalink to this headline">¶</a></h2>
|
||||
<p>If you have played around a bit, you’ve probably figured out that you can use <code class="docutils literal notranslate"><span class="pre">leave</span> <span class="pre">train</span></code> when
|
||||
outside the train and <code class="docutils literal notranslate"><span class="pre">enter</span> <span class="pre">train</span></code> when inside. This doesn’t make any sense … so let’s go ahead
|
||||
|
|
@ -253,16 +254,16 @@ player and <em>only</em> allow access if they are inside the train.</p>
|
|||
<p>First of all we need to create a new lock function. Evennia comes with many lock functions built-in
|
||||
already, but none that we can use for locking a command in this particular case. Create a new entry
|
||||
in <code class="docutils literal notranslate"><span class="pre">mygame/server/conf/lockfuncs.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="c1"># file mygame/server/conf/lockfuncs.py</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">cmdinside</span><span class="p">(</span><span class="n">accessing_obj</span><span class="p">,</span> <span class="n">accessed_obj</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>
|
||||
|
|
@ -286,17 +287,17 @@ train.</p>
|
|||
it is, it means the player is inside the train. Otherwise it means the player is somewhere else and
|
||||
the check will fail.</p>
|
||||
<p>The next step is to actually use this new lock function to create a lock of type <code class="docutils literal notranslate"><span class="pre">cmd</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file commands/train.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file commands/train.py</span>
|
||||
<span class="o">...</span>
|
||||
<span class="k">class</span> <span class="nc">CmdEnterTrain</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||||
<span class="n">key</span> <span class="o">=</span> <span class="s2">"enter train"</span>
|
||||
|
|
@ -316,8 +317,8 @@ should be locked down appropriately and you should only be able to use them at t
|
|||
<div><p>Note: If you’re logged in as the super user (user <code class="docutils literal notranslate"><span class="pre">#1</span></code>) then this lock will not work: the super
|
||||
user ignores lock functions. In order to use this functionality you need to <code class="docutils literal notranslate"><span class="pre">@quell</span></code> first.</p>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="making-our-train-move">
|
||||
</section>
|
||||
<section id="making-our-train-move">
|
||||
<h2>Making our train move<a class="headerlink" href="#making-our-train-move" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Now that we can enter and leave the train correctly, it’s time to make it move. There are different
|
||||
things we need to consider for this:</p>
|
||||
|
|
@ -347,42 +348,42 @@ and leave it.</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>Next we will tell the train how to move and which route to take.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file typeclasses/train.py</span>
|
||||
<div class="highlight-python notranslate"><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 class="highlight"><pre><span></span><span class="c1"># file typeclasses/train.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultObject</span><span class="p">,</span> <span class="n">search_object</span>
|
||||
|
||||
|
|
@ -434,8 +435,8 @@ moves the train to the next room in the list. Or makes it stop driving if it rea
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>You should see the train moving forward one step along the rail road.</p>
|
||||
</div>
|
||||
<div class="section" id="adding-in-scripts">
|
||||
</section>
|
||||
<section id="adding-in-scripts">
|
||||
<h2>Adding in scripts<a class="headerlink" href="#adding-in-scripts" title="Permalink to this headline">¶</a></h2>
|
||||
<p>If we wanted full control of the train we could now just add a command to step it along the track
|
||||
when desired. We want the train to move on its own though, without us having to force it by manually
|
||||
|
|
@ -444,44 +445,44 @@ calling the <code class="docutils literal notranslate"><span class="pre">goto_ne
|
|||
a station and is responsible for starting the train again after a while. The other script will take
|
||||
care of the driving.</p>
|
||||
<p>Let’s make a new file in <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/trainscript.py</span></code></p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/typeclasses/trainscript.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/typeclasses/trainscript.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultScript</span>
|
||||
|
||||
|
|
@ -526,15 +527,15 @@ starts again. When the train is driving, it moves to the next room every second.
|
|||
in one of those two states - both scripts take care of adding the other one once they are done.</p>
|
||||
<p>As a last step we need to link the stopped-state script to our train, reload the game and reset our
|
||||
train again., and we’re ready to ride it around!</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file typeclasses/train.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file typeclasses/train.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">typeclasses.trainscript</span> <span class="kn">import</span> <span class="n">TrainStoppedScript</span>
|
||||
|
||||
|
|
@ -561,8 +562,8 @@ train again., and we’re ready to ride it around!</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
<p>Our train will stop 30 seconds at each end station and then turn around to go back to the other end.</p>
|
||||
</div>
|
||||
<div class="section" id="expanding">
|
||||
</section>
|
||||
<section id="expanding">
|
||||
<h2>Expanding<a class="headerlink" href="#expanding" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This train is very basic and still has some flaws. Some more things to do:</p>
|
||||
<ul class="simple">
|
||||
|
|
@ -577,8 +578,8 @@ track. Some track segments can split to lead to two different rooms and a player
|
|||
direction to which room it goes.</p></li>
|
||||
<li><p>Create another kind of vehicle!</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Understanding Color Tags — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="understanding-color-tags">
|
||||
<section id="understanding-color-tags">
|
||||
<h1>Understanding Color Tags<a class="headerlink" href="#understanding-color-tags" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This tutorial aims at dispelling confusions regarding the use of color tags within Evennia.</p>
|
||||
<p>Correct understanding of this topic requires having read the <a class="reference internal" href="../Concepts/TextTags.html"><span class="doc">TextTags</span></a> page and learned
|
||||
|
|
@ -46,8 +47,8 @@ apparently incoherent) behaviors of some color tags, as mentioned <em>en passant
|
|||
<a class="reference internal" href="../Concepts/TextTags.html"><span class="doc">TextTags</span></a> page.</p>
|
||||
<p>All you’ll need for this tutorial is access to a running instance of Evennia via a color-enabled
|
||||
client. The examples provided are just commands that you can type in your client.</p>
|
||||
</div>
|
||||
<div class="section" id="evennia-ansi-and-xterm256">
|
||||
</section>
|
||||
<section id="evennia-ansi-and-xterm256">
|
||||
<h1>Evennia, ANSI and Xterm256<a class="headerlink" href="#evennia-ansi-and-xterm256" title="Permalink to this headline">¶</a></h1>
|
||||
<p>All modern MUD clients support colors; nevertheless, the standards to which all clients abide dates
|
||||
back to old day of terminals, and when it comes to colors we are dealing with ANSI and Xterm256
|
||||
|
|
@ -63,8 +64,8 @@ generated text, etc.</p>
|
|||
pitfalls. ANSI and Xterm256 coexist without conflicts in Evennia, but in many ways they don’t «see»
|
||||
each other: ANSI-specific color tags will have no effect on Xterm-defined colors, as we shall see
|
||||
here.</p>
|
||||
</div>
|
||||
<div class="section" id="ansi">
|
||||
</section>
|
||||
<section id="ansi">
|
||||
<h1>ANSI<a class="headerlink" href="#ansi" title="Permalink to this headline">¶</a></h1>
|
||||
<p>ANSI has a set of 16 colors, to be more precise: ANSI has 8 basic colors which come in <em>dark</em> and
|
||||
<em>bright</em> flavours—with <em>dark</em> being <em>normal</em>. The colors are: red, green, yellow, blue, magenta,
|
||||
|
|
@ -78,16 +79,16 @@ behavior of ANSI tags, as we shall see.</p>
|
|||
<p>Also, it’s important to remember that the 16 ANSI colors are a convention, and the final user can
|
||||
always customize their appearance—he might decide to have green show as red, and dark green as blue,
|
||||
etc.</p>
|
||||
</div>
|
||||
<div class="section" id="xterm256">
|
||||
</section>
|
||||
<section id="xterm256">
|
||||
<h1>Xterm256<a class="headerlink" href="#xterm256" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The 16 colors of ANSI should be more than enough to handle simple coloring of text. But when an
|
||||
author wants to be sure that a given color will show as he intended it, she might choose to rely on
|
||||
Xterm256 colors.</p>
|
||||
<p>Xterm256 doesn’t rely on a palette of named colors, it instead represent colors by their values. So,
|
||||
a red color could be <code class="docutils literal notranslate"><span class="pre">|[500</span></code> (bright and pure red), or <code class="docutils literal notranslate"><span class="pre">|[300</span></code> (darker red), and so on.</p>
|
||||
</div>
|
||||
<div class="section" id="ansi-color-tags-in-evennia">
|
||||
</section>
|
||||
<section id="ansi-color-tags-in-evennia">
|
||||
<h1>ANSI Color Tags in Evennia<a class="headerlink" href="#ansi-color-tags-in-evennia" title="Permalink to this headline">¶</a></h1>
|
||||
<blockquote>
|
||||
<div><p>NOTE: for ease of reading, the examples contain extra white spaces after the
|
||||
|
|
@ -197,7 +198,7 @@ it is meant to work.</p>
|
|||
<p>ANSI operates according to a simple states-based mechanism, and it’s important to understand the
|
||||
positive effect of resetting with the <code class="docutils literal notranslate"><span class="pre">|n</span></code> tag, and not try to
|
||||
push it over the limit, so to speak.</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Weather Tutorial — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="weather-tutorial">
|
||||
<section id="weather-tutorial">
|
||||
<h1>Weather Tutorial<a class="headerlink" href="#weather-tutorial" title="Permalink to this headline">¶</a></h1>
|
||||
<p>This tutorial will have us create a simple weather system for our MUD. The way we want to use this
|
||||
is to have all outdoor rooms echo weather-related messages to the room at regular and semi-random
|
||||
|
|
@ -52,27 +53,27 @@ computing overhead.</p>
|
|||
will use it for our weather system.</p>
|
||||
<p>We will assume you know how to make your own Typeclasses. If not see one of the beginning tutorials.
|
||||
We will create a new WeatherRoom typeclass that is aware of the day-night cycle.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21</pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>
|
||||
<span class="kn">import</span> <span class="nn">random</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultRoom</span><span class="p">,</span> <span class="n">TICKER_HANDLER</span>
|
||||
|
||||
|
|
@ -103,7 +104,7 @@ call sign required by TickerHandler hooks.</p>
|
|||
<p>Henceforth the room will inform everyone inside it when the weather changes. This particular example
|
||||
is of course very simplistic - the weather echoes are just randomly chosen and don’t care what
|
||||
weather came before it. Expanding it to be more realistic is a useful exercise.</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Web Character Generation — 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" />
|
||||
|
|
@ -37,9 +38,9 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="web-character-generation">
|
||||
<section id="web-character-generation">
|
||||
<h1>Web Character Generation<a class="headerlink" href="#web-character-generation" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="section" id="introduction">
|
||||
<section id="introduction">
|
||||
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This tutorial will create a simple web-based interface for generating a new in-game Character.
|
||||
Accounts will need to have first logged into the website (with their <code class="docutils literal notranslate"><span class="pre">AccountDB</span></code> account). Once
|
||||
|
|
@ -57,8 +58,8 @@ at the <a class="reference external" href="https://docs.djangoproject.com/en/1.8
|
|||
does, before throwing Evennia into the mix (Evennia shares its API and attributes with the website
|
||||
interface). This guide will outline the format of the models, views, urls, and html templates
|
||||
needed.</p>
|
||||
</div>
|
||||
<div class="section" id="pictures">
|
||||
</section>
|
||||
<section id="pictures">
|
||||
<h2>Pictures<a class="headerlink" href="#pictures" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Here are some screenshots of the simple app we will be making.</p>
|
||||
<p>Index page, with no character application yet done:</p>
|
||||
|
|
@ -79,9 +80,9 @@ you see it listed:</p>
|
|||
<em>detail</em> page:</p>
|
||||
<hr class="docutils" />
|
||||
<p><img alt="Detail view of character application." src="https://lh6.googleusercontent.com/-2m1UhSE7s_k/VWcUKfLRfII/AAAAAAAAEZc/UFmBOqVya4k/w267-h175-no/webchargen_detail.gif" /></p>
|
||||
</div>
|
||||
</section>
|
||||
<hr class="docutils" />
|
||||
<div class="section" id="installing-an-app">
|
||||
<section id="installing-an-app">
|
||||
<h2>Installing an App<a class="headerlink" href="#installing-an-app" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Assuming your game is named “mygame”, navigate to your <code class="docutils literal notranslate"><span class="pre">mygame/</span></code> directory, and type:</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">evennia</span> <span class="n">startapp</span> <span class="n">chargen</span>
|
||||
|
|
@ -99,15 +100,15 @@ Evennia (and Django) aware of our new app:</p>
|
|||
<p>After this, we will get into defining our <em>models</em> (the description of the database storage),
|
||||
<em>views</em> (the server-side website content generators), <em>urls</em> (how the web browser finds the pages)
|
||||
and <em>templates</em> (how the web page should be structured).</p>
|
||||
<div class="section" id="installing-checkpoint">
|
||||
<section id="installing-checkpoint">
|
||||
<h3>Installing - Checkpoint:<a class="headerlink" href="#installing-checkpoint" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>you should have a folder named <code class="docutils literal notranslate"><span class="pre">chargen</span></code> or whatever you chose in your mygame/web/ directory</p></li>
|
||||
<li><p>you should have your application name added to your INSTALLED_APPS in settings.py</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="create-models">
|
||||
</section>
|
||||
</section>
|
||||
<section id="create-models">
|
||||
<h2>Create Models<a class="headerlink" href="#create-models" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Models are created in <code class="docutils literal notranslate"><span class="pre">mygame/web/chargen/models.py</span></code>.</p>
|
||||
<p>A <a class="reference internal" href="../Concepts/New-Models.html"><span class="doc">Django database model</span></a> is a Python class that describes the database storage of the
|
||||
|
|
@ -129,17 +130,17 @@ AccountID from the AccountDB object.</p></li>
|
|||
attributes and so on.</p>
|
||||
</div></blockquote>
|
||||
<p>Our <code class="docutils literal notranslate"><span class="pre">models.py</span></code> file should look something like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/web/chargen/models.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/web/chargen/models.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
|
||||
|
||||
|
|
@ -158,15 +159,15 @@ which characters are owned by which accounts. Since the account id is a primary
|
|||
is a good candidate, as you will never have two of the same IDs in Evennia. You can feel free to use
|
||||
anything else, but for the purposes of this guide, we are going to use account ID to join the
|
||||
character applications with the proper account.</p>
|
||||
<div class="section" id="model-checkpoint">
|
||||
<section id="model-checkpoint">
|
||||
<h3>Model - Checkpoint:<a class="headerlink" href="#model-checkpoint" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>you should have filled out <code class="docutils literal notranslate"><span class="pre">mygame/web/chargen/models.py</span></code> with the model class shown above
|
||||
(eventually adding fields matching what you need for your game).</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="create-views">
|
||||
</section>
|
||||
</section>
|
||||
<section id="create-views">
|
||||
<h2>Create Views<a class="headerlink" href="#create-views" title="Permalink to this headline">¶</a></h2>
|
||||
<p><em>Views</em> are server-side constructs that make dynamic data available to a web page. We are going to
|
||||
add them to <code class="docutils literal notranslate"><span class="pre">mygame/web/chargen.views.py</span></code>. Each view in our example represents the backbone of a
|
||||
|
|
@ -178,22 +179,22 @@ specific web page. We will use three views and three pages here:</p>
|
|||
given Character.</p></li>
|
||||
<li><p>Character creation sheet (manages <code class="docutils literal notranslate"><span class="pre">create.html</span></code>). This is the main form with fields to fill in.</p></li>
|
||||
</ul>
|
||||
<div class="section" id="index-view">
|
||||
<section id="index-view">
|
||||
<h3><em>Index</em> view<a class="headerlink" href="#index-view" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Let’s get started with the index first.</p>
|
||||
<p>We’ll want characters to be able to see their created characters so let’s</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/web/chargen.views.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/web/chargen.views.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">.models</span> <span class="kn">import</span> <span class="n">CharApp</span>
|
||||
|
||||
|
|
@ -207,8 +208,8 @@ given Character.</p></li>
|
|||
<span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s1">'chargen/index.html'</span><span class="p">,</span> <span class="n">context</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="detail-view">
|
||||
</section>
|
||||
<section id="detail-view">
|
||||
<h3><em>Detail</em> view<a class="headerlink" href="#detail-view" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Our detail page will have pertinent character application information our users can see. Since this
|
||||
is a basic demonstration, our detail page will only show two fields:</p>
|
||||
|
|
@ -218,17 +219,17 @@ is a basic demonstration, our detail page will only show two fields:</p>
|
|||
</ul>
|
||||
<p>We will use the account ID again just to double-check that whoever tries to check our character page
|
||||
is actually the account who owns the application.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/web/chargen.views.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/web/chargen.views.py</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">detail</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">app_id</span><span class="p">):</span>
|
||||
<span class="n">app</span> <span class="o">=</span> <span class="n">CharApp</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">app_id</span><span class="o">=</span><span class="n">app_id</span><span class="p">)</span>
|
||||
|
|
@ -241,22 +242,22 @@ is actually the account who owns the application.</p>
|
|||
<span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s1">'chargen/detail.html'</span><span class="p">,</span> <span class="n">context</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="creating-view">
|
||||
</section>
|
||||
</section>
|
||||
<section id="creating-view">
|
||||
<h2><em>Creating</em> view<a class="headerlink" href="#creating-view" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Predictably, our <em>create</em> function will be the most complicated of the views, as it needs to accept
|
||||
information from the user, validate the information, and send the information to the server. Once
|
||||
the form content is validated will actually create a playable Character.</p>
|
||||
<p>The form itself we will define first. In our simple example we are just looking for the Character’s
|
||||
name and background. This form we create in <code class="docutils literal notranslate"><span class="pre">mygame/web/chargen/forms.py</span></code>:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/web/chargen/forms.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/web/chargen/forms.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>
|
||||
|
||||
|
|
@ -266,50 +267,50 @@ name and background. This form we create in <code class="docutils literal notran
|
|||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>Now we make use of this form in our view.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/web/chargen/views.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/web/chargen/views.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">web.chargen.models</span> <span class="kn">import</span> <span class="n">CharApp</span>
|
||||
<span class="kn">from</span> <span class="nn">web.chargen.forms</span> <span class="kn">import</span> <span class="n">AppForm</span>
|
||||
|
|
@ -374,69 +375,69 @@ character. It may be a good idea to decompose this function and create a separat
|
|||
function in order to set up your character object the account owns. But with the Evennia API,
|
||||
setting custom attributes is as easy as doing it in the meat of your Evennia game directory.</p>
|
||||
<p>After all of this, our <code class="docutils literal notranslate"><span class="pre">views.py</span></code> file should look like something like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/web/chargen/views.py</span>
|
||||
<div class="highlight-python notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span>
|
||||
<span class="normal">47</span>
|
||||
<span class="normal">48</span>
|
||||
<span class="normal">49</span>
|
||||
<span class="normal">50</span>
|
||||
<span class="normal">51</span>
|
||||
<span class="normal">52</span>
|
||||
<span class="normal">53</span>
|
||||
<span class="normal">54</span>
|
||||
<span class="normal">55</span>
|
||||
<span class="normal">56</span>
|
||||
<span class="normal">57</span>
|
||||
<span class="normal">58</span>
|
||||
<span class="normal">59</span>
|
||||
<span class="normal">60</span>
|
||||
<span class="normal">61</span>
|
||||
<span class="normal">62</span>
|
||||
<span class="normal">63</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/web/chargen/views.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">render</span>
|
||||
<span class="kn">from</span> <span class="nn">web.chargen.models</span> <span class="kn">import</span> <span class="n">CharApp</span>
|
||||
|
|
@ -501,7 +502,7 @@ setting custom attributes is as easy as doing it in the meat of your Evennia gam
|
|||
<span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s1">'chargen/create.html'</span><span class="p">,</span> <span class="p">{</span><span class="s1">'form'</span><span class="p">:</span> <span class="n">form</span><span class="p">})</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="section" id="create-views-checkpoint">
|
||||
<section id="create-views-checkpoint">
|
||||
<h3>Create Views - Checkpoint:<a class="headerlink" href="#create-views-checkpoint" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>you’ve defined a <code class="docutils literal notranslate"><span class="pre">views.py</span></code> that has an index, detail, and creating functions.</p></li>
|
||||
|
|
@ -509,25 +510,25 @@ setting custom attributes is as easy as doing it in the meat of your Evennia gam
|
|||
<code class="docutils literal notranslate"><span class="pre">views.py</span></code>.</p></li>
|
||||
<li><p>your <code class="docutils literal notranslate"><span class="pre">mygame/web/chargen</span></code> directory should now have a <code class="docutils literal notranslate"><span class="pre">views.py</span></code> and <code class="docutils literal notranslate"><span class="pre">forms.py</span></code> file</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="create-urls">
|
||||
</section>
|
||||
</section>
|
||||
<section id="create-urls">
|
||||
<h2>Create URLs<a class="headerlink" href="#create-urls" title="Permalink to this headline">¶</a></h2>
|
||||
<p>URL patterns helps redirect requests from the web browser to the right views. These patterns are
|
||||
created in <code class="docutils literal notranslate"><span class="pre">mygame/web/chargen/urls.py</span></code>.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/web/chargen/urls.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># file mygame/web/chargen/urls.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">url</span>
|
||||
<span class="kn">from</span> <span class="nn">web.chargen</span> <span class="kn">import</span> <span class="n">views</span>
|
||||
|
|
@ -548,24 +549,24 @@ account_id to find all the character application objects to display.</p>
|
|||
<p>We must also update the main <code class="docutils literal notranslate"><span class="pre">mygame/web/urls.py</span></code> file (that is, one level up from our chargen app),
|
||||
so the main website knows where our app’s views are located. Find the <code class="docutils literal notranslate"><span class="pre">patterns</span></code> variable, and
|
||||
change it to include:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in file mygame/web/urls.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in file mygame/web/urls.py</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">url</span><span class="p">,</span> <span class="n">include</span>
|
||||
|
||||
|
|
@ -585,15 +586,15 @@ change it to include:</p>
|
|||
<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">custom_patterns</span> <span class="o">+</span> <span class="n">urlpatterns</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<div class="section" id="urls-checkpoint">
|
||||
<section id="urls-checkpoint">
|
||||
<h3>URLs - Checkpoint:<a class="headerlink" href="#urls-checkpoint" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>You’ve created a urls.py file in the <code class="docutils literal notranslate"><span class="pre">mygame/web/chargen</span></code> directory</p></li>
|
||||
<li><p>You have edited the main <code class="docutils literal notranslate"><span class="pre">mygame/web/urls.py</span></code> file to include urls to the <code class="docutils literal notranslate"><span class="pre">chargen</span></code> directory.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="html-templates">
|
||||
</section>
|
||||
</section>
|
||||
<section id="html-templates">
|
||||
<h2>HTML Templates<a class="headerlink" href="#html-templates" title="Permalink to this headline">¶</a></h2>
|
||||
<p>So we have our url patterns, views, and models defined. Now we must define our HTML templates that
|
||||
the actual user will see and interact with. For this tutorial we us the basic <em>prosimii</em> template
|
||||
|
|
@ -601,32 +602,32 @@ that comes with Evennia.</p>
|
|||
<p>Take note that we use <code class="docutils literal notranslate"><span class="pre">user.is_authenticated</span></code> to make sure that the user cannot create a character
|
||||
without logging in.</p>
|
||||
<p>These files will all go into the <code class="docutils literal notranslate"><span class="pre">/mygame/web/chargen/templates/chargen/</span></code> directory.</p>
|
||||
<div class="section" id="index-html">
|
||||
<section id="index-html">
|
||||
<h3>index.html<a class="headerlink" href="#index-html" title="Permalink to this headline">¶</a></h3>
|
||||
<p>This HTML template should hold a list of all the applications the account currently has active. For
|
||||
this demonstration, we will only list the applications that the account has submitted. You could
|
||||
easily adjust this to include saved applications, or other types of applications if you have
|
||||
different kinds.</p>
|
||||
<p>Please refer back to <code class="docutils literal notranslate"><span class="pre">views.py</span></code> to see where we define the variables these templates make use of.</p>
|
||||
<div class="highlight-html notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c"><!-- file mygame/web/chargen/templates/chargen/index.html--></span>
|
||||
<div class="highlight-html notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c"><!-- file mygame/web/chargen/templates/chargen/index.html--></span>
|
||||
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
|
|
@ -647,31 +648,31 @@ different kinds.</p>
|
|||
{% endblock %}
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="detail-html">
|
||||
</section>
|
||||
<section id="detail-html">
|
||||
<h3>detail.html<a class="headerlink" href="#detail-html" title="Permalink to this headline">¶</a></h3>
|
||||
<p>This page should show a detailed character sheet of their application. This will only show their
|
||||
name and character background. You will likely want to extend this to show many more fields for your
|
||||
game. In a full-fledged character generation, you may want to extend the boolean attribute of
|
||||
submitted to allow accounts to save character applications and submit them later.</p>
|
||||
<div class="highlight-html notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c"><!-- file mygame/web/chargen/templates/chargen/detail.html--></span>
|
||||
<div class="highlight-html notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c"><!-- file mygame/web/chargen/templates/chargen/detail.html--></span>
|
||||
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
|
|
@ -691,29 +692,29 @@ submitted to allow accounts to save character applications and submit them later
|
|||
{% endblock %}
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="create-html">
|
||||
</section>
|
||||
<section id="create-html">
|
||||
<h3>create.html<a class="headerlink" href="#create-html" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Our create HTML template will use the Django form we defined back in views.py/forms.py to drive the
|
||||
majority of the application process. There will be a form input for every field we defined in
|
||||
forms.py, which is handy. We have used POST as our method because we are sending information to the
|
||||
server that will update the database. As an alternative, GET would be much less secure. You can read
|
||||
up on documentation elsewhere on the web for GET vs. POST.</p>
|
||||
<div class="highlight-html notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c"><!-- file mygame/web/chargen/templates/chargen/create.html--></span>
|
||||
<div class="highlight-html notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c"><!-- file mygame/web/chargen/templates/chargen/create.html--></span>
|
||||
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
|
|
@ -730,25 +731,25 @@ up on documentation elsewhere on the web for GET vs. POST.</p>
|
|||
{% endblock %}
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="templates-checkpoint">
|
||||
</section>
|
||||
<section id="templates-checkpoint">
|
||||
<h3>Templates - Checkpoint:<a class="headerlink" href="#templates-checkpoint" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>Create a <code class="docutils literal notranslate"><span class="pre">index.html</span></code>, <code class="docutils literal notranslate"><span class="pre">detail.html</span></code> and <code class="docutils literal notranslate"><span class="pre">create.html</span></code> template in your
|
||||
<code class="docutils literal notranslate"><span class="pre">mygame/web/chargen/templates/chargen</span></code> directory</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="activating-your-new-character-generation">
|
||||
</section>
|
||||
</section>
|
||||
<section id="activating-your-new-character-generation">
|
||||
<h2>Activating your new character generation<a class="headerlink" href="#activating-your-new-character-generation" title="Permalink to this headline">¶</a></h2>
|
||||
<p>After finishing this tutorial you should have edited or created the following files:</p>
|
||||
<div class="highlight-bash notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span>mygame/web/urls.py
|
||||
<div class="highlight-bash notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>mygame/web/urls.py
|
||||
mygame/web/chargen/models.py
|
||||
mygame/web/chargen/views.py
|
||||
mygame/web/chargen/urls.py
|
||||
|
|
@ -758,8 +759,8 @@ mygame/web/chargen/templates/chargen/detail.html
|
|||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>Once you have all these files stand in your <code class="docutils literal notranslate"><span class="pre">mygame/</span></code>folder and run:</p>
|
||||
<div class="highlight-bash notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2</pre></div></td><td class="code"><div class="highlight"><pre><span></span>evennia makemigrations
|
||||
<div class="highlight-bash notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
||||
<span class="normal">2</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span>evennia makemigrations
|
||||
evennia migrate
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
|
|
@ -771,8 +772,8 @@ be something like <code class="docutils literal notranslate"><span class="pre">h
|
|||
<p>This should hopefully give you a good starting point in figuring out how you’d like to approach your
|
||||
own web generation. The main difficulties are in setting the appropriate settings on your newly
|
||||
created character object. Thankfully, the Evennia API makes this easy.</p>
|
||||
</div>
|
||||
<div class="section" id="adding-a-no-capcha-recapcha-on-your-character-generation">
|
||||
</section>
|
||||
<section id="adding-a-no-capcha-recapcha-on-your-character-generation">
|
||||
<h2>Adding a no CAPCHA reCAPCHA on your character generation<a class="headerlink" href="#adding-a-no-capcha-recapcha-on-your-character-generation" title="Permalink to this headline">¶</a></h2>
|
||||
<p>As sad as it is, if your server is open to the web, bots might come to visit and take advantage of
|
||||
your open form to create hundreds, thousands, millions of characters if you give them the
|
||||
|
|
@ -784,7 +785,7 @@ inside. It’s worth pointing out that, as long as Google doesn’t suspect you
|
|||
is quite useful, not only for common users, but to screen-reader users, to which reading inside of
|
||||
an image is pretty difficult, if not impossible. And to top it all, it will be so easy to add in
|
||||
your website.</p>
|
||||
<div class="section" id="step-1-obtain-a-sitekey-and-secret-from-google">
|
||||
<section id="step-1-obtain-a-sitekey-and-secret-from-google">
|
||||
<h3>Step 1: Obtain a SiteKey and secret from Google<a class="headerlink" href="#step-1-obtain-a-sitekey-and-secret-from-google" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The first thing is to ask Google for a way to safely authenticate your website to their service. To
|
||||
do it, we need to create a site key and a secret. Go to
|
||||
|
|
@ -792,8 +793,8 @@ do it, we need to create a site key and a secret. Go to
|
|||
site key. It’s quite easy when you have a Google account.</p>
|
||||
<p>When you have created your site key, save it safely. Also copy your secret key as well. You should
|
||||
find both information on the web page. Both would contain a lot of letters and figures.</p>
|
||||
</div>
|
||||
<div class="section" id="step-2-installing-and-configuring-the-dedicated-django-app">
|
||||
</section>
|
||||
<section id="step-2-installing-and-configuring-the-dedicated-django-app">
|
||||
<h3>Step 2: installing and configuring the dedicated Django app<a class="headerlink" href="#step-2-installing-and-configuring-the-dedicated-django-app" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Since Evennia runs on Django, the easiest way to add our CAPCHA and perform the proper check is to
|
||||
install the dedicated Django app. Quite easy:</p>
|
||||
|
|
@ -802,11 +803,11 @@ install the dedicated Django app. Quite easy:</p>
|
|||
</div>
|
||||
<p>And add it to the installed apps in your settings. In your <code class="docutils literal notranslate"><span class="pre">mygame/server/conf/settings.py</span></code>, you
|
||||
might have something like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
|
||||
<span class="n">INSTALLED_APPS</span> <span class="o">+=</span> <span class="p">(</span>
|
||||
<span class="s1">'web.chargen'</span><span class="p">,</span>
|
||||
<span class="s1">'nocaptcha_recaptcha'</span><span class="p">,</span>
|
||||
|
|
@ -815,28 +816,28 @@ might have something like this:</p>
|
|||
</td></tr></table></div>
|
||||
<p>Don’t close the setting file just yet. We have to add in the site key and secret key. You can add
|
||||
them below:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># NoReCAPCHA site key</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># NoReCAPCHA site key</span>
|
||||
<span class="n">NORECAPTCHA_SITE_KEY</span> <span class="o">=</span> <span class="s2">"PASTE YOUR SITE KEY HERE"</span>
|
||||
<span class="c1"># NoReCAPCHA secret key</span>
|
||||
<span class="n">NORECAPTCHA_SECRET_KEY</span> <span class="o">=</span> <span class="s2">"PUT YOUR SECRET KEY HERE"</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
<div class="section" id="step-3-adding-the-capcha-to-our-form">
|
||||
</section>
|
||||
<section id="step-3-adding-the-capcha-to-our-form">
|
||||
<h3>Step 3: Adding the CAPCHA to our form<a class="headerlink" href="#step-3-adding-the-capcha-to-our-form" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Finally we have to add the CAPCHA to our form. It will be pretty easy too. First, open your
|
||||
<code class="docutils literal notranslate"><span class="pre">web/chargen/forms.py</span></code> file. We’re going to add a new field, but hopefully, all the hard work has
|
||||
been done for us. Update at your convenience, You might end up with something like this:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>
|
||||
<span class="kn">from</span> <span class="nn">nocaptcha_recaptcha.fields</span> <span class="kn">import</span> <span class="n">NoReCaptchaField</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">AppForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
|
||||
|
|
@ -848,27 +849,27 @@ been done for us. Update at your convenience, You might end up with something l
|
|||
<p>As you see, we added a line of import (line 2) and a field in our form.</p>
|
||||
<p>And lastly, we need to update our HTML file to add in the Google library. You can open
|
||||
<code class="docutils literal notranslate"><span class="pre">web/chargen/templates/chargen/create.html</span></code>. There’s only one line to add:</p>
|
||||
<div class="highlight-html notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="p"><</span><span class="nt">script</span> <span class="na">src</span><span class="o">=</span><span class="s">"https://www.google.com/recaptcha/api.js"</span> <span class="na">async</span> <span class="na">defer</span><span class="p">></</span><span class="nt">script</span><span class="p">></span>
|
||||
<div class="highlight-html notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="p"><</span><span class="nt">script</span> <span class="na">src</span><span class="o">=</span><span class="s">"https://www.google.com/recaptcha/api.js"</span> <span class="na">async</span> <span class="na">defer</span><span class="p">></</span><span class="nt">script</span><span class="p">></span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<p>And you should put it at the bottom of the page. Just before the closing body would be good, but
|
||||
for the time being, the base page doesn’t provide a footer block, so we’ll put it in the content
|
||||
block. Note that it’s not the best place, but it will work. In the end, your
|
||||
<code class="docutils literal notranslate"><span class="pre">web/chargen/templates/chargen/create.html</span></code> file should look like this:</p>
|
||||
<div class="highlight-html notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14</pre></div></td><td class="code"><div class="highlight"><pre><span></span>{% extends "base.html" %}
|
||||
<div class="highlight-html notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span>{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<span class="p"><</span><span class="nt">h1</span><span class="p">></span>Character Creation<span class="p"></</span><span class="nt">h1</span><span class="p">></span>
|
||||
{% if user.is_authenticated %}
|
||||
|
|
@ -887,9 +888,9 @@ block. Note that it’s not the best place, but it will work. In the end, your
|
|||
<p>Reload and open <a class="reference external" href="http://localhost:4001/chargen/create/">http://localhost:4001/chargen/create</a> and
|
||||
you should see your beautiful CAPCHA just before the “submit” button. Try not to check the checkbox
|
||||
to see what happens. And do the same while checking the checkbox!</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||||
|
||||
<title>Web Character View Tutorial — 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" />
|
||||
|
|
@ -37,7 +38,7 @@
|
|||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="web-character-view-tutorial">
|
||||
<section id="web-character-view-tutorial">
|
||||
<h1>Web Character View Tutorial<a class="headerlink" href="#web-character-view-tutorial" title="Permalink to this headline">¶</a></h1>
|
||||
<p><strong>Before doing this tutorial you will probably want to read the intro in [Basic Web tutorial](Web-
|
||||
Tutorial).</strong></p>
|
||||
|
|
@ -59,7 +60,7 @@ the scope of this tutorial.</p>
|
|||
<p>In order for Django to find our new web app, we’ll need to add it to the <code class="docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code> setting.
|
||||
Evennia’s default installed apps are already set, so in <code class="docutils literal notranslate"><span class="pre">server/conf/settings.py</span></code>, we’ll just extend
|
||||
them:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="n">INSTALLED_APPS</span> <span class="o">+=</span> <span class="p">(</span><span class="s1">'web.character'</span><span class="p">,)</span>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="n">INSTALLED_APPS</span> <span class="o">+=</span> <span class="p">(</span><span class="s1">'web.character'</span><span class="p">,)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<blockquote>
|
||||
|
|
@ -72,14 +73,14 @@ know what URL should trigger the view. The pattern may also provide some informa
|
|||
we shall see.</p>
|
||||
<p>Here is our <code class="docutils literal notranslate"><span class="pre">character/urls.py</span></code> file (<strong>Note</strong>: you may have to create this file if a blank one
|
||||
wasn’t generated for you):</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># URL patterns for the character app</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># URL patterns for the character app</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">url</span>
|
||||
<span class="kn">from</span> <span class="nn">web.character.views</span> <span class="kn">import</span> <span class="n">sheet</span>
|
||||
|
|
@ -117,25 +118,25 @@ superuser you create in the beginning (#1). Thus, the griefer can get 50% of the
|
|||
need to hijack the admin account (the admin’s username) just by navigating to <code class="docutils literal notranslate"><span class="pre">sheet/1</span></code>!</p>
|
||||
</div></blockquote>
|
||||
<p>Next we create <code class="docutils literal notranslate"><span class="pre">views.py</span></code>, the view file that <code class="docutils literal notranslate"><span class="pre">urls.py</span></code> refers to.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># Views for our character app</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># Views for our character app</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">django.http</span> <span class="kn">import</span> <span class="n">Http404</span>
|
||||
<span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">render</span>
|
||||
|
|
@ -170,52 +171,52 @@ available as the variable “character”.</p>
|
|||
<p>The html template is created as <code class="docutils literal notranslate"><span class="pre">templates/character/sheet.html</span></code> under your <code class="docutils literal notranslate"><span class="pre">character</span></code> app folder.
|
||||
You may have to manually create both <code class="docutils literal notranslate"><span class="pre">template</span></code> and its subfolder <code class="docutils literal notranslate"><span class="pre">character</span></code>. Here’s the template
|
||||
to create:</p>
|
||||
<div class="highlight-html notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46</pre></div></td><td class="code"><div class="highlight"><pre><span></span>{% extends "base.html" %}
|
||||
<div class="highlight-html notranslate"><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>
|
||||
<span class="normal">37</span>
|
||||
<span class="normal">38</span>
|
||||
<span class="normal">39</span>
|
||||
<span class="normal">40</span>
|
||||
<span class="normal">41</span>
|
||||
<span class="normal">42</span>
|
||||
<span class="normal">43</span>
|
||||
<span class="normal">44</span>
|
||||
<span class="normal">45</span>
|
||||
<span class="normal">46</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span>{% extends "base.html" %}
|
||||
{% block content %}
|
||||
|
||||
<span class="p"><</span><span class="nt">h1</span><span class="p">></span>{{ character.name }}<span class="p"></</span><span class="nt">h1</span><span class="p">></span>
|
||||
|
|
@ -283,11 +284,11 @@ skills the user has, or if the user is approved (assuming your game has an appro
|
|||
<p>The last file we need to edit is the master URLs file. This is needed in order to smoothly integrate
|
||||
the URLs from your new <code class="docutils literal notranslate"><span class="pre">character</span></code> app with the URLs from Evennia’s existing pages. Find the file
|
||||
<code class="docutils literal notranslate"><span class="pre">web/urls.py</span></code> and update its <code class="docutils literal notranslate"><span class="pre">patterns</span></code> list as follows:</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># web/urls.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># web/urls.py</span>
|
||||
|
||||
<span class="n">custom_patterns</span> <span class="o">=</span> <span class="p">[</span>
|
||||
<span class="n">url</span><span class="p">(</span><span class="sa">r</span><span class="s1">'^character/'</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s1">'web.character.urls'</span><span class="p">))</span>
|
||||
|
|
@ -301,12 +302,12 @@ changed your defaults, you should be able to find the sheet for character <code
|
|||
immediately.</p>
|
||||
<p>As an optional final step, you can also change your character typeclass to have a method called
|
||||
‘get_absolute_url’.</p>
|
||||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># typeclasses/characters.py</span>
|
||||
<div class="highlight-python notranslate"><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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># typeclasses/characters.py</span>
|
||||
|
||||
<span class="c1"># inside Character</span>
|
||||
<span class="k">def</span> <span class="nf">get_absolute_url</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
|
|
@ -320,7 +321,7 @@ page by using {{ object.get_absolute_url }} in any template where you have a giv
|
|||
<p><em>Now that you’ve made a basic page and app with Django, you may want to read the full Django
|
||||
tutorial to get a better idea of what it can do. <a class="reference external" href="https://docs.djangoproject.com/en/1.8/intro/tutorial01/">You can find Django’s tutorial
|
||||
here</a>.</em></p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<div class="clearer"></div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue