evennia/docs/2.x/Components/Exits.html

200 lines
13 KiB
HTML
Raw Normal View History

2023-10-19 20:22:27 +00:00
<!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>Exits &#8212; Evennia 2.x 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="Scripts" href="Scripts.html" />
<link rel="prev" title="Rooms" href="Rooms.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="Scripts.html" title="Scripts"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Rooms.html" title="Rooms"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="Components-Overview.html" accesskey="U">Core Components</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Exits</a></li>
</ul>
2023-12-20 18:20:52 +01:00
</div>
2023-10-19 20:22:27 +00:00
<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="#">Exits</a><ul>
<li><a class="reference internal" href="#exit-details">Exit details</a></li>
<li><a class="reference internal" href="#creating-exits-in-code">Creating Exits in code</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="Rooms.html"
title="previous chapter">Rooms</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="Scripts.html"
title="next chapter">Scripts</a></p>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
<li><a href="../_sources/Components/Exits.md.txt"
rel="nofollow">Show Page Source</a></li>
</ul>
</div><h3>Links</h3>
<ul>
<li><a href="https://www.evennia.com/docs/latest/index.html">Documentation Top</a> </li>
<li><a href="https://www.evennia.com">Evennia Home</a> </li>
<li><a href="https://github.com/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>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section class="tex2jax_ignore mathjax_ignore" id="exits">
<h1>Exits<a class="headerlink" href="#exits" title="Permalink to this headline"></a></h1>
<p><strong>Inheritance Tree:</strong></p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>┌─────────────┐
│DefaultObject│
└─────▲───────┘
┌─────┴─────┐
│DefaultExit│
└─────▲─────┘
│ ┌────────────┐
│ ┌─────►ObjectParent│
│ │ └────────────┘
┌─┴─┴┐
│Exit│
└────┘
</pre></div>
</div>
<p><em>Exits</em> are in-game <a class="reference internal" href="Objects.html"><span class="doc std std-doc">Objects</span></a> connecting other objects (usually <a class="reference internal" href="Rooms.html"><span class="doc std std-doc">Rooms</span></a>) together.</p>
<blockquote>
<div><p>Note that Exits are one-way objects, so in order for two Rooms to be linked bi-directionally, there will need to be two exits.</p>
</div></blockquote>
<p>An object named <code class="docutils literal notranslate"><span class="pre">north</span></code> or <code class="docutils literal notranslate"><span class="pre">in</span></code> might be exits, as well as <code class="docutils literal notranslate"><span class="pre">door</span></code>, <code class="docutils literal notranslate"><span class="pre">portal</span></code> or <code class="docutils literal notranslate"><span class="pre">jump</span> <span class="pre">out</span> <span class="pre">the</span> <span class="pre">window</span></code>.</p>
<p>An exit has two things that separate them from other objects.</p>
<ol class="simple">
<li><p>Their <code class="docutils literal notranslate"><span class="pre">.destination</span></code> property is set and points to a valid target location. This fact makes it easy and fast to locate exits in the database.</p></li>
<li><p>Exits define a special <a class="reference internal" href="Commands.html"><span class="doc std std-doc">Transit Command</span></a> on themselves when they are created. This command is named the same as the exit object and will, when called, handle the practicalities of moving the character to the Exitss <code class="docutils literal notranslate"><span class="pre">.destination</span></code> - this allows you to just enter the name of the exit on its own to move around, just as you would expect.</p></li>
</ol>
<p>The default exit functionality is all defined on the <a class="reference internal" href="../api/evennia.objects.objects.html#evennia.objects.objects.DefaultExit" title="evennia.objects.objects.DefaultExit"><span class="xref myst py py-class">DefaultExit</span></a> typeclass. You could in principle completely change how exits work in your game by overriding this - its not recommended though, unless you really know what you are doing).</p>
<p>Exits are <a class="reference internal" href="Locks.html"><span class="doc std std-doc">locked</span></a> using an <code class="docutils literal notranslate"><span class="pre">access_type</span></code> called <em>traverse</em> and also make use of a few hook methods for giving feedback if the traversal fails. See <code class="docutils literal notranslate"><span class="pre">evennia.DefaultExit</span></code> for more info.</p>
<p>Exits are normally overridden on a case-by-case basis, but if you want to change the default exit created by rooms like <code class="docutils literal notranslate"><span class="pre">dig</span></code>, <code class="docutils literal notranslate"><span class="pre">tunnel</span></code> or <code class="docutils literal notranslate"><span class="pre">open</span></code> you can change it in settings:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>BASE_EXIT_TYPECLASS = &quot;typeclasses.exits.Exit&quot;
</pre></div>
</div>
<p>In <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/exits.py</span></code> there is an empty <code class="docutils literal notranslate"><span class="pre">Exit</span></code> class for you to modify.</p>
<section id="exit-details">
<h2>Exit details<a class="headerlink" href="#exit-details" title="Permalink to this headline"></a></h2>
<p>The process of traversing an exit is as follows:</p>
<ol class="simple">
<li><p>The traversing <code class="docutils literal notranslate"><span class="pre">obj</span></code> sends a command that matches the Exit-command name on the Exit object. The <a class="reference internal" href="Commands.html"><span class="doc std std-doc">cmdhandler</span></a> detects this and triggers the command defined on the Exit. Traversal always involves the “source” (the current location) and the <code class="docutils literal notranslate"><span class="pre">destination</span></code> (this is stored on the Exit object).</p></li>
<li><p>The Exit command checks the <code class="docutils literal notranslate"><span class="pre">traverse</span></code> lock on the Exit object</p></li>
<li><p>The Exit command triggers <code class="docutils literal notranslate"><span class="pre">at_traverse(obj,</span> <span class="pre">destination)</span></code> on the Exit object.</p></li>
<li><p>In <code class="docutils literal notranslate"><span class="pre">at_traverse</span></code>, <code class="docutils literal notranslate"><span class="pre">object.move_to(destination)</span></code> is triggered. This triggers the following hooks, in order:</p>
<ol class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">obj.at_pre_move(destination)</span></code> - if this returns False, move is aborted.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">origin.at_pre_leave(obj,</span> <span class="pre">destination)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">obj.announce_move_from(destination)</span></code></p></li>
<li><p>Move is performed by changing <code class="docutils literal notranslate"><span class="pre">obj.location</span></code> from source location to <code class="docutils literal notranslate"><span class="pre">destination</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">obj.announce_move_to(source)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">destination.at_object_receive(obj,</span> <span class="pre">source)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">obj.at_post_move(source)</span></code></p></li>
</ol>
</li>
<li><p>On the Exit object, <code class="docutils literal notranslate"><span class="pre">at_post_traverse(obj,</span> <span class="pre">source)</span></code> is triggered.</p></li>
</ol>
<p>If the move fails for whatever reason, the Exit will look for an Attribute <code class="docutils literal notranslate"><span class="pre">err_traverse</span></code> on itself and display this as an error message. If this is not found, the Exit will instead call <code class="docutils literal notranslate"><span class="pre">at_failed_traverse(obj)</span></code> on itself.</p>
</section>
<section id="creating-exits-in-code">
<h2>Creating Exits in code<a class="headerlink" href="#creating-exits-in-code" title="Permalink to this headline"></a></h2>
<p>For an example of how to create Exits programatically please see <a class="reference internal" href="../Howtos/Beginner-Tutorial/Part1/Beginner-Tutorial-Creating-Things.html#linking-exits-and-rooms-in-code"><span class="std std-doc">this guide</span></a>.</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="Scripts.html" title="Scripts"
>next</a> |</li>
<li class="right" >
<a href="Rooms.html" title="Rooms"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="Components-Overview.html" >Core Components</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Exits</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</div>
</body>
</html>