<h1>Nicks<aclass="headerlink"href="#nicks"title="Permalink to this headline">¶</a></h1>
<p><em>Nicks</em>, short for <em>Nicknames</em> is a system allowing an object (usually a <aclass="reference internal"href="Accounts.html"><spanclass="doc">Account</span></a>) to assign custom replacement names for other game entities.</p>
<p>Nicks are not to be confused with <em>Aliases</em>. Setting an Alias on a game entity actually changes an inherent attribute on that entity, and everyone in the game will be able to use that alias to address the entity thereafter. A <em>Nick</em> on the other hand, is used to map a different way <em>you alone</em> can refer to that entity. Nicks are also commonly used to replace your input text which means you can create your own aliases to default commands.</p>
<p>Default Evennia use Nicks in three flavours that determine when Evennia actually tries to do the substitution.</p>
<ulclass="simple">
<li><p>inputline - replacement is attempted whenever you write anything on the command line. This is the default.</p></li>
<li><p>objects - replacement is only attempted when referring to an object</p></li>
<li><p>accounts - replacement is only attempted when referring an account</p></li>
</ul>
<p>Here’s how to use it in the default command set (using the <codeclass="docutils literal notranslate"><spanclass="pre">nick</span></code> command):</p>
<p>This is a good one for unix/linux users who are accustomed to using the <codeclass="docutils literal notranslate"><spanclass="pre">ls</span></code> command in their daily life. It is equivalent to <codeclass="docutils literal notranslate"><spanclass="pre">nick/inputline</span><spanclass="pre">ls</span><spanclass="pre">=</span><spanclass="pre">look</span></code>.</p>
<p>One can use nicks to speed up input. Below we add ourselves a quicker way to build red buttons. In the future just writing <em>rb</em> will be enough to execute that whole long string.</p>
<p>The nick replacer also supports unix-style <em>templating</em>:</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span> nick build $1 $2 = @create/drop $1;$2
</pre></div>
</div>
<p>This will catch space separated arguments and store them in the the tags <codeclass="docutils literal notranslate"><spanclass="pre">$1</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">$2</span></code>, to be inserted in the replacement string. This example allows you to do <codeclass="docutils literal notranslate"><spanclass="pre">build</span><spanclass="pre">box</span><spanclass="pre">crate</span></code> and have Evennia see <codeclass="docutils literal notranslate"><spanclass="pre">@create/drop</span><spanclass="pre">box;crate</span></code>. You may use any <codeclass="docutils literal notranslate"><spanclass="pre">$</span></code> numbers between 1 and 99, but the markers must match between the nick pattern and the replacement.</p>
<blockquote>
<div><p>If you want to catch “the rest” of a command argument, make sure to put a <codeclass="docutils literal notranslate"><spanclass="pre">$</span></code> tag <em>with no spaces to the right of it</em> - it will then receive everything up until the end of the line.</p>
</div></blockquote>
<p>You can also use <aclass="reference external"href="http://www.linfo.org/wildcard.html">shell-type wildcards</a>:</p>
<ulclass="simple">
<li><p>* - matches everything.</p></li>
<li><p>? - matches a single character.</p></li>
<li><p>[seq] - matches everything in the sequence, e.g. [xyz] will match both x, y and z</p></li>
<li><p>[!seq] - matches everything <em>not</em> in the sequence. e.g. [!xyz] will match all but x,y z.</p></li>
</ul>
<divclass="section"id="coding-with-nicks">
<h2>Coding with nicks<aclass="headerlink"href="#coding-with-nicks"title="Permalink to this headline">¶</a></h2>
<p>Nicks are stored as the <codeclass="docutils literal notranslate"><spanclass="pre">Nick</span></code> database model and are referred from the normal Evennia <aclass="reference internal"href="Objects.html"><spanclass="doc">object</span></a> through the <codeclass="docutils literal notranslate"><spanclass="pre">nicks</span></code> property - this is known as the <em>NickHandler</em>. The NickHandler offers effective error checking, searches and conversion.</p>
17</pre></div></td><tdclass="code"><divclass="highlight"><pre><span></span><spanclass="c1"># A command/channel nick:</span>
<spanclass="n">obj</span><spanclass="o">.</span><spanclass="n">nicks</span><spanclass="o">.</span><spanclass="n">add</span><spanclass="p">(</span><spanclass="s2">"greetjack"</span><spanclass="p">,</span><spanclass="s2">"tell Jack = Hello pal!"</span><spanclass="p">)</span>
<spanclass="c1"># An object nick: </span>
<spanclass="n">obj</span><spanclass="o">.</span><spanclass="n">nicks</span><spanclass="o">.</span><spanclass="n">add</span><spanclass="p">(</span><spanclass="s2">"rose"</span><spanclass="p">,</span><spanclass="s2">"The red flower"</span><spanclass="p">,</span><spanclass="n">nick_type</span><spanclass="o">=</span><spanclass="s2">"object"</span><spanclass="p">)</span>
<p>In a command definition you can reach the nick handler through <codeclass="docutils literal notranslate"><spanclass="pre">self.caller.nicks</span></code>. See the <codeclass="docutils literal notranslate"><spanclass="pre">nick</span></code> command in <codeclass="docutils literal notranslate"><spanclass="pre">evennia/commands/default/general.py</span></code> for more examples.</p>
<p>As a last note, The Evennia <aclass="reference internal"href="Communications.html"><spanclass="doc">channel</span></a> alias systems are using nicks with the <codeclass="docutils literal notranslate"><spanclass="pre">nick_type="channel"</span></code> in order to allow users to create their own custom aliases to channels.</p>
</div>
</div>
<divclass="section"id="advanced-note">
<h1>Advanced note<aclass="headerlink"href="#advanced-note"title="Permalink to this headline">¶</a></h1>
<p>Internally, nicks are <aclass="reference internal"href="Attributes.html"><spanclass="doc">Attributes</span></a> saved with the <codeclass="docutils literal notranslate"><spanclass="pre">db_attrype</span></code> set to “nick” (normal Attributes has this set to <codeclass="docutils literal notranslate"><spanclass="pre">None</span></code>).</p>
<p>The nick stores the replacement data in the Attribute.db_value field as a tuple with four fields <codeclass="docutils literal notranslate"><spanclass="pre">(regex_nick,</span><spanclass="pre">template_string,</span><spanclass="pre">raw_nick,</span><spanclass="pre">raw_template)</span></code>. Here <codeclass="docutils literal notranslate"><spanclass="pre">regex_nick</span></code> is the converted regex representation of the <codeclass="docutils literal notranslate"><spanclass="pre">raw_nick</span></code> and the <codeclass="docutils literal notranslate"><spanclass="pre">template-string</span></code> is a version of the <codeclass="docutils literal notranslate"><spanclass="pre">raw_template</span></code> prepared for efficient replacement of any <codeclass="docutils literal notranslate"><spanclass="pre">$</span></code>- type markers. The <codeclass="docutils literal notranslate"><spanclass="pre">raw_nick</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">raw_template</span></code> are basically the unchanged strings you enter to the <codeclass="docutils literal notranslate"><spanclass="pre">nick</span></code> command (with unparsed <codeclass="docutils literal notranslate"><spanclass="pre">$</span></code> etc).</p>
<p>If you need to access the tuple for some reason, here’s how:</p>