evennia/docs/1.0-dev/Howtos/Beginner-Tutorial/Part1/Searching-Things.html

415 lines
30 KiB
HTML
Raw Normal View History

2020-07-14 00:21:00 +02:00
<!DOCTYPE html>
2020-10-15 01:31:30 +02:00
<html>
2020-07-14 00:21:00 +02:00
<head>
<meta charset="utf-8" />
2021-05-16 00:06:01 +02:00
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
2022-02-06 18:34:09 +00:00
<title>11. Searching for things &#8212; Evennia 1.0-dev documentation</title>
2020-07-14 00:21:00 +02:00
<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" />
2020-10-19 22:46:24 +02:00
<link rel="search" title="Search" href="../../../search.html" />
2022-02-06 18:34:09 +00:00
<link rel="next" title="12. Advanced searching - Django Database queries" href="Django-queries.html" />
<link rel="prev" title="10. Creating things" href="Creating-Things.html" />
2020-07-14 00:21:00 +02:00
</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>
2020-10-19 22:46:24 +02:00
<li class="right" >
2022-02-06 18:34:09 +00:00
<a href="Django-queries.html" title="12. Advanced searching - Django Database queries"
2020-10-19 22:46:24 +02:00
accesskey="N">next</a> |</li>
<li class="right" >
2022-02-06 18:34:09 +00:00
<a href="Creating-Things.html" title="10. Creating things"
2020-10-19 22:46:24 +02:00
accesskey="P">previous</a> |</li>
2020-10-15 01:31:30 +02:00
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 1.0-dev</a> &#187;</li>
2022-02-06 18:34:09 +00:00
<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">11. </span>Searching for things</a></li>
2020-07-14 00:21:00 +02:00
</ul>
2021-06-23 18:58:26 +02:00
<div class="develop">develop branch</div>
2020-07-14 00:21:00 +02:00
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
2021-10-26 21:41:11 +02:00
<section class="tex2jax_ignore mathjax_ignore" id="searching-for-things">
2022-02-06 18:34:09 +00:00
<h1><span class="section-number">11. </span>Searching for things<a class="headerlink" href="#searching-for-things" title="Permalink to this headline"></a></h1>
2020-07-14 00:21:00 +02:00
<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>
2021-05-16 00:06:01 +02:00
<section id="main-search-functions">
2022-02-06 18:34:09 +00:00
<h2><span class="section-number">11.1. </span>Main search functions<a class="headerlink" href="#main-search-functions" title="Permalink to this headline"></a></h2>
2020-07-14 00:21:00 +02:00
<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>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span> rose = evennia.search_object(key=&quot;rose&quot;)
acct = evennia.search_account(key=&quot;MyAccountName&quot;, email=&quot;foo@bar.com&quot;)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
2021-05-16 00:06:01 +02:00
<aside class="sidebar">
2020-07-14 00:21:00 +02:00
<p class="sidebar-title">Querysets</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>What is returned from the main search functions is actually a `queryset`. They can be
treated like lists except that they can&#39;t modified in-place. We&#39;ll discuss querysets in
the `next lesson` &lt;Django-queries&gt;`_.
</pre></div>
</div>
2021-05-16 00:06:01 +02:00
</aside>
2020-07-14 00:21:00 +02:00
<p>Strings are always case-insensitive, so searching for <code class="docutils literal notranslate"><span class="pre">&quot;rose&quot;</span></code>, <code class="docutils literal notranslate"><span class="pre">&quot;Rose&quot;</span></code> or <code class="docutils literal notranslate"><span class="pre">&quot;rOsE&quot;</span></code> give the same results.
Its 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>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>rose = rose[0]
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>Often you really want all matches to the search parameters you specify. In other situations, having zero or
more than one match is a sign of a problem and you need to handle this case yourself.</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>the_one_ring = evennia.search_object(key=&quot;The one Ring&quot;)
if not the_one_ring:
# handle not finding the ring at all
elif len(the_one_ring) &gt; 1:
# handle finding more than one ring
else:
# ok - exactly one ring found
the_one_ring = the_one_ring[0]
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>There are equivalent search functions for all the main resources. You can find a listing of them
2021-10-26 21:41:11 +02:00
<a class="reference internal" href="../../../Evennia-API.html"><span class="doc std std-doc">in the Search functions section</span></a> of the API frontpage.</p>
2021-05-16 00:06:01 +02:00
</section>
<section id="searching-using-object-search">
2022-02-06 18:34:09 +00:00
<h2><span class="section-number">11.2. </span>Searching using Object.search<a class="headerlink" href="#searching-using-object-search" title="Permalink to this headline"></a></h2>
2020-07-14 00:21:00 +02:00
<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>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>rose = obj.search(&quot;rose&quot;)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">.search</span></code> method wraps <code class="docutils literal notranslate"><span class="pre">evennia.search_object</span></code> and handles its output in various ways.</p>
<ul class="simple">
<li><p>By default it will always search for objects among those in <code class="docutils literal notranslate"><span class="pre">obj.location.contents</span></code> and <code class="docutils literal notranslate"><span class="pre">obj.contents</span></code> (that is,
things in objs inventory or in the same room).</p></li>
<li><p>It will always return exactly one match. If it found zero or more than one match, the return is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</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>
2021-10-26 21:41:11 +02:00
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
2020-07-14 00:21:00 +02:00
<span class="k">class</span> <span class="nc">MyCommand</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">&quot;findfoo&quot;</span>
<span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">foo</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="s2">&quot;foo&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">foo</span><span class="p">:</span>
<span class="k">return</span>
</pre></div>
2021-10-26 21:41:11 +02:00
</div>
2020-07-14 00:21:00 +02:00
<p>Remember, <code class="docutils literal notranslate"><span class="pre">self.caller</span></code> is the one calling the command. This is usually a Character, which
inherits from <code class="docutils literal notranslate"><span class="pre">DefaultObject</span></code>! This (rather stupid) Command searches for an object named “foo” in
the same location. If it cant find it, <code class="docutils literal notranslate"><span class="pre">foo</span></code> will be <code class="docutils literal notranslate"><span class="pre">None</span></code>. The error has already been reported
to <code class="docutils literal notranslate"><span class="pre">self.caller</span></code> so we just abort with <code class="docutils literal notranslate"><span class="pre">return</span></code>.</p>
<p>You can use <code class="docutils literal notranslate"><span class="pre">.search</span></code> to find anything, not just stuff in the same room:</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>volcano = self.caller.search(&quot;Volcano&quot;, global=True)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>If you only want to search for a specific list of things, you can do so too:</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>stone = self.caller.search(&quot;MyStone&quot;, candidates=[obj1, obj2, obj3, obj4])
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>This will only return a match if MyStone is one of the four provided candidate objects. This is quite powerful,
heres how youd find something only in your inventory:</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>potion = self.caller.search(&quot;Healing potion&quot;, candidates=self.caller.contents)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>You can also turn off the automatic error handling:</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>swords = self.caller.search(&quot;Sword&quot;, quiet=True)
2020-07-14 00:21:00 +02:00
</pre></div>
</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>
2021-05-16 00:06:01 +02:00
</section>
<section id="what-can-be-searched-for">
2022-02-06 18:34:09 +00:00
<h2><span class="section-number">11.3. </span>What can be searched for<a class="headerlink" href="#what-can-be-searched-for" title="Permalink to this headline"></a></h2>
2020-07-14 00:21:00 +02:00
<p>These are the main database entities one can search for:</p>
<ul class="simple">
2021-10-26 21:41:11 +02:00
<li><p><a class="reference internal" href="../../../Components/Objects.html"><span class="doc std std-doc">Objects</span></a></p></li>
<li><p><a class="reference internal" href="../../../Components/Accounts.html"><span class="doc std std-doc">Accounts</span></a></p></li>
<li><p><a class="reference internal" href="../../../Components/Scripts.html"><span class="doc std std-doc">Scripts</span></a>,</p></li>
<li><p><a class="reference internal" href="../../../Components/Channels.html"><span class="doc std std-doc">Channels</span></a>,</p></li>
<li><p><a class="reference internal" href="../../../Components/Msg.html"><span class="doc std std-doc">Messages</span></a></p></li>
<li><p><a class="reference internal" href="../../../Components/Help-System.html"><span class="doc std std-doc">Help Entries</span></a>.</p></li>
2020-07-14 00:21:00 +02:00
</ul>
<p>Most of the time youll likely spend your time searching for Objects and the occasional Accounts.</p>
<p>So to find an entity, what can be searched for?</p>
2021-05-16 00:06:01 +02:00
<section id="search-by-key">
2022-02-06 18:34:09 +00:00
<h3><span class="section-number">11.3.1. </span>Search by key<a class="headerlink" href="#search-by-key" title="Permalink to this headline"></a></h3>
2020-07-14 00:21:00 +02:00
<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>
2021-05-16 00:06:01 +02:00
</section>
<section id="search-by-aliases">
2022-02-06 18:34:09 +00:00
<h3><span class="section-number">11.3.2. </span>Search by aliases<a class="headerlink" href="#search-by-aliases" title="Permalink to this headline"></a></h3>
2020-07-14 00:21:00 +02:00
<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 cant easily search only for aliases.</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>rose.aliases.add(&quot;flower&quot;)
2020-07-14 00:21:00 +02:00
</pre></div>
</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">&quot;Rose&quot;</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>
2021-05-16 00:06:01 +02:00
</section>
<section id="search-by-location">
2022-02-06 18:34:09 +00:00
<h3><span class="section-number">11.3.3. </span>Search by location<a class="headerlink" href="#search-by-location" title="Permalink to this headline"></a></h3>
2020-07-14 00:21:00 +02:00
<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
general search function. If we assume <code class="docutils literal notranslate"><span class="pre">room</span></code> is a particular Room instance,</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>chest = evennia.search_object(&quot;Treasure chest&quot;, location=room)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
2021-05-16 00:06:01 +02:00
</section>
<section id="search-by-tags">
2022-02-06 18:34:09 +00:00
<h3><span class="section-number">11.3.4. </span>Search by Tags<a class="headerlink" href="#search-by-tags" title="Permalink to this headline"></a></h3>
2021-10-26 21:41:11 +02:00
<p>Think of a <a class="reference internal" href="../../../Components/Tags.html"><span class="doc std std-doc">Tag</span></a> as the label the airport puts on your luggage when flying.
2020-07-14 00:21:00 +02:00
Everyone going on the same plane gets a tag grouping them together so the airport can know what should
go to which plane. Entities in Evennia can be grouped in the same way. Any number of tags can be attached
to each object.</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>rose.tags.add(&quot;flowers&quot;)
daffodil.tags.add(&quot;flowers&quot;)
tulip.tags.add(&quot;flowers&quot;)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>You can now find all flowers using the <code class="docutils literal notranslate"><span class="pre">search_tag</span></code> function:</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>all_flowers = evennia.search_tag(&quot;flowers&quot;)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>Tags can also have categories. By default this category is <code class="docutils literal notranslate"><span class="pre">None</span></code> which is also considered a category.</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>silmarillion.tags.add(&quot;fantasy&quot;, category=&quot;books&quot;)
ice_and_fire.tags.add(&quot;fantasy&quot;, category=&quot;books&quot;)
mona_lisa_overdrive.tags.add(&quot;cyberpunk&quot;, category=&quot;books&quot;)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>Note that if you specify the tag you <em>must</em> also include its category, otherwise that category
will be <code class="docutils literal notranslate"><span class="pre">None</span></code> and find no matches.</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>all_fantasy_books = evennia.search_tag(&quot;fantasy&quot;) # no matches!
all_fantasy_books = evennia.search_tag(&quot;fantasy&quot;, category=&quot;books&quot;)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>Only the second line above returns the two fantasy books. If we specify a category however,
we can get all tagged entities within that category:</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>all_books = evennia.search_tag(category=&quot;books&quot;)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>This gets all three books.</p>
2021-05-16 00:06:01 +02:00
</section>
<section id="search-by-attribute">
2022-02-06 18:34:09 +00:00
<h3><span class="section-number">11.3.5. </span>Search by Attribute<a class="headerlink" href="#search-by-attribute" title="Permalink to this headline"></a></h3>
2021-10-26 21:41:11 +02:00
<p>We can also search by the <a class="reference internal" href="../../../Components/Attributes.html"><span class="doc std std-doc">Attributes</span></a> associated with entities.</p>
2020-07-14 00:21:00 +02:00
<p>For example, lets give our rose thorns:</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>rose.db.has_thorns = True
wines.db.has_thorns = True
daffodil.db.has_thorns = False
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>Now we can find things attribute and the value we want it to have:</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>is_ouch = evennia.search_object_attribute(&quot;has_thorns&quot;, True)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>This returns the rose and the wines.</p>
<blockquote>
<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>
2021-05-16 00:06:01 +02:00
</section>
<section id="search-by-typeclass">
2022-02-06 18:34:09 +00:00
<h3><span class="section-number">11.3.6. </span>Search by Typeclass<a class="headerlink" href="#search-by-typeclass" title="Permalink to this headline"></a></h3>
2020-07-14 00:21:00 +02:00
<p>Sometimes its useful to find all objects of a specific Typeclass. All of Evennias search tools support this.</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>all_roses = evennia.search_object(typeclass=&quot;typeclasses.flowers.Rose&quot;)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>If you have the <code class="docutils literal notranslate"><span class="pre">Rose</span></code> class already imported you can also pass it directly:</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>all_roses = evennia.search_object(typeclass=Rose)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>You can also search using the typeclass itself:</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>all_roses = Rose.objects.all()
2020-07-14 00:21:00 +02:00
</pre></div>
</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
2021-10-26 21:41:11 +02:00
Python.</p>
2021-05-16 00:06:01 +02:00
</section>
<section id="search-by-dbref">
2022-02-06 18:34:09 +00:00
<h3><span class="section-number">11.3.7. </span>Search by dbref<a class="headerlink" href="#search-by-dbref" title="Permalink to this headline"></a></h3>
2020-07-14 00:21:00 +02:00
<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>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>the_answer = self.caller.search(&quot;#42&quot;)
eightball = evennia.search_object(&quot;#8&quot;)
2020-07-14 00:21:00 +02:00
</pre></div>
</div>
<p>Since <code class="docutils literal notranslate"><span class="pre">#dbref</span></code> is always unique, this search is always global.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Relying on #dbrefs</p>
2021-10-26 21:41:11 +02:00
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>You may be used to using #dbrefs a lot from other codebases. It is however considered
`bad practice` in Evennia to rely on hard-coded #dbrefs. It makes your code hard to maintain
2020-07-14 00:21:00 +02:00
and tied to the exact layout of the database. In 99% of cases you should pass the actual objects
2021-10-26 21:41:11 +02:00
around and search by key/tags/attribute instead.
</pre></div>
</div>
2020-07-14 00:21:00 +02:00
</div>
2021-05-16 00:06:01 +02:00
</section>
</section>
<section id="finding-objects-relative-each-other">
2022-02-06 18:34:09 +00:00
<h2><span class="section-number">11.4. </span>Finding objects relative each other<a class="headerlink" href="#finding-objects-relative-each-other" title="Permalink to this headline"></a></h2>
2020-07-14 00:21:00 +02:00
<p>Lets 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>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">coin.location</span></code> is <code class="docutils literal notranslate"><span class="pre">chest</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">chest.location</span></code> is <code class="docutils literal notranslate"><span class="pre">dungeon</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">door.location</span></code> is <code class="docutils literal notranslate"><span class="pre">dungeon</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">room.location</span></code> is <code class="docutils literal notranslate"><span class="pre">None</span></code> since its not inside something else.</p></li>
</ul>
<p>One can use this to find what is inside what. For example, <code class="docutils literal notranslate"><span class="pre">coin.location.location</span></code> is the <code class="docutils literal notranslate"><span class="pre">room</span></code>.
We can also find what is inside each object. This is a list of things.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">room.contents</span></code> is <code class="docutils literal notranslate"><span class="pre">[chest,</span> <span class="pre">door]</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">chest.contents</span></code> is <code class="docutils literal notranslate"><span class="pre">[coin]</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">coin.contents</span></code> is <code class="docutils literal notranslate"><span class="pre">[]</span></code>, the empty list since theres nothing inside the coin.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">door.contents</span></code> is <code class="docutils literal notranslate"><span class="pre">[]</span></code> too.</p></li>
</ul>
<p>A convenient helper is <code class="docutils literal notranslate"><span class="pre">.contents_get</span></code> - this allows to restrict what is returned:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">room.contents_get(exclude=chest)</span></code> - this returns everything in the room except the chest (maybe its hidden?)</p></li>
</ul>
<p>There is a special property for finding exits:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">room.exits</span></code> is <code class="docutils literal notranslate"><span class="pre">[door]</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">coin.exits</span></code> is <code class="docutils literal notranslate"><span class="pre">[]</span></code> (same for all the other objects)</p></li>
</ul>
<p>There is a property <code class="docutils literal notranslate"><span class="pre">.destination</span></code> which is only used by exits:</p>
<ul class="simple">
<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>
2021-05-16 00:06:01 +02:00
</section>
<section id="summary">
2022-02-06 18:34:09 +00:00
<h2><span class="section-number">11.5. </span>Summary<a class="headerlink" href="#summary" title="Permalink to this headline"></a></h2>
2020-07-14 00:21:00 +02:00
<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>
2021-05-16 00:06:01 +02:00
</section>
</section>
2020-07-14 00:21:00 +02:00
2020-10-15 01:31:30 +02:00
<div class="clearer"></div>
2020-07-14 00:21:00 +02:00
</div>
</div>
</div>
<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>
<p><h3><a href="../../../index.html">Table of Contents</a></h3>
<ul>
2022-02-06 18:34:09 +00:00
<li><a class="reference internal" href="#">11. Searching for things</a><ul>
<li><a class="reference internal" href="#main-search-functions">11.1. Main search functions</a></li>
<li><a class="reference internal" href="#searching-using-object-search">11.2. Searching using Object.search</a></li>
<li><a class="reference internal" href="#what-can-be-searched-for">11.3. What can be searched for</a><ul>
<li><a class="reference internal" href="#search-by-key">11.3.1. Search by key</a></li>
<li><a class="reference internal" href="#search-by-aliases">11.3.2. Search by aliases</a></li>
<li><a class="reference internal" href="#search-by-location">11.3.3. Search by location</a></li>
<li><a class="reference internal" href="#search-by-tags">11.3.4. Search by Tags</a></li>
<li><a class="reference internal" href="#search-by-attribute">11.3.5. Search by Attribute</a></li>
<li><a class="reference internal" href="#search-by-typeclass">11.3.6. Search by Typeclass</a></li>
<li><a class="reference internal" href="#search-by-dbref">11.3.7. Search by dbref</a></li>
2020-07-14 00:21:00 +02:00
</ul>
</li>
2022-02-06 18:34:09 +00:00
<li><a class="reference internal" href="#finding-objects-relative-each-other">11.4. Finding objects relative each other</a></li>
<li><a class="reference internal" href="#summary">11.5. Summary</a></li>
2020-07-14 00:21:00 +02:00
</ul>
</li>
</ul>
2020-10-19 22:46:24 +02:00
<h4>Previous topic</h4>
<p class="topless"><a href="Creating-Things.html"
2022-02-06 18:34:09 +00:00
title="previous chapter"><span class="section-number">10. </span>Creating things</a></p>
2020-10-19 22:46:24 +02:00
<h4>Next topic</h4>
<p class="topless"><a href="Django-queries.html"
2022-02-06 18:34:09 +00:00
title="next chapter"><span class="section-number">12. </span>Advanced searching - Django Database queries</a></p>
2020-07-14 00:21:00 +02:00
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
2022-02-06 18:34:09 +00:00
<li><a href="../../../_sources/Howtos/Beginner-Tutorial/Part1/Searching-Things.md.txt"
2020-07-14 00:21:00 +02:00
rel="nofollow">Show Page Source</a></li>
</ul>
2021-03-06 01:37:43 +01:00
</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>
2021-08-06 00:47:51 +02:00
<li>
<a href="https://discord.gg/AJJpcRUhtF">Discord</a> -
<a href="https://github.com/evennia/evennia/discussions">Discussions</a> -
2021-08-06 00:53:44 +02:00
<a href="https://evennia.blogspot.com/">Blog</a>
2021-03-06 01:37:43 +01:00
</li>
</ul>
2020-07-14 00:21:00 +02:00
<h3>Versions</h3>
<ul>
<li><a href="Searching-Things.html">1.0-dev (develop branch)</a></li>
2022-02-05 18:41:59 +00:00
<li><a href="../../../../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
2020-07-14 00:21:00 +02:00
</ul>
</div>
</div>
<div class="clearer"></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>
2020-10-19 22:46:24 +02:00
<li class="right" >
2022-02-06 18:34:09 +00:00
<a href="Django-queries.html" title="12. Advanced searching - Django Database queries"
2020-10-19 22:46:24 +02:00
>next</a> |</li>
<li class="right" >
2022-02-06 18:34:09 +00:00
<a href="Creating-Things.html" title="10. Creating things"
2020-10-19 22:46:24 +02:00
>previous</a> |</li>
2020-10-15 01:31:30 +02:00
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 1.0-dev</a> &#187;</li>
2022-02-06 18:34:09 +00:00
<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">11. </span>Searching for things</a></li>
2020-07-14 00:21:00 +02:00
</ul>
2021-06-23 18:58:26 +02:00
<div class="develop">develop branch</div>
2020-07-14 00:21:00 +02:00
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2020, The Evennia developer community.
2020-10-15 01:31:30 +02:00
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
2020-07-14 00:21:00 +02:00
</div>
</body>
</html>