<spanid="evennia-commands-cmdsethandler"></span><h1>evennia.commands.cmdsethandler<aclass="headerlink"href="#module-evennia.commands.cmdsethandler"title="Permalink to this headline">¶</a></h1>
<p>CmdSethandler</p>
<p>The Cmdsethandler tracks an object’s ‘Current CmdSet’, which is the
current merged sum of all CmdSets added to it.</p>
<p>A CmdSet constitues a set of commands. The CmdSet works as a special
intelligent container that, when added to other CmdSet make sure that
same-name commands are treated correctly (usually so there are no
doublets). This temporary but up-to-date merger of CmdSet is jointly
called the Current Cmset. It is this Current CmdSet that the
commandhandler looks through whenever an account enters a command (it
also adds CmdSets from objects in the room in real-time). All account
objects have a ‘default cmdset’ containing all the normal in-game mud
commands (look etc).</p>
<p>So what is all this cmdset complexity good for?</p>
<p>In its simplest form, a CmdSet has no commands, only a key name. In
this case the cmdset’s use is up to each individual game - it can be
used by an AI module for example (mobs in cmdset ‘roam’ move from room
to room, in cmdset ‘attack’ they enter combat with accounts).</p>
<p>Defining commands in cmdsets offer some further powerful game-design
consequences however. Here are some examples:</p>
<p>As mentioned above, all accounts always have at least the Default
CmdSet. This contains the set of all normal-use commands in-game,
stuff like look and @desc etc. Now assume our players end up in a dark
room. You don’t want the player to be able to do much in that dark
room unless they light a candle. You could handle this by changing all
your normal commands to check if the player is in a dark room. This
rapidly goes unwieldly and error prone. Instead you just define a
cmdset with only those commands you want to be available in the ‘dark’
cmdset - maybe a modified look command and a ‘light candle’ command -
and have this completely replace the default cmdset.</p>
<p>Another example: Say you want your players to be able to go
fishing. You could implement this as a ‘fish’ command that fails
whenever the account has no fishing rod. Easy enough. But what if you
want to make fishing more complex - maybe you want four-five different
commands for throwing your line, reeling in, etc? Most players won’t
(we assume) have fishing gear, and having all those detailed commands
is cluttering up the command list. And what if you want to use the
‘throw’ command also for throwing rocks etc instead of ‘using it up’
for a minor thing like fishing?</p>
<p>So instead you put all those detailed fishing commands into their own
CommandSet called ‘Fishing’. Whenever the player gives the command
‘fish’ (presumably the code checks there is also water nearby), only
THEN this CommandSet is added to the Cmdhandler of the account. The
‘throw’ command (which normally throws rocks) is replaced by the
custom ‘fishing variant’ of throw. What has happened is that the
Fishing CommandSet was merged on top of the Default ones, and due to
how we defined it, its command overrules the default ones.</p>
<p>When we are tired of fishing, we give the ‘go home’ command (or
whatever) and the Cmdhandler simply removes the fishing CommandSet
so that we are back at defaults (and can throw rocks again).</p>
<p>Since any number of CommandSets can be piled on top of each other, you
can then implement separate sets for different situations. For
example, you can have a ‘On a boat’ set, onto which you then tack on
the ‘Fishing’ set. Fishing from a boat? No problem!</p>
<codeclass="sig-prename descclassname">evennia.commands.cmdsethandler.</code><codeclass="sig-name descname">import_cmdset</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">path</span></em>, <emclass="sig-param"><spanclass="n">cmdsetobj</span></em>, <emclass="sig-param"><spanclass="n">emit_to_obj</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">no_logging</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdsethandler.html#import_cmdset"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdsethandler.import_cmdset"title="Permalink to this definition">¶</a></dt>
<dd><p>This helper function is used by the cmdsethandler to load a cmdset
instance from a python module, given a python_path. It’s usually accessed
through the cmdsethandler’s add() and add_default() methods.
path - This is the full path to the cmdset object on python dot-form</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>path</strong> (<em>str</em>) – The path to the command set to load.</p></li>
<li><p><strong>cmdsetobj</strong> (<aclass="reference internal"href="evennia.commands.cmdset.html#evennia.commands.cmdset.CmdSet"title="evennia.commands.cmdset.CmdSet"><em>CmdSet</em></a>) – The database object/typeclass on which this cmdset is to be
assigned (this can be also channels and exits, as well as accounts
but there will always be such an object)</p></li>
<li><p><strong>emit_to_obj</strong> (<em>Object</em><em>, </em><em>optional</em>) – If given, error is emitted to
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.commands.cmdsethandler.</code><codeclass="sig-name descname">CmdSetHandler</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em>, <emclass="sig-param"><spanclass="n">init_true</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdsethandler.html#CmdSetHandler"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">__init__</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em>, <emclass="sig-param"><spanclass="n">init_true</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdsethandler.html#CmdSetHandler.__init__"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.__init__"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">update</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">init_mode</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdsethandler.html#CmdSetHandler.update"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.update"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">add</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">cmdset</span></em>, <emclass="sig-param"><spanclass="n">emit_to_obj</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">persistent</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <emclass="sig-param"><spanclass="n">default_cmdset</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdsethandler.html#CmdSetHandler.add"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.add"title="Permalink to this definition">¶</a></dt>
<dd><p>Add a cmdset to the handler, on top of the old ones, unless it
is set as the default one (it will then end up at the bottom of the stack)</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>cmdset</strong> (<aclass="reference internal"href="evennia.commands.cmdset.html#evennia.commands.cmdset.CmdSet"title="evennia.commands.cmdset.CmdSet"><em>CmdSet</em></a><em> or </em><em>str</em>) – Can be a cmdset object or the python path
to such an object.</p></li>
<li><p><strong>emit_to_obj</strong> (<em>Object</em><em>, </em><em>optional</em>) – An object to receive error messages.</p></li>
<codeclass="sig-name descname">add_default</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">cmdset</span></em>, <emclass="sig-param"><spanclass="n">emit_to_obj</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">persistent</span><spanclass="o">=</span><spanclass="default_value">True</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdsethandler.html#CmdSetHandler.add_default"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.add_default"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">remove</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">cmdset</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">default_cmdset</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdsethandler.html#CmdSetHandler.remove"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.remove"title="Permalink to this definition">¶</a></dt>
<li><p><strong>cmdset</strong> (<em>CommandSet</em><em> or </em><em>str</em><em>, </em><em>optional</em>) – This can can be supplied either as a cmdset-key,
an instance of the CmdSet or a python path to the cmdset.
If no key is given, the last cmdset in the stack is
removed. Whenever the cmdset_stack changes, the cmdset is
updated. If default_cmdset is set, this argument is ignored.</p></li>
<li><p><strong>default_cmdset</strong> (<em>bool</em><em>, </em><em>optional</em>) – If set, this will remove the
default cmdset (at the bottom of the stack).</p></li>
<codeclass="sig-name descname">delete</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">cmdset</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">default_cmdset</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.delete"title="Permalink to this definition">¶</a></dt>
<li><p><strong>cmdset</strong> (<em>CommandSet</em><em> or </em><em>str</em><em>, </em><em>optional</em>) – This can can be supplied either as a cmdset-key,
an instance of the CmdSet or a python path to the cmdset.
If no key is given, the last cmdset in the stack is
removed. Whenever the cmdset_stack changes, the cmdset is
updated. If default_cmdset is set, this argument is ignored.</p></li>
<li><p><strong>default_cmdset</strong> (<em>bool</em><em>, </em><em>optional</em>) – If set, this will remove the
default cmdset (at the bottom of the stack).</p></li>
<codeclass="sig-name descname">remove_default</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdsethandler.html#CmdSetHandler.remove_default"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.remove_default"title="Permalink to this definition">¶</a></dt>
<dd><p>This explicitly deletes only the default cmdset.</p>
<codeclass="sig-name descname">delete_default</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.delete_default"title="Permalink to this definition">¶</a></dt>
<dd><p>This explicitly deletes only the default cmdset.</p>
<codeclass="sig-name descname">get</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdsethandler.html#CmdSetHandler.get"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.get"title="Permalink to this definition">¶</a></dt>
<dd><p>Get all cmdsets.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>cmdsets (list)</em>– All the command sets currently in the handler.</p>
<codeclass="sig-name descname">all</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.all"title="Permalink to this definition">¶</a></dt>
<dd><p>Get all cmdsets.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>cmdsets (list)</em>– All the command sets currently in the handler.</p>
<codeclass="sig-name descname">clear</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdsethandler.html#CmdSetHandler.clear"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.clear"title="Permalink to this definition">¶</a></dt>
<dd><p>Removes all Command Sets from the handler except the default one
(use <strong>self.remove_default</strong> to remove that).</p>
<codeclass="sig-name descname">has</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">cmdset</span></em>, <emclass="sig-param"><spanclass="n">must_be_default</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdsethandler.html#CmdSetHandler.has"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.has"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">has_cmdset</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">cmdset</span></em>, <emclass="sig-param"><spanclass="n">must_be_default</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.has_cmdset"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">reset</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdsethandler.html#CmdSetHandler.reset"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdsethandler.CmdSetHandler.reset"title="Permalink to this definition">¶</a></dt>
<dd><p>Force reload of all cmdsets in handler. This should be called
after _CACHED_CMDSETS have been cleared (normally this is