Updated HTML docs

This commit is contained in:
Griatch 2021-10-26 21:41:11 +02:00
parent 66d0ad0bc9
commit 7900aad365
2073 changed files with 32986 additions and 41197 deletions

View file

@ -14,6 +14,8 @@
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"processClass": "tex2jax_process|mathjax_process|math|output_area"}})</script>
<link rel="shortcut icon" href="../../../_static/favicon.ico"/>
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
@ -47,31 +49,31 @@
<div class="bodywrapper">
<div class="body" role="main">
<section id="creating-things">
<section class="tex2jax_ignore mathjax_ignore" 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>
<p>Given the path to a Typeclass, there are three ways to create an instance of it:</p>
<ul>
<li><p>Firstly, you can call the class directly, and then <code class="docutils literal notranslate"><span class="pre">.save()</span></code> it:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="n">obj</span> <span class="o">=</span> <span class="n">SomeTypeClass</span><span class="p">(</span><span class="n">db_key</span><span class="o">=...</span><span class="p">)</span>
<span class="n">obj</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span> obj = SomeTypeClass(db_key=...)
obj.save()
</pre></div>
</div>
<p>This has the drawback of being two operations; you must also import the class and have to pass
the actual database field names, such as <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> as keyword arguments.</p>
</li>
<li><p>Secondly you can use the Evennia creation helpers:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="n">obj</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">create_object</span><span class="p">(</span><span class="n">SomeTypeClass</span><span class="p">,</span> <span class="n">key</span><span class="o">=...</span><span class="p">)</span>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span> obj = evennia.create_object(SomeTypeClass, key=...)
</pre></div>
</div>
<p>This is the recommended way if you are trying to create things in Python. The first argument can either be
the class <em>or</em> the python-path to the typeclass, like <code class="docutils literal notranslate"><span class="pre">&quot;path.to.SomeTypeClass&quot;</span></code>. It can also be <code class="docutils literal notranslate"><span class="pre">None</span></code> in which
case the Evennia default will be used. While all the creation methods
are available on <code class="docutils literal notranslate"><span class="pre">evennia</span></code>, they are actually implemented in <a class="reference external" href="../../../api/evennia.utils.create.html">evennia/utils/create.py</a>.</p>
are available on <code class="docutils literal notranslate"><span class="pre">evennia</span></code>, they are actually implemented in <a class="reference internal" href="../../../api/evennia.utils.create.html"><span class="doc std std-doc">evennia/utils/create.py</span></a>.</p>
</li>
<li><p>Finally, you can create objects using an in-game command, such as</p>
<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">obj</span><span class="p">:</span><span class="n">path</span><span class="o">.</span><span class="n">to</span><span class="o">.</span><span class="n">SomeTypeClass</span>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span> create/drop obj:path.to.SomeTypeClass
</pre></div>
</div>
<p>As a developer you are usually best off using the two other methods, but a command is usually the only way
@ -82,9 +84,9 @@ to let regular players or builders without Python-access help build the game wor
<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>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;</span> <span class="n">py</span>
<span class="o">&gt;</span> <span class="kn">import</span> <span class="nn">evennia</span>
<span class="o">&gt;</span> <span class="n">rose</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">create_object</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="s2">&quot;rose&quot;</span><span class="p">)</span>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; py
&gt; import evennia
&gt; rose = evennia.create_object(key=&quot;rose&quot;)
</pre></div>
</div>
<p>Since we didnt 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>
@ -153,7 +155,7 @@ You can find the parent class for Accounts in <code class="docutils literal notr
<h3>Versions</h3>
<ul>
<li><a href="Creating-Things.html">1.0-dev (develop branch)</a></li>
<li><a href="../../../../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
<li><a href="../../../../0.95/index.html">0.95 (v0.9.5 branch)</a></li>
</ul>
</div>