<linkrel="next"title="How To Contribute And Get Help"href="../Contributing.html"/>
<linkrel="prev"title="Pseudo-random generator and registry"href="Contrib-Random-String-Generator.html"/>
</head><body>
<divclass="admonition important">
<pclass="first admonition-title">Note</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>.
<h1>Easy menu selection tree<aclass="headerlink"href="#easy-menu-selection-tree"title="Permalink to this headline">¶</a></h1>
<p>Contribution by Tim Ashley Jenkins, 2017</p>
<p>This utility allows you to create and initialize an entire branching EvMenu
instance from a multi-line string passed to one function.</p>
<blockquote>
<div><p>Note: Since the time this contrib was created, EvMenu itself got its own templating
language that has more features and is not compatible with the style used in
this contrib. Both can still be used in parallel.</p>
</div></blockquote>
<p><codeclass="docutils literal notranslate"><spanclass="pre">EvMenu</span></code> is incredibly powerful and flexible but it can be a little overwhelming
and offers a lot of power that may not be needed for a simple multiple-choice menu.</p>
<p>This module provides a function, <codeclass="docutils literal notranslate"><spanclass="pre">init_tree_selection</span></code>, which acts as a frontend
for EvMenu, dynamically sourcing the options from a multi-line string you
provide. For example, if you define a string as such:</p>
<p>The index of the selection is given along with a string containing the
selection’s key. That way, if you have two selections in the menu with the same
key, you can still differentiate between them.</p>
<p>And that’s all there is to it! For simple branching-tree selections, using this
system is much easier than manually creating EvMenu nodes. It also makes
generating menus with dynamic options much easier - since the source of the menu
tree is just a string, you could easily generate that string procedurally before
passing it to the <codeclass="docutils literal notranslate"><spanclass="pre">init_tree_selection</span></code> function. For example, if a player casts
a spell or does an attack without specifying a target, instead of giving them an
error, you could present them with a list of valid targets to select by
generating a multi-line string of targets and passing it to
<codeclass="docutils literal notranslate"><spanclass="pre">init_tree_selection</span></code>, with the callable performing the maneuver once a
selection is made.</p>
<p>This selection system only works for simple branching trees - doing anything
really complicated like jumping between categories or prompting for arbitrary
input would still require a full EvMenu implementation. For simple selections,
however, I’m sure you will find using this function to be much easier!</p>
<p>Included in this module is a sample menu and function which will let a player
change the color of their name - feel free to mess with it to get a feel for how
this system works by importing this module in your game’s <codeclass="docutils literal notranslate"><spanclass="pre">default_cmdsets.py</span></code>
module and adding <codeclass="docutils literal notranslate"><spanclass="pre">CmdNameColor</span></code> to your default character’s command set.</p>
<hrclass="docutils"/>
<p><small>This document page is generated from <codeclass="docutils literal notranslate"><spanclass="pre">evennia/contrib/utils/tree_select/README.md</span></code>. Changes to this
file will be overwritten, so edit that file rather than this one.</small></p>
<liclass="nav-item nav-item-this"><ahref="">Easy menu selection tree</a></li>
</ul>
</div>
<divclass="admonition important">
<pclass="first admonition-title">Note</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.