evennia/docs/1.0-dev/Howtos/Beginner-Tutorial/Part1/Beginner-Tutorial-Creating-Things.html
Evennia docbuilder action 91f982833e Updated HTML docs.
2022-11-15 19:52:44 +00:00

196 lines
No EOL
11 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>10. Creating things &#8212; Evennia 1.0-dev documentation</title>
<link rel="stylesheet" href="../../../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></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" />
<link rel="next" title="11. Searching for things" href="Beginner-Tutorial-Searching-Things.html" />
<link rel="prev" title="9. Parsing Command input" href="Beginner-Tutorial-More-on-Commands.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Searching-Things.html" title="11. Searching for things"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-More-on-Commands.html" title="9. Parsing Command input"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 1.0-dev</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Intro.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Intro.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">10. </span>Creating things</a></li>
</ul>
<div class="develop">develop branch</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../../../index.html">
<img class="logo" src="../../../_static/evennia_logo.png" alt="Logo"/>
</a></p>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
<h3><a href="../../../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">10. Creating things</a><ul>
<li><a class="reference internal" href="#creating-objects">10.1. Creating Objects</a></li>
<li><a class="reference internal" href="#creating-accounts">10.2. Creating Accounts</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="Beginner-Tutorial-More-on-Commands.html"
title="previous chapter"><span class="section-number">9. </span>Parsing Command input</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="Beginner-Tutorial-Searching-Things.html"
title="next chapter"><span class="section-number">11. </span>Searching for things</a></p>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
<li><a href="../../../_sources/Howtos/Beginner-Tutorial/Part1/Beginner-Tutorial-Creating-Things.md.txt"
rel="nofollow">Show Page Source</a></li>
</ul>
</div><h3>Links</h3>
<ul>
<li><a href="https://www.evennia.com">Home page</a> </li>
<li><a href="https://github.com/evennia/evennia">Evennia Github</a> </li>
<li><a href="http://games.evennia.com">Game Index</a> </li>
<li>
<a href="https://discord.gg/AJJpcRUhtF">Discord</a> -
<a href="https://github.com/evennia/evennia/discussions">Discussions</a> -
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Creating-Things.html">1.0-dev (develop branch)</a></li>
</ul>
<ul>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section class="tex2jax_ignore mathjax_ignore" id="creating-things">
<h1><span class="section-number">10. </span>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-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-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 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-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
to let regular players or builders without Python-access help build the game world.</p>
</li>
</ul>
<section id="creating-objects">
<h2><span class="section-number">10.1. </span>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-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>
(<code class="docutils literal notranslate"><span class="pre">typeclasses.objects.Object</span></code>) will be used.</p>
</section>
<section id="creating-accounts">
<h2><span class="section-number">10.2. </span>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>
</section>
</section>
</div>
</div>
</div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Searching-Things.html" title="11. Searching for things"
>next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-More-on-Commands.html" title="9. Parsing Command input"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 1.0-dev</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Intro.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Intro.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">10. </span>Creating things</a></li>
</ul>
<div class="develop">develop branch</div>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2022, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</div>
</body>
</html>