<pclass="last">You are reading an old version of the Evennia documentation. <ahref="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
<h1>Containers<aclass="headerlink"href="#containers"title="Permalink to this headline">¶</a></h1>
<p>Contribution by InspectorCaracal (2023)</p>
<p>Adds the ability to put objects into other container objects by providing a container typeclass and extending certain base commands.</p>
<sectionid="installation">
<h2>Installation<aclass="headerlink"href="#installation"title="Permalink to this headline">¶</a></h2>
<p>To install, import and add the <codeclass="docutils literal notranslate"><spanclass="pre">ContainerCmdSet</span></code> to <codeclass="docutils literal notranslate"><spanclass="pre">CharacterCmdSet</span></code> in your <codeclass="docutils literal notranslate"><spanclass="pre">default_cmdsets.py</span></code> file:</p>
<p>This will replace the default <codeclass="docutils literal notranslate"><spanclass="pre">look</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">get</span></code> commands with the container-friendly versions provided by the contrib as well as add a new <codeclass="docutils literal notranslate"><spanclass="pre">put</span></code> command.</p>
</section>
<sectionid="usage">
<h2>Usage<aclass="headerlink"href="#usage"title="Permalink to this headline">¶</a></h2>
<p>The contrib includes a <codeclass="docutils literal notranslate"><spanclass="pre">ContribContainer</span></code> typeclass which has all of the set-up necessary to be used as a container. To use, all you need to do is create an object in-game with that typeclass - it will automatically inherit anything you implemented in your base Object typeclass as well.</p>
<p>The contrib’s <codeclass="docutils literal notranslate"><spanclass="pre">ContribContainer</span></code> comes with a capacity limit of a maximum number of items it can hold. This can be changed per individual object.</p>
<p>You can also make any other objects usable as containers by setting the <codeclass="docutils literal notranslate"><spanclass="pre">get_from</span></code> lock type on it.</p>
<h2>Extending<aclass="headerlink"href="#extending"title="Permalink to this headline">¶</a></h2>
<p>The <codeclass="docutils literal notranslate"><spanclass="pre">ContribContainer</span></code> class is intended to be usable as-is, but you can also inherit from it for your own container classes to extend its functionality. Aside from having the container lock pre-set on object creation, it comes with three main additions:</p>
<sectionid="capacity-property">
<h3><codeclass="docutils literal notranslate"><spanclass="pre">capacity</span></code> property<aclass="headerlink"href="#capacity-property"title="Permalink to this headline">¶</a></h3>
<p><codeclass="docutils literal notranslate"><spanclass="pre">ContribContainer.capacity</span></code> is an <codeclass="docutils literal notranslate"><spanclass="pre">AttributeProperty</span></code> - meaning you can access it in code with <codeclass="docutils literal notranslate"><spanclass="pre">obj.capacity</span></code> and also set it in game with <codeclass="docutils literal notranslate"><spanclass="pre">set</span><spanclass="pre">obj/capacity</span><spanclass="pre">=</span><spanclass="pre">5</span></code> - which represents the capacity of the container as an integer. You can override this with a more complex representation of capacity on your own container classes.</p>
<h3><codeclass="docutils literal notranslate"><spanclass="pre">at_pre_get_from</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">at_pre_put_in</span></code> methods<aclass="headerlink"href="#at-pre-get-from-and-at-pre-put-in-methods"title="Permalink to this headline">¶</a></h3>
<p>These two methods on <codeclass="docutils literal notranslate"><spanclass="pre">ContribContainer</span></code> are called as extra checks when attempting to either get an object from, or put an object in, a container. The contrib’s <codeclass="docutils literal notranslate"><spanclass="pre">ContribContainer.at_pre_get_from</span></code> doesn’t do any additional validation by default, while <codeclass="docutils literal notranslate"><spanclass="pre">ContribContainer.at_pre_put_in</span></code> does a simple capacity check.</p>
<p>You can override these methods on your own child class to do any additional capacity or access checks.</p>
<hrclass="docutils"/>
<p><small>This document page is generated from <codeclass="docutils literal notranslate"><spanclass="pre">evennia/contrib/game_systems/containers/README.md</span></code>. Changes to this
file will be overwritten, so edit that file rather than this one.</small></p>
<pclass="last">You are reading an old version of the Evennia documentation. <ahref="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
</div>
<divclass="footer"role="contentinfo">
© Copyright 2023, The Evennia developer community.
Created using <ahref="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.