<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="Objects.html"><spanclass="doc">Exit Object</span></a> and an <aclass="reference internal"href="Commands.html"><spanclass="doc">Exit Command</span></a> stored on said exit object. The command has the same key and aliases as the object, which is why you can see the exit in the room and just write its name to traverse it.</p>
<p>If you try to enter the name of a non-existing exit, it is thus the same as trying a non-exising command; Evennia doesn’t care about the difference:</p>
<spanclass="n">Command</span><spanclass="s1">'jump out the window'</span><spanclass="ow">is</span><spanclass="ow">not</span><spanclass="n">available</span><spanclass="o">.</span><spanclass="n">Type</span><spanclass="s2">"help"</span><spanclass="k">for</span><spanclass="n">help</span><spanclass="o">.</span>
</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-default 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>
<h2>Adding default error commands<aclass="headerlink"href="#adding-default-error-commands"title="Permalink to this headline">¶</a></h2>
<p>To solve this you need to be aware of how to <aclass="reference internal"href="Adding-Command-Tutorial.html"><spanclass="doc">write and add new commands</span></a>. What you need to do is to create new commands for all directions you want to support in your game. In this example all we’ll do is echo an error message, but you could certainly consider more advanced uses. You add these commands to the default command set. Here is an example of such a set of commands:</p>
28</pre></div></td><tdclass="code"><divclass="highlight"><pre><span></span><spanclass="c1"># for example in a file mygame/commands/movecommands.py</span>
<p>Make sure to add the directional commands (not their parent) to the <codeclass="docutils literal notranslate"><spanclass="pre">CharacterCmdSet</span></code> class in <codeclass="docutils literal notranslate"><spanclass="pre">mygame/commands/default_cmdsets.py</span></code>:</p>
<p>After a <codeclass="docutils literal notranslate"><spanclass="pre">@reload</span></code> these commands (assuming you don’t get any errors - check your log) will be loaded. 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 overload your error command (also named “north”). But if you enter an direction without having a matching exit for it, you will fallback to your default error commands:</p>
<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="Typeclasses.html"><spanclass="doc">Exit typeclass</span></a> directly.</p>
</div>
<divclass="section"id="additional-comments">
<h2>Additional Comments<aclass="headerlink"href="#additional-comments"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 anwer is that this would <em>not</em> work and understanding why is important in order to not be confused when working with commands and command sets.</p>
<p>The reason it doesn’t work is because Evennia’s <aclass="reference internal"href="Commands.html"><spanclass="doc">command system</span></a> compares commands <em>both</em> by <codeclass="docutils literal notranslate"><spanclass="pre">key</span></code> and by <codeclass="docutils literal notranslate"><spanclass="pre">aliases</span></code>. If <em>either</em> of those match, the two commands are considered <em>identical</em> as far as cmdset merging system is concerned.</p>
<p>So the above example would work fine as long as there were no Exits at all in the room. But what happens when we enter a room with an exit “north”? The Exit’s cmdset is merged onto the default one, and since there is an alias match, the system determines our <codeclass="docutils literal notranslate"><spanclass="pre">CmdExitError</span></code> to be identical. It is thus overloaded by the Exit command (which also correctly defaults to a higher priority). The result is that you can go through the north exit normally but none of the error messages for the other directions are available since the single error command was completely overloaded by the single matching “north” exit-command.</p>