<h1>Default Exit Errors<aclass="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 <aclass="reference internal"href="../Components/Objects.html"><spanclass="doc std std-doc">Exit Object</span></a> and
an <aclass="reference internal"href="../Components/Commands.html"><spanclass="doc std std-doc">Exit Command</span></a> stored on said exit object. The command has the same key and aliases as the
exit-object, which is why you can see the exit in the room and just write its name to traverse it.</p>
<p>So if you try to enter the name of a non-existing exit, Evennia treats is the same way as if you were trying to
use a non-existing command:</p>
<divclass="highlight-none notranslate"><divclass="highlight"><pre><span></span>> jump out the window
Command 'jump out the window' is not available. Type "help" for help.
</pre></div>
</div>
<p>Many games don’t need this type of freedom however. They define only the cardinal directions as valid exit names (
Evennia’s <codeclass="docutils literal notranslate"><spanclass="pre">tunnel</span></code> command also offers this functionality). In this case, the error starts to look less logical:</p>
<divclass="highlight-none notranslate"><divclass="highlight"><pre><span></span>> west
Command 'west' is not available. Maybe you meant "set" or "reset"?
</pre></div>
</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>
<divclass="highlight-none notranslate"><divclass="highlight"><pre><span></span>> west
You cannot move west.
</pre></div>
</div>
<sectionid="adding-default-error-commands">
<h2>Adding default error commands<aclass="headerlink"href="#adding-default-error-commands"title="Permalink to this headline">¶</a></h2>
<p>The way to do this is to give Evennia an <em>alternative</em> Command to use when no Exit-Command is found
in the room. See <aclass="reference internal"href="Beginner-Tutorial/Part1/Beginner-Tutorial-Adding-Commands.html"><spanclass="doc std std-doc">Adding Commands</span></a> for more info about the
process of adding new Commands to Evennia.</p>
<p>In this example all we’ll do is echo an error message.</p>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># for example in a file mygame/commands/movecommands.py</span>
<p>We pack our commands in a new little cmdset; if we add this to our
<codeclass="docutils literal notranslate"><spanclass="pre">CharacterCmdSet</span></code>, we can just add more errors to <codeclass="docutils literal notranslate"><spanclass="pre">MovementFailCmdSet</span></code>
later without having to change code in two places.</p>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># in mygame/commands/default_cmdsets.py</span>
<p><codeclass="docutils literal notranslate"><spanclass="pre">reload</span></code> the server. What happens henceforth is that if you are in a room with an Exitobject (let’s say it’s “north”),
the proper Exit-command will <em>overload</em> your error command (also named “north”). But if you enter a direction without
having a matching exit for it, you will fall back to your default error commands:</p>
<divclass="highlight-none notranslate"><divclass="highlight"><pre><span></span>> east
You cannot move east.
</pre></div>
</div>
<p>Further expansions by the exit system (including manipulating the way the Exit command itself is created) can be done by
modifying the <aclass="reference internal"href="../Components/Typeclasses.html"><spanclass="doc std std-doc">Exit typeclass</span></a> directly.</p>
</section>
<sectionid="why-not-a-single-command">
<h2>Why not a single command?<aclass="headerlink"href="#why-not-a-single-command"title="Permalink to this headline">¶</a></h2>
<p>So why didn’t we create a single error command above? Something like this:</p>
<p>The reason is that this would <em>not</em> work. Understanding why is important.</p>
<p>Evennia’s <aclass="reference internal"href="../Components/Commands.html"><spanclass="doc std std-doc">command system</span></a> compares commands by key and/or aliases. If <em>any</em> key or alias
match, the two commands are considered <em>identical</em>. When the cmdsets merge, priority will then decide which of these
‘identical’ commandss replace which.</p>
<p>So the above example would work fine as long as there were <em>no Exits at all</em> in the room. But when we enter
a room with an exit “north”, its Exit-command (which has a higher priority) will override the single <codeclass="docutils literal notranslate"><spanclass="pre">CmdExitError</span></code>
with its alias ‘north’. So the <codeclass="docutils literal notranslate"><spanclass="pre">CmdExitError</span></code> will be gone and while “north” will work, we’ll again get the normal
“Command not recognized” error for the other directions.</p>