Fix legacy 2.0 docs

This commit is contained in:
Griatch 2023-12-20 18:20:52 +01:00
parent c71092825f
commit 7716ce9612
3968 changed files with 11058 additions and 560326 deletions

View file

@ -17,12 +17,10 @@
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Part 1: What We Have" href="Part1/Beginner-Tutorial-Part1-Overview.html" />
<link rel="prev" title="Tutorials and How-Tos" href="../Howtos-Overview.html" />
<link rel="next" title="Part 1: What we have" href="Part1/Beginner-Tutorial-Part1-Overview.html" />
<link rel="prev" title="Tutorials and Howtos" href="../Howtos-Overview.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -34,16 +32,20 @@
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="Part1/Beginner-Tutorial-Part1-Overview.html" title="Part 1: What We Have"
<a href="Part1/Beginner-Tutorial-Part1-Overview.html" title="Part 1: What we have"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="../Howtos-Overview.html" title="Tutorials and How-Tos"
<a href="../Howtos-Overview.html" title="Tutorials and Howtos"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../Howtos-Overview.html" accesskey="U">Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../Howtos-Overview.html" accesskey="U">Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Beginner Tutorial</a></li>
</ul>
</div>
</div>
<div class="document">
@ -66,11 +68,11 @@
<h3><a href="../../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Beginner Tutorial</a><ul>
<li><a class="reference internal" href="#things-you-need">Things You Need</a><ul>
<li><a class="reference internal" href="#a-command-line-interface">A Command Line Interface</a></li>
<li><a class="reference internal" href="#a-fresh-game-dir">A Fresh Game-Dir?</a></li>
<li><a class="reference internal" href="#a-mud-client">A MUD Client</a></li>
<li><a class="reference internal" href="#a-text-editor-or-ide">A Text Editor or IDE</a></li>
<li><a class="reference internal" href="#things-you-need">Things you need</a><ul>
<li><a class="reference internal" href="#a-command-line">A Command line</a></li>
<li><a class="reference internal" href="#a-fresh-game-dir">A fresh game dir?</a></li>
<li><a class="reference internal" href="#a-mud-client">A MUD client</a></li>
<li><a class="reference internal" href="#a-text-editor-or-ide">A text Editor or IDE</a></li>
</ul>
</li>
</ul>
@ -79,10 +81,10 @@
<h4>Previous topic</h4>
<p class="topless"><a href="../Howtos-Overview.html"
title="previous chapter">Tutorials and How-Tos</a></p>
title="previous chapter">Tutorials and Howtos</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="Part1/Beginner-Tutorial-Part1-Overview.html"
title="next chapter">Part 1: What We Have</a></p>
title="next chapter">Part 1: What we have</a></p>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
@ -101,18 +103,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Overview.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -125,76 +115,77 @@
<ul class="simple">
<li><p><strong><a class="reference internal" href="#"><span class="doc std std-doc">Introduction</span></a></strong>
<br>Getting set up.</p></li>
<li><p>Part 1: <a class="reference internal" href="Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">What We Have</span></a>
<li><p>Part 1: <a class="reference internal" href="Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">What we have</span></a>
<br>A tour of Evennia and how to use the tools, including an introduction to Python.</p></li>
<li><p>Part 2: <a class="reference internal" href="Part2/Beginner-Tutorial-Part2-Overview.html"><span class="doc std std-doc">What We Want</span></a>
<br>Planning our tutorial game and what to consider when planning your own.</p></li>
<li><p>Part 3: <a class="reference internal" href="Part3/Beginner-Tutorial-Part3-Overview.html"><span class="doc std std-doc">How We Get There</span></a>
<br>Getting down to the meat of extending Evennia to make your game.</p></li>
<li><p>Part 4: <a class="reference internal" href="Part4/Beginner-Tutorial-Part4-Overview.html"><span class="doc std std-doc">Using What We Created</span></a>
<br>Building a tech-demo and world content to go with our code.</p></li>
<li><p>Part 5: <a class="reference internal" href="Part5/Beginner-Tutorial-Part5-Overview.html"><span class="doc std std-doc">Showing the World</span></a>
<br>Taking our new game online and letting players try it out.</p></li>
<li><p>Part 2: <a class="reference internal" href="Part2/Beginner-Tutorial-Part2-Overview.html"><span class="doc std std-doc">What we want</span></a>
<br>Planning our tutorial game and what to think about when planning your own in the future.</p></li>
<li><p>Part 3: <a class="reference internal" href="Part3/Beginner-Tutorial-Part3-Overview.html"><span class="doc std std-doc">How we get there</span></a>
<br>Getting down to the meat of extending Evennia to make our game</p></li>
<li><p>Part 4: <a class="reference internal" href="Part4/Beginner-Tutorial-Part4-Overview.html"><span class="doc std std-doc">Using what we created</span></a>
<br>Building a tech-demo and world content to go with our code</p></li>
<li><p>Part 5: <a class="reference internal" href="Part5/Beginner-Tutorial-Part5-Overview.html"><span class="doc std std-doc">Showing the world</span></a>
<br>Taking our new game online and let players try it out</p></li>
</ul>
</aside>
<p>Welcome to Evennia! This multi-part Beginner Tutorial will help get you off the ground and running.</p>
<p>You may choose topics that seem interesting but, if you follow this tutorial through to the end, you will have created your own small online game to play and share with others!</p>
<p>Use the menu on the right to navigate the index of each of the tutorials parts. Use the <a class="reference internal" href="Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">next</span></a> and <a class="reference internal" href="../Howtos-Overview.html"><span class="doc std std-doc">previous</span></a> links at the top/bottom right of each page to jump between lessons.</p>
<p>Welcome to Evennia! This multi-part Beginner Tutorial will help you get off the ground.</p>
<p>You can pick what seems interesting, but if you follow through to the end you will have created a little online game of your own to play and share with others!</p>
<p>Use the menu on the right to get the index of each tutorial-part. Use the <a class="reference internal" href="Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">next</span></a> and <a class="reference internal" href="../Howtos-Overview.html"><span class="doc std std-doc">previous</span></a> links at the top/bottom right of the page to step between lessons.</p>
<section id="things-you-need">
<h2>Things You Need<a class="headerlink" href="#things-you-need" title="Permalink to this headline"></a></h2>
<h2>Things you need<a class="headerlink" href="#things-you-need" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p>A command line interface</p></li>
<li><p>A Command line</p></li>
<li><p>A MUD client (or web browser)</p></li>
<li><p>A text-editor/IDE</p></li>
<li><p>Evennia installed and a game-dir initialized</p></li>
</ul>
<section id="a-command-line-interface">
<h3>A Command Line Interface<a class="headerlink" href="#a-command-line-interface" title="Permalink to this headline"></a></h3>
<p>You need to know how to find the terminal/console in your OS. The Evennia server can be controlled from in-game, but you <em>will</em> realistically need to use the command-line interface to get anywhere. Here are some starters:</p>
<section id="a-command-line">
<h3>A Command line<a class="headerlink" href="#a-command-line" title="Permalink to this headline"></a></h3>
<p>You need to know how to find your Terminal/Console in your OS. The Evennia server can be controlled from in-game, but you <em>will</em> need to use the command-line to get anywhere. Here are some starters:</p>
<ul class="simple">
<li><p><a class="reference external" href="https://tutorial.djangogirls.org/en/intro_to_command_line/">Online Intro to the Command line for different OS:es</a></p></li>
</ul>
<blockquote>
<div><p>Note that the documentation typically uses forward-slashes (<code class="docutils literal notranslate"><span class="pre">/</span></code>) for file system paths. Windows users should convert these to back-slashes (<code class="docutils literal notranslate"><span class="pre">\</span></code>) instead.</p>
<div><p>Note that we usually only show forward-slashes <code class="docutils literal notranslate"><span class="pre">/</span></code> for file system paths. Windows users should mentally convert this to back-slashes <code class="docutils literal notranslate"><span class="pre">\</span></code> instead.</p>
</div></blockquote>
</section>
<section id="a-fresh-game-dir">
<h3>A Fresh Game-Dir?<a class="headerlink" href="#a-fresh-game-dir" title="Permalink to this headline"></a></h3>
<p>You should make sure that you have successfully <a class="reference internal" href="../../Setup/Installation.html"><span class="doc std std-doc">installed Evennia</span></a>. If you followed the instructions, you will have already created a game-dir. The documentation will continue to refer to this game-dir as <code class="docutils literal notranslate"><span class="pre">mygame</span></code>, so you may want to re-use it or make a new one specific to this tutorial only its up to you.</p>
<p>If you already have a game-dir and want a new one specific to this tutorial, use the <code class="docutils literal notranslate"><span class="pre">evennia</span> <span class="pre">stop</span></code> command to halt the running server. Then, <a class="reference internal" href="../../Setup/Installation.html#initialize-a-new-game"><span class="std std-doc">initialize a new game-dir</span></a> somewhere else (<em>not</em> inside the previous game-dir!).</p>
<h3>A fresh game dir?<a class="headerlink" href="#a-fresh-game-dir" title="Permalink to this headline"></a></h3>
<p>You should make sure you have successfully <a class="reference internal" href="../../Setup/Installation.html"><span class="doc std std-doc">installed Evennia</span></a>. If you followed the instructions you will already have created a game-dir. You could re-use that or make a new one only for this tutorial, its up to you.</p>
<p>If you already have a game dir and want a separate one for the tutorial, use <code class="docutils literal notranslate"><span class="pre">evennia</span> <span class="pre">stop</span></code> to halt the running server and then <a class="reference internal" href="../../Setup/Installation.html#initialize-a-new-game"><span class="std std-doc">Initialize a new game dir</span></a> somewhere else (<em>not</em> inside the previous game dir!). We refer to it everywhere as <code class="docutils literal notranslate"><span class="pre">mygame</span></code>, so you may want to use that name too.</p>
</section>
<section id="a-mud-client">
<h3>A MUD Client<a class="headerlink" href="#a-mud-client" title="Permalink to this headline"></a></h3>
<p>You may already have a preferred MUD client. Check out the <a class="reference internal" href="../../Setup/Client-Support-Grid.html"><span class="doc std std-doc">grid of supported clients</span></a>. Or, if telnets not your thing, you may also simply use Evennias web-client in your preferred browser.</p>
<p>Make sure you know how to connect and log in to your locally running Evennia server.</p>
<h3>A MUD client<a class="headerlink" href="#a-mud-client" title="Permalink to this headline"></a></h3>
<p>You might already have a MUD-client you prefer. Check out the <a class="reference internal" href="../../Setup/Client-Support-Grid.html"><span class="doc std std-doc">grid of supported clients</span></a>.
If telnets not your thing, you can also just use Evennias web client in your browser.</p>
<p>Make sure you know how to connect to and log in to your locally running Evennia server.</p>
<blockquote>
<div><p>In this documentation we often interchangeably use the terms MUD, MU, and MU* to represent all the historically different forms of text-based multiplayer game-styles (i.e., MUD, MUX, MUSH, MUCK, MOO, etc.). Evennia can be used to create any of these game-styles… and more!</p>
<div><p>In this documentation we often use the terms MUD, MU or MU* interchangeably to represent all the historically different forms of text-based multiplayer game-styles, like MUD, MUX, MUSH, MUCK, MOO and others. Evennia can be used to create all those game-styles and more.</p>
</div></blockquote>
</section>
<section id="a-text-editor-or-ide">
<h3>A Text Editor or IDE<a class="headerlink" href="#a-text-editor-or-ide" title="Permalink to this headline"></a></h3>
<p>You need a text editor application to edit Python source files. Most anything that can edit and output raw text should work (…so not Microsoft Word).</p>
<h3>A text Editor or IDE<a class="headerlink" href="#a-text-editor-or-ide" title="Permalink to this headline"></a></h3>
<p>You need a text-editor to edit Python source files. Most everything that can edit and output raw text works (so not Word).</p>
<ul class="simple">
<li><p><a class="reference external" href="https://www.elegantthemes.com/blog/resources/best-code-editors">Heres a blog post summing up a variety of text editor options</a> - these things dont change much from year to year. Popular choices for Python are PyCharm, VSCode, Atom, Sublime Text, and Notepad++. Evennia is to a very large degree coded in VIM, but it is not suitable for beginners.</p></li>
<li><p><a class="reference external" href="https://www.elegantthemes.com/blog/resources/best-code-editors">Heres a blog post summing up some of the alternatives</a> - these things dont change much from year to year. Popular choices for Python are PyCharm, VSCode, Atom, Sublime Text and Notepad++. Evennia is to a very large degree coded in VIM, but thats not suitable for beginners.</p></li>
</ul>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>Use Spaces, Not Tabs&lt; br/&gt;
Make sure to configure your text editor so that pressing the Tab key inserts <em>4 spaces</em> rather than a tab-character. Because Python is whitespace-aware, this simple practice will make your life much easier.</p>
<p>Use spaces, not tabs
Make sure to configure your editor so that pressing TAB inserts <em>4 spaces</em> rather than a Tab-character. Since Python is whitespace-aware, this will make your life a lot easier.</p>
</div>
<p>You should now be ready to move on to the <a class="reference internal" href="Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">first part of the Beginner Tutorial</span></a>! (In the future, use the <code class="docutils literal notranslate"><span class="pre">previous</span> <span class="pre">|</span> <span class="pre">next</span></code> buttons on the top/bottom of the page to progress.)</p>
<p>You should now be ready to move on to the <a class="reference internal" href="Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">first part of the tutorial</span></a> (in the future, use the <code class="docutils literal notranslate"><span class="pre">previous</span> <span class="pre">|</span> <span class="pre">next</span></code> buttons on the top/bottom of the page to progress)!</p>
<details>
<summary>
Click here to see the full index of all parts and lessons of the Beginner-Tutorial.
</summary>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="Part1/Beginner-Tutorial-Part1-Overview.html">Part 1: What We Have</a><ul>
<li class="toctree-l1"><a class="reference internal" href="Part1/Beginner-Tutorial-Part1-Overview.html">Part 1: What we have</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Part1/Beginner-Tutorial-Part1-Overview.html#lessons">Lessons</a><ul>
<li class="toctree-l3"><a class="reference internal" href="Part1/Beginner-Tutorial-Building-Quickstart.html">1. Using Commands and Building Stuff</a><ul>
<li class="toctree-l4"><a class="reference internal" href="Part1/Beginner-Tutorial-Building-Quickstart.html#getting-help">1.1. Getting Help</a></li>
<li class="toctree-l4"><a class="reference internal" href="Part1/Beginner-Tutorial-Building-Quickstart.html#looking-around">1.2. Looking Around</a></li>
<li class="toctree-l4"><a class="reference internal" href="Part1/Beginner-Tutorial-Building-Quickstart.html#stepping-down-from-godhood">1.3. Stepping Down from Godhood</a></li>
<li class="toctree-l3"><a class="reference internal" href="Part1/Beginner-Tutorial-Building-Quickstart.html">1. Using commands and building stuff</a><ul>
<li class="toctree-l4"><a class="reference internal" href="Part1/Beginner-Tutorial-Building-Quickstart.html#getting-help">1.1. Getting help</a></li>
<li class="toctree-l4"><a class="reference internal" href="Part1/Beginner-Tutorial-Building-Quickstart.html#looking-around">1.2. Looking around</a></li>
<li class="toctree-l4"><a class="reference internal" href="Part1/Beginner-Tutorial-Building-Quickstart.html#stepping-down-from-godhood">1.3. Stepping Down From Godhood</a></li>
<li class="toctree-l4"><a class="reference internal" href="Part1/Beginner-Tutorial-Building-Quickstart.html#creating-an-object">1.4. Creating an Object</a></li>
<li class="toctree-l4"><a class="reference internal" href="Part1/Beginner-Tutorial-Building-Quickstart.html#get-a-personality">1.5. Get a Personality</a></li>
<li class="toctree-l4"><a class="reference internal" href="Part1/Beginner-Tutorial-Building-Quickstart.html#pushing-your-buttons">1.6. Pushing Your Buttons</a></li>
@ -291,8 +282,7 @@ Click here to see the full index of all parts and lessons of the Beginner-Tutori
<li class="toctree-l3"><a class="reference internal" href="Part1/Beginner-Tutorial-Adding-Commands.html">8. Adding custom commands</a><ul>
<li class="toctree-l4"><a class="reference internal" href="Part1/Beginner-Tutorial-Adding-Commands.html#creating-a-custom-command">8.1. Creating a custom command</a><ul>
<li class="toctree-l5"><a class="reference internal" href="Part1/Beginner-Tutorial-Adding-Commands.html#making-our-cmdset-persistent">8.1.1. Making our cmdset persistent</a></li>
<li class="toctree-l5"><a class="reference internal" href="Part1/Beginner-Tutorial-Adding-Commands.html#add-the-echo-command-to-the-default-cmdset">8.1.2. Add the echo command to the default cmdset</a></li>
<li class="toctree-l5"><a class="reference internal" href="Part1/Beginner-Tutorial-Adding-Commands.html#figuring-out-who-to-hit">8.1.3. Figuring out who to hit</a></li>
<li class="toctree-l5"><a class="reference internal" href="Part1/Beginner-Tutorial-Adding-Commands.html#figuring-out-who-to-hit">8.1.2. Figuring out who to hit</a></li>
</ul>
</li>
<li class="toctree-l4"><a class="reference internal" href="Part1/Beginner-Tutorial-Adding-Commands.html#summary">8.2. Summary</a></li>
@ -370,7 +360,7 @@ Click here to see the full index of all parts and lessons of the Beginner-Tutori
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Part2/Beginner-Tutorial-Part2-Overview.html">Part 2: What We Want</a><ul>
<li class="toctree-l1"><a class="reference internal" href="Part2/Beginner-Tutorial-Part2-Overview.html">Part 2: What we want</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Part2/Beginner-Tutorial-Part2-Overview.html#lessons">Lessons</a><ul>
<li class="toctree-l3"><a class="reference internal" href="Part2/Beginner-Tutorial-Planning-Where-Do-I-Begin.html">1. Where do I begin?</a><ul>
<li class="toctree-l4"><a class="reference internal" href="Part2/Beginner-Tutorial-Planning-Where-Do-I-Begin.html#what-is-your-motivation-for-doing-this">1.1. What is your motivation for doing this?</a></li>
@ -461,7 +451,7 @@ Click here to see the full index of all parts and lessons of the Beginner-Tutori
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Part3/Beginner-Tutorial-Part3-Overview.html">Part 3: How We Get There (Example Game)</a><ul>
<li class="toctree-l1"><a class="reference internal" href="Part3/Beginner-Tutorial-Part3-Overview.html">Part 3: How we get there (example game)</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Part3/Beginner-Tutorial-Part3-Overview.html#lessons">Lessons</a><ul>
<li class="toctree-l3"><a class="reference internal" href="Part3/Beginner-Tutorial-Utilities.html">1. Code structure and Utilities</a><ul>
<li class="toctree-l4"><a class="reference internal" href="Part3/Beginner-Tutorial-Utilities.html#folder-structure">1.1. Folder structure</a></li>
@ -538,10 +528,7 @@ Click here to see the full index of all parts and lessons of the Beginner-Tutori
<li class="toctree-l4"><a class="reference internal" href="Part3/Beginner-Tutorial-Equipment.html#add-and-remove">5.5. <code class="docutils literal notranslate"><span class="pre">.add</span></code> and <code class="docutils literal notranslate"><span class="pre">.remove</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="Part3/Beginner-Tutorial-Equipment.html#moving-things-around">5.6. Moving things around</a></li>
<li class="toctree-l4"><a class="reference internal" href="Part3/Beginner-Tutorial-Equipment.html#get-everything">5.7. Get everything</a></li>
<li class="toctree-l4"><a class="reference internal" href="Part3/Beginner-Tutorial-Equipment.html#weapon-and-armor">5.8. Weapon and armor</a><ul>
<li class="toctree-l5"><a class="reference internal" href="Part3/Beginner-Tutorial-Equipment.html#fixing-the-character-class">5.8.1. Fixing the Character class</a></li>
</ul>
</li>
<li class="toctree-l4"><a class="reference internal" href="Part3/Beginner-Tutorial-Equipment.html#weapon-and-armor">5.8. Weapon and armor</a></li>
<li class="toctree-l4"><a class="reference internal" href="Part3/Beginner-Tutorial-Equipment.html#extra-credits">5.9. Extra credits</a></li>
<li class="toctree-l4"><a class="reference internal" href="Part3/Beginner-Tutorial-Equipment.html#unit-testing">5.10. Unit Testing</a></li>
<li class="toctree-l4"><a class="reference internal" href="Part3/Beginner-Tutorial-Equipment.html#summary">5.11. Summary</a></li>
@ -670,14 +657,14 @@ Click here to see the full index of all parts and lessons of the Beginner-Tutori
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Part4/Beginner-Tutorial-Part4-Overview.html">Part 4: Using What We Created</a><ul>
<li class="toctree-l1"><a class="reference internal" href="Part4/Beginner-Tutorial-Part4-Overview.html">Part 4: Using what we created</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Part4/Beginner-Tutorial-Part4-Overview.html#lessons">Lessons</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../Unimplemented.html">1. Unimplemented</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Part5/Beginner-Tutorial-Part5-Overview.html">Part 5: Showing the World</a><ul>
<li class="toctree-l1"><a class="reference internal" href="Part5/Beginner-Tutorial-Part5-Overview.html">Part 5: Showing the world</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Part5/Beginner-Tutorial-Part5-Overview.html#lessons">Lessons</a><ul>
<li class="toctree-l3"><a class="reference internal" href="Part5/Add-a-simple-new-web-page.html">1. Add a simple new web page</a><ul>
<li class="toctree-l4"><a class="reference internal" href="Part5/Add-a-simple-new-web-page.html#create-the-view">1.1. Create the view</a></li>
@ -691,8 +678,7 @@ Click here to see the full index of all parts and lessons of the Beginner-Tutori
</li>
</ul>
</div>
</details>
</section>
</details></section>
</section>
</section>
@ -712,19 +698,16 @@ Click here to see the full index of all parts and lessons of the Beginner-Tutori
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="Part1/Beginner-Tutorial-Part1-Overview.html" title="Part 1: What We Have"
<a href="Part1/Beginner-Tutorial-Part1-Overview.html" title="Part 1: What we have"
>next</a> |</li>
<li class="right" >
<a href="../Howtos-Overview.html" title="Tutorials and How-Tos"
<a href="../Howtos-Overview.html" title="Tutorials and Howtos"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Beginner Tutorial</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="7. Making objects persistent" href="Beginner-Tutorial-Learning-Typeclasses.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Learning-Typeclasses.html" title="7. Making objects persistent"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">8. </span>Adding custom commands</a></li>
</ul>
</div>
</div>
<div class="document">
@ -70,8 +72,7 @@
<li><a class="reference internal" href="#">8. Adding custom commands</a><ul>
<li><a class="reference internal" href="#creating-a-custom-command">8.1. Creating a custom command</a><ul>
<li><a class="reference internal" href="#making-our-cmdset-persistent">8.1.1. Making our cmdset persistent</a></li>
<li><a class="reference internal" href="#add-the-echo-command-to-the-default-cmdset">8.1.2. Add the echo command to the default cmdset</a></li>
<li><a class="reference internal" href="#figuring-out-who-to-hit">8.1.3. Figuring out who to hit</a></li>
<li><a class="reference internal" href="#figuring-out-who-to-hit">8.1.2. Figuring out who to hit</a></li>
</ul>
</li>
<li><a class="reference internal" href="#summary">8.2. Summary</a></li>
@ -103,18 +104,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Adding-Commands.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -173,8 +162,7 @@ database. They are “just” normal Python classes.</p>
</div>
<p>This is the simplest form of command you can imagine. It just gives itself a name, “echo”. This is what you will use to call this command later.</p>
<p>Next we need to put this in a CmdSet. It will be a one-command CmdSet for now! Change your file as such:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/mycommands.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span>
<span class="kn">from</span> <span class="nn">commands.command</span> <span class="kn">import</span> <span class="n">Command</span>
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">CmdSet</span>
@ -241,8 +229,7 @@ current cmdset (self.cmdset): ChannelCmdSet
<li><p><code class="docutils literal notranslate"><span class="pre">obj</span></code> - this is object on which this Command (and CmdSet) “sits”. So you, in this case.</p></li>
</ul>
<p>The reason our command doesnt do anything yet is because its missing a <code class="docutils literal notranslate"><span class="pre">func</span></code> method. This is what Evennia looks for to figure out what a Command actually does. Modify your <code class="docutils literal notranslate"><span class="pre">CmdEcho</span></code> class:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/mycommands.py</span>
<span class="c1"># ...</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
<span class="k">class</span> <span class="nc">CmdEcho</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
@ -278,9 +265,13 @@ Echo: &#39;&#39;
Echo: &#39; Woo Tang!&#39;
</pre></div>
</div>
<p>Note that there is an extra space before <code class="docutils literal notranslate"><span class="pre">Woo</span></code>. That is because self.args contains <em>everything</em> after the command name, including spaces. Lets remove that extra space with a small tweak:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/mycommands.py</span>
<span class="c1"># ...</span>
<p>Note that there is an extra space before <code class="docutils literal notranslate"><span class="pre">Woo!</span></code>. That is because self.args contains <em>everything</em> after the command name, including spaces. Evennia will happily understand if you skip that space too:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; echoWoo Tang!
Echo: &#39;Woo Tang!&#39;
</pre></div>
</div>
<p>There are ways to force Evennia to <em>require</em> an initial space, but right now we want to just ignore it since it looks a bit weird for our echo example. Tweak the code:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
<span class="k">class</span> <span class="nc">CmdEcho</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
@ -317,62 +308,15 @@ enough to make <code class="docutils literal notranslate"><span class="pre">echo
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; py self.cmdset.add(&quot;commands.mycommands.MyCmdSet&quot;, persistent=True)
</pre></div>
</div>
<p>Now you can <code class="docutils literal notranslate"><span class="pre">reload</span></code> as much as you want and your code changes will be available directly without needing to re-add the MyCmdSet again.</p>
<p>We will add this cmdset in another way, so remove it manually:</p>
<p>Now you can <code class="docutils literal notranslate"><span class="pre">reload</span></code> as much as you want and your code changes will be available directly without
needing to re-add the MyCmdSet again. To remove the cmdset again, youd do</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; py self.cmdset.remove(&quot;commands.mycommands.MyCmdSet&quot;)
</pre></div>
</div>
</section>
<section id="add-the-echo-command-to-the-default-cmdset">
<h3><span class="section-number">8.1.2. </span>Add the echo command to the default cmdset<a class="headerlink" href="#add-the-echo-command-to-the-default-cmdset" title="Permalink to this headline"></a></h3>
<p>Above we added the <code class="docutils literal notranslate"><span class="pre">echo</span></code> command to ourselves. It will <em>only</em> be available to us and noone else in the game. But all commands in Evennia are part of command-sets, including the normal <code class="docutils literal notranslate"><span class="pre">look</span></code> and <code class="docutils literal notranslate"><span class="pre">py</span></code> commands we have been using all the while. You can easily extend the default command set with your <code class="docutils literal notranslate"><span class="pre">echo</span></code> command - this way <em>everyone</em> in the game will have access to it!</p>
<p>In <code class="docutils literal notranslate"><span class="pre">mygame/commands/</span></code> youll find an existing module named <code class="docutils literal notranslate"><span class="pre">default_cmdsets.py</span></code> Open it and youll find four empty cmdset-classes:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">CharacterCmdSet</span></code> - this sits on all Characters (this is the one we usually want to modify)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">AccountCmdSet</span></code> - this sits on all Accounts (shared between Characters, like <code class="docutils literal notranslate"><span class="pre">logout</span></code> etc)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">UnloggedCmdSet</span></code> - commands available <em>before</em> you login, like the commands for creating your password and connecting to the game.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">SessionCmdSet</span></code> - commands unique to your Session (your particular client connection). This is unused by default.</p></li>
</ul>
<p>Tweak this file as follows:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/default_cmdsets.py </span>
<span class="c1"># ,.. </span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">mycommands</span> <span class="c1"># &lt;------- </span>
<span class="k">class</span> <span class="nc">CharacterCmdSet</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">CharacterCmdSet</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The `CharacterCmdSet` contains general in-game commands like `look`,</span>
<span class="sd"> `get`, etc available on in-game Character objects. It is merged with</span>
<span class="sd"> the `AccountCmdSet` when an Account puppets a Character.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">key</span> <span class="o">=</span> <span class="s2">&quot;DefaultCharacter&quot;</span>
<span class="k">def</span> <span class="nf">at_cmdset_creation</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Populates the cmdset</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">at_cmdset_creation</span><span class="p">()</span>
<span class="c1">#</span>
<span class="c1"># any commands you add below will overload the default ones.</span>
<span class="c1">#</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">mycommands</span><span class="o">.</span><span class="n">CmdEcho</span><span class="p">)</span> <span class="c1"># &lt;-----------</span>
<span class="c1"># ... </span>
</pre></div>
</div>
<aside class="sidebar">
<p class="sidebar-title">super() and overriding defaults</p>
<p>The <code class="docutils literal notranslate"><span class="pre">super()</span></code> Python keyword means that the <em>parent</em> is called. In this case, the parent adds all default commands to this cmdset.</p>
<p>Coincidentally, this is also how you replace default commands in Evennia!jj To replace e.g. the command <code class="docutils literal notranslate"><span class="pre">get</span></code>, you just give your replacement command the <code class="docutils literal notranslate"><span class="pre">key</span></code> get and add it here - since its added after <code class="docutils literal notranslate"><span class="pre">super()</span></code>, it will replace the default version of <code class="docutils literal notranslate"><span class="pre">get</span></code>.</p>
</aside>
<p>This works the same way as when you added <code class="docutils literal notranslate"><span class="pre">CmdEcho</span></code> to your <code class="docutils literal notranslate"><span class="pre">MyCmdSet</span></code>. The only difference cmdsets are automatically added to all Characters/Accounts etc so you dont have to do so manually. We must also make sure to import the <code class="docutils literal notranslate"><span class="pre">CmdEcho</span></code> from your <code class="docutils literal notranslate"><span class="pre">mycommands</span></code> module in order for this module to know about it. The period <code class="docutils literal notranslate"><span class="pre">.</span></code> in <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">.</span> <span class="pre">import</span> <span class="pre">mycommands</span></code> means that we are telling Python that <code class="docutils literal notranslate"><span class="pre">mycommands.py</span></code> sits in the same directory as this current module. We want to import the entire module. Further down we access <code class="docutils literal notranslate"><span class="pre">mycommands.CmdEcho</span></code> to add it to the character cmdset.</p>
<p>Just <code class="docutils literal notranslate"><span class="pre">reload</span></code> the server and your <code class="docutils literal notranslate"><span class="pre">echo</span></code> command will be available again. There is no limit to how many cmdsets a given Command can be a part of.</p>
<p>To remove, you just comment out or delete the <code class="docutils literal notranslate"><span class="pre">self.add()</span></code> line. Keep it like this for now though - well expand on it below.</p>
<p>But for now, keep it around, well expand it with some more examples.</p>
</section>
<section id="figuring-out-who-to-hit">
<h3><span class="section-number">8.1.3. </span>Figuring out who to hit<a class="headerlink" href="#figuring-out-who-to-hit" title="Permalink to this headline"></a></h3>
<h3><span class="section-number">8.1.2. </span>Figuring out who to hit<a class="headerlink" href="#figuring-out-who-to-hit" title="Permalink to this headline"></a></h3>
<p>Lets try something a little more exciting than just echo. Lets make a <code class="docutils literal notranslate"><span class="pre">hit</span></code> command, for punching someone in the face! This is how we want it to work:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; hit &lt;target&gt;
You hit &lt;target&gt; with full force!
@ -392,35 +336,52 @@ You hit Bob with full force!
</pre></div>
</div>
<p>Still in <code class="docutils literal notranslate"><span class="pre">mygame/commands/mycommands.py</span></code>, add a new class, between <code class="docutils literal notranslate"><span class="pre">CmdEcho</span></code> and <code class="docutils literal notranslate"><span class="pre">MyCmdSet</span></code>.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/mycommands.py</span>
<div class="highlight-python notranslate"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
<span class="normal"> 2</span>
<span class="normal"> 3</span>
<span class="normal"> 4</span>
<span class="normal"> 5</span>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span>
<span class="normal">12</span>
<span class="normal">13</span>
<span class="normal">14</span>
<span class="normal">15</span>
<span class="normal">16</span>
<span class="normal">17</span>
<span class="normal">18</span>
<span class="normal">19</span>
<span class="normal">20</span>
<span class="normal">21</span>
<span class="normal">22</span>
<span class="normal">23</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># ...</span>
<span class="p">:</span><span class="n">linenos</span><span class="p">:</span>
<span class="p">:</span><span class="n">emphasize</span><span class="o">-</span><span class="n">lines</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">11</span><span class="p">,</span><span class="mi">14</span><span class="p">,</span><span class="mi">15</span><span class="p">,</span><span class="mi">17</span><span class="p">,</span><span class="mi">18</span><span class="p">,</span><span class="mi">19</span><span class="p">,</span><span class="mi">21</span>
<span class="c1"># ...</span>
<span class="k">class</span> <span class="nc">CmdHit</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Hit a target.</span>
<span class="hll"><span class="k">class</span> <span class="nc">CmdHit</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
</span><span class="hll"><span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
</span><span class="sd"> Hit a target.</span>
<span class="sd"> Usage:</span>
<span class="sd"> hit &lt;target&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">key</span> <span class="o">=</span> <span class="s2">&quot;hit&quot;</span>
<span class="hll"> <span class="n">key</span> <span class="o">=</span> <span class="s2">&quot;hit&quot;</span>
</span>
<span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">args</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">args</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">&quot;Who do you want to hit?&quot;</span><span class="p">)</span>
<span class="k">return</span>
<span class="n">target</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">target</span><span class="p">:</span>
<span class="k">return</span>
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You hit </span><span class="si">{</span><span class="n">target</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2"> with full force!&quot;</span><span class="p">)</span>
<span class="n">target</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You got hit by </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2"> with full force!&quot;</span><span class="p">)</span>
<span class="hll"> <span class="n">args</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
</span><span class="hll"> <span class="k">if</span> <span class="ow">not</span> <span class="n">args</span><span class="p">:</span>
</span> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">&quot;Who do you want to hit?&quot;</span><span class="p">)</span>
<span class="hll"> <span class="k">return</span>
</span><span class="hll"> <span class="n">target</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
</span><span class="hll"> <span class="k">if</span> <span class="ow">not</span> <span class="n">target</span><span class="p">:</span>
</span> <span class="k">return</span>
<span class="hll"> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You hit </span><span class="si">{</span><span class="n">target</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2"> with full force!&quot;</span><span class="p">)</span>
</span> <span class="n">target</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You got hit by </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2"> with full force!&quot;</span><span class="p">)</span>
<span class="c1"># ...</span>
</pre></div>
</pre></div></td></tr></table></div>
</div>
<p>A lot of things to dissect here:</p>
<ul class="simple">
@ -443,7 +404,9 @@ else:
...
</pre></div>
</div>
<p>There can be any number of <code class="docutils literal notranslate"><span class="pre">elifs</span></code> to mark when different branches of the code should run. If <code class="docutils literal notranslate"><span class="pre">else</span></code> is provided, it will run if none of the other conditions were truthy.</p>
<p>There can be any number of <code class="docutils literal notranslate"><span class="pre">elifs</span></code> to mark when different branches of the code should run. If
the <code class="docutils literal notranslate"><span class="pre">else</span></code> condition is given, it will run if none of the other conditions was truthy. In Python
the <code class="docutils literal notranslate"><span class="pre">if..elif..else</span></code> structure also serves the same function as <code class="docutils literal notranslate"><span class="pre">case</span></code> in some other languages.</p>
</aside>
<ul class="simple">
<li><p><strong>Line 15</strong> has our first <em>conditional</em>, an <code class="docutils literal notranslate"><span class="pre">if</span></code> statement. This is written on the form <code class="docutils literal notranslate"><span class="pre">if</span> <span class="pre">&lt;condition&gt;:</span></code> and only if that condition is truthy will the indented code block under the <code class="docutils literal notranslate"><span class="pre">if</span></code> statement run. To learn what is truthy in Python its usually easier to learn what is “falsy”:</p>
@ -451,8 +414,8 @@ else:
<li><p><code class="docutils literal notranslate"><span class="pre">False</span></code> - this is a reserved boolean word in Python. The opposite is <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">None</span></code> - another reserved word. This represents nothing, a null-result or value.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">0</span></code> or <code class="docutils literal notranslate"><span class="pre">0.0</span></code></p></li>
<li><p>The empty strings <code class="docutils literal notranslate"><span class="pre">&quot;&quot;</span></code>, <code class="docutils literal notranslate"><span class="pre">''</span></code>, or empty triple-strings like <code class="docutils literal notranslate"><span class="pre">&quot;&quot;&quot;&quot;&quot;&quot;</span></code>, <code class="docutils literal notranslate"><span class="pre">''''''</span></code></p></li>
<li><p>Empty <em>iterables</em> we havent used yet, like empty lists <code class="docutils literal notranslate"><span class="pre">[]</span></code>, empty tuples <code class="docutils literal notranslate"><span class="pre">()</span></code> and empty dicts <code class="docutils literal notranslate"><span class="pre">{}</span></code>.</p></li>
<li><p>The empty string <code class="docutils literal notranslate"><span class="pre">&quot;&quot;</span></code> or <code class="docutils literal notranslate"><span class="pre">''</span></code> or <code class="docutils literal notranslate"><span class="pre">&quot;&quot;&quot;&quot;&quot;&quot;</span></code> or <code class="docutils literal notranslate"><span class="pre">''''''</span></code></p></li>
<li><p>Empty <em>iterables</em> we havent seen yet, like empty lists <code class="docutils literal notranslate"><span class="pre">[]</span></code>, empty tuples <code class="docutils literal notranslate"><span class="pre">()</span></code> and empty dicts <code class="docutils literal notranslate"><span class="pre">{}</span></code>.</p></li>
<li><p>Everything else is “truthy”.</p></li>
</ul>
</li>
@ -463,10 +426,9 @@ else:
<li><p><strong>Lines 19-20</strong>: A feature of <code class="docutils literal notranslate"><span class="pre">.search</span></code> is that it will already inform <code class="docutils literal notranslate"><span class="pre">self.caller</span></code> if it couldnt find the target. In that case, <code class="docutils literal notranslate"><span class="pre">target</span></code> will be <code class="docutils literal notranslate"><span class="pre">None</span></code> and we should just directly <code class="docutils literal notranslate"><span class="pre">return</span></code>.</p></li>
<li><p><strong>Lines 21-22</strong>: At this point we have a suitable target and can send our punching strings to each.</p></li>
</ul>
<p>Finally we must also add this to a CmdSet. Lets add it to <code class="docutils literal notranslate"><span class="pre">MyCmdSet</span></code>.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/mycommands.py</span>
<p>Finally we must also add this to a CmdSet. Lets add it to <code class="docutils literal notranslate"><span class="pre">MyCmdSet</span></code> which we made persistent earlier.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># ...</span>
<span class="c1"># ...</span>
<span class="k">class</span> <span class="nc">MyCmdSet</span><span class="p">(</span><span class="n">CmdSet</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">at_cmdset_creation</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
@ -482,35 +444,6 @@ make an error and get a <code class="docutils literal notranslate"><span class="
directly in-game or in your log (view it with <code class="docutils literal notranslate"><span class="pre">evennia</span> <span class="pre">-l</span></code> in a terminal).
Dont panic; tracebacks are your friends - they are to be read bottom-up and usually describe exactly where your problem is. Refer to <a class="reference internal" href="Beginner-Tutorial-Python-basic-introduction.html"><span class="doc std std-doc">The Python introduction lesson</span></a> for more hints. If you get stuck, reach out to the Evennia community for help.</p>
</aside>
<p>Note that since we did <code class="docutils literal notranslate"><span class="pre">py</span> <span class="pre">self.cmdset.remove(&quot;commands.mycommands.MyCmdSet&quot;)</span></code> earlier, this cmdset is no longer available on our Character. Instead we will add these commands directly to our default cmdset.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/default_cmdsets.py </span>
<span class="c1"># ,.. </span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">mycommands</span>
<span class="k">class</span> <span class="nc">CharacterCmdSet</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">CharacterCmdSet</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The `CharacterCmdSet` contains general in-game commands like `look`,</span>
<span class="sd"> `get`, etc available on in-game Character objects. It is merged with</span>
<span class="sd"> the `AccountCmdSet` when an Account puppets a Character.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">key</span> <span class="o">=</span> <span class="s2">&quot;DefaultCharacter&quot;</span>
<span class="k">def</span> <span class="nf">at_cmdset_creation</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Populates the cmdset</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">at_cmdset_creation</span><span class="p">()</span>
<span class="c1">#</span>
<span class="c1"># any commands you add below will overload the default ones.</span>
<span class="c1">#</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">mycommands</span><span class="o">.</span><span class="n">MyCmdSet</span><span class="p">)</span> <span class="c1"># &lt;-----------</span>
<span class="c1"># ... </span>
</pre></div>
</div>
<p>We changed from adding the individual <code class="docutils literal notranslate"><span class="pre">echo</span></code> command to adding the entire <code class="docutils literal notranslate"><span class="pre">MyCmdSet</span></code> in one go! This will add all commands in that cmdset to the <code class="docutils literal notranslate"><span class="pre">CharacterCmdSet</span></code> and is a practical way to add a lot of command in one go. Once you explore Evennia further, youll find that <a class="reference internal" href="../../../Contribs/Contribs-Overview.html"><span class="doc std std-doc">Evennia contribs</span></a> all distribute their new commands in cmdsets, so you can easily add them to your game like this.</p>
<p>Next we reload to let Evennia know of these code changes and try it out:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; reload
hit
@ -558,15 +491,12 @@ get into how we replace and extend Evennias default Commands.</p>
<a href="Beginner-Tutorial-Learning-Typeclasses.html" title="7. Making objects persistent"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">8. </span>Adding custom commands</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -6,7 +6,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>1. Using Commands and Building Stuff &#8212; Evennia 2.x documentation</title>
<title>1. Using commands and building stuff &#8212; Evennia 2.x documentation</title>
<link rel="stylesheet" href="../../../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
@ -18,11 +18,9 @@
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<link rel="next" title="2. The Tutorial World" href="Beginner-Tutorial-Tutorial-World.html" />
<link rel="prev" title="Part 1: What We Have" href="Beginner-Tutorial-Part1-Overview.html" />
<link rel="prev" title="Part 1: What we have" href="Beginner-Tutorial-Part1-Overview.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -37,15 +35,19 @@
<a href="Beginner-Tutorial-Tutorial-World.html" title="2. The Tutorial World"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Part1-Overview.html" title="Part 1: What We Have"
<a href="Beginner-Tutorial-Part1-Overview.html" title="Part 1: What we have"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">1. </span>Using Commands and Building Stuff</a></li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">1. </span>Using commands and building stuff</a></li>
</ul>
</div>
</div>
<div class="document">
@ -67,10 +69,10 @@
<script>$('#searchbox').show(0);</script>
<h3><a href="../../../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">1. Using Commands and Building Stuff</a><ul>
<li><a class="reference internal" href="#getting-help">1.1. Getting Help</a></li>
<li><a class="reference internal" href="#looking-around">1.2. Looking Around</a></li>
<li><a class="reference internal" href="#stepping-down-from-godhood">1.3. Stepping Down from Godhood</a></li>
<li><a class="reference internal" href="#">1. Using commands and building stuff</a><ul>
<li><a class="reference internal" href="#getting-help">1.1. Getting help</a></li>
<li><a class="reference internal" href="#looking-around">1.2. Looking around</a></li>
<li><a class="reference internal" href="#stepping-down-from-godhood">1.3. Stepping Down From Godhood</a></li>
<li><a class="reference internal" href="#creating-an-object">1.4. Creating an Object</a></li>
<li><a class="reference internal" href="#get-a-personality">1.5. Get a Personality</a></li>
<li><a class="reference internal" href="#pushing-your-buttons">1.6. Pushing Your Buttons</a></li>
@ -84,7 +86,7 @@
<h4>Previous topic</h4>
<p class="topless"><a href="Beginner-Tutorial-Part1-Overview.html"
title="previous chapter">Part 1: What We Have</a></p>
title="previous chapter">Part 1: What we have</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="Beginner-Tutorial-Tutorial-World.html"
title="next chapter"><span class="section-number">2. </span>The Tutorial World</a></p>
@ -106,43 +108,32 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Building-Quickstart.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section class="tex2jax_ignore mathjax_ignore" id="using-commands-and-building-stuff">
<h1><span class="section-number">1. </span>Using Commands and Building Stuff<a class="headerlink" href="#using-commands-and-building-stuff" title="Permalink to this headline"></a></h1>
<h1><span class="section-number">1. </span>Using commands and building stuff<a class="headerlink" href="#using-commands-and-building-stuff" title="Permalink to this headline"></a></h1>
<p>In this lesson, we will test out what we can do in-game out-of-the-box. Evennia ships with
<a class="reference internal" href="../../../Components/Default-Commands.html"><span class="doc std std-doc">around 90 default commands</span></a> and, while you can override those as you please, the defaults can be quite useful.</p>
<p>Connect and login to your new game. You will find yourself in the “Limbo” location. This
is the only room in the game at this point. Lets explore the default commands a little.</p>
<p>The default commands have syntax <a class="reference internal" href="../../../Coding/Default-Command-Syntax.html"><span class="doc std std-doc">similar to MUX</span></a>:</p>
<a class="reference internal" href="../../../Components/Default-Commands.html"><span class="doc std std-doc">around 90 default commands</span></a>, and while you can override those as you please,
the defaults can be quite useful.</p>
<p>Connect and log into your new game and you will end up in the “Limbo” location. This
is the only room in the game at this point. Lets explore the commands a little.</p>
<p>The default commands has syntax <a class="reference internal" href="../../../Coding/Default-Command-Syntax.html"><span class="doc std std-doc">similar to MUX</span></a>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span> command[/switch/switch...] [arguments ...]
</pre></div>
</div>
<p>An example would be:</p>
<p>An example would be</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span> create/drop box
</pre></div>
</div>
<p>A <em>/switch</em> is a special, optional flag to make a command behave differently. A switch is always put directly after the command name, and begins with a forward slash (<code class="docutils literal notranslate"><span class="pre">/</span></code>). The <em>arguments</em> are one or more inputs to the commands. Its common to use an equal sign (<code class="docutils literal notranslate"><span class="pre">=</span></code>) when assigning something to an object.</p>
<p>A <em>/switch</em> is a special, optional flag to the command to make it behave differently. It is always put directly after the command name, and begins with a forward slash (<code class="docutils literal notranslate"><span class="pre">/</span></code>). The <em>arguments</em> are one or more inputs to the commands. Its common to use an equal sign (<code class="docutils literal notranslate"><span class="pre">=</span></code>) when assigning something to an object.</p>
<blockquote>
<div><p>Are you used to commands starting with &#64;, like &#64;create? That will work, too. Evennia simply ignores the preceeding &#64;.</p>
<div><p>Are you used to commands starting with &#64;, like &#64;create? That will work too. Evennia simply ignores the preceeding &#64;.</p>
</div></blockquote>
<section id="getting-help">
<h2><span class="section-number">1.1. </span>Getting Help<a class="headerlink" href="#getting-help" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">1.1. </span>Getting help<a class="headerlink" href="#getting-help" title="Permalink to this headline"></a></h2>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>help
</pre></div>
</div>
@ -153,26 +144,26 @@ is the only room in the game at this point. Lets explore the default commands
<p>to see the in-game help for that command.</p>
</section>
<section id="looking-around">
<h2><span class="section-number">1.2. </span>Looking Around<a class="headerlink" href="#looking-around" title="Permalink to this headline"></a></h2>
<p>The most common command is</p>
<h2><span class="section-number">1.2. </span>Looking around<a class="headerlink" href="#looking-around" title="Permalink to this headline"></a></h2>
<p>The most common comman is</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>look
</pre></div>
</div>
<p>This will show you the description of the current location. <code class="docutils literal notranslate"><span class="pre">l</span></code> is an alias for the look command.</p>
<p>When targeting objects in commands, you have two special labels you can use: <code class="docutils literal notranslate"><span class="pre">here</span></code> for the current room, or <code class="docutils literal notranslate"><span class="pre">me</span></code>/<code class="docutils literal notranslate"><span class="pre">self</span></code> to point back to yourself. Thus,</p>
<p>This will show you the description of the current location. <code class="docutils literal notranslate"><span class="pre">l</span></code> is an alias.</p>
<p>When targeting objects in commands, you have two special labels you can use, <code class="docutils literal notranslate"><span class="pre">here</span></code> for the current room or <code class="docutils literal notranslate"><span class="pre">me</span></code>/<code class="docutils literal notranslate"><span class="pre">self</span></code> to point back to yourself. So</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>look me
</pre></div>
</div>
<p>will give you your own description. <code class="docutils literal notranslate"><span class="pre">look</span> <span class="pre">here</span></code> is, in this case, the same as just plain <code class="docutils literal notranslate"><span class="pre">look</span></code>.</p>
<p>will give you your own description. <code class="docutils literal notranslate"><span class="pre">look</span> <span class="pre">here</span></code> is, in this case, the same as plain <code class="docutils literal notranslate"><span class="pre">look</span></code>.</p>
</section>
<section id="stepping-down-from-godhood">
<h2><span class="section-number">1.3. </span>Stepping Down from Godhood<a class="headerlink" href="#stepping-down-from-godhood" title="Permalink to this headline"></a></h2>
<p>If you just installed Evennia, your very first player account is called user #1 also known as the <em>superuser</em> or <em>god user</em>. This user is very powerful so powerful that it will override many game restrictions (such as locks). This can be useful, but it also hides some functionality that you might want to test.</p>
<p>To step down temporarily from your superuser position, you may use the <code class="docutils literal notranslate"><span class="pre">quell</span></code> command in-game:</p>
<h2><span class="section-number">1.3. </span>Stepping Down From Godhood<a class="headerlink" href="#stepping-down-from-godhood" title="Permalink to this headline"></a></h2>
<p>If you just installed Evennia, your very first player account is called user #1, also known as the <em>superuser</em> or <em>god user</em>. This user is very powerful, so powerful that it will override many game restrictions (such as locks). This can be useful, but it also hides some functionality that you might want to test.</p>
<p>To temporarily step down from your superuser position, you can use the <code class="docutils literal notranslate"><span class="pre">quell</span></code> command in-game:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>quell
</pre></div>
</div>
<p>This will make you start using the permission of your current characters level instead of your superuser level. If you didnt change any settings, your initial game Character should have <em>Developer</em> level permission — as high as can be without bypassing locks like the superuser does. This will work fine for the examples on this page. Use</p>
<p>This will make you start using the permission of your current characters level instead of your superuser level. If you didnt change any settings, your game Character should have an <em>Developer</em> level permission - high as can be without bypassing locks like the superuser does. This will work fine for the examples on this page. Use</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>unquell
</pre></div>
</div>
@ -180,95 +171,97 @@ is the only room in the game at this point. Lets explore the default commands
</section>
<section id="creating-an-object">
<h2><span class="section-number">1.4. </span>Creating an Object<a class="headerlink" href="#creating-an-object" title="Permalink to this headline"></a></h2>
<p>Basic objects can be anything swords, flowers, and non-player characters. They are created using the <code class="docutils literal notranslate"><span class="pre">create</span></code> command. For example:</p>
<p>Basic objects can be anything swords, flowers, and non-player characters. They are created using the <code class="docutils literal notranslate"><span class="pre">create</span></code> command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>create box
</pre></div>
</div>
<p>This creates a new box (of the default object type) in your inventory. Use the command <code class="docutils literal notranslate"><span class="pre">inventory</span></code> (or <code class="docutils literal notranslate"><span class="pre">i</span></code>) to see it. Now, box is a rather short name, so lets rename it and tack on a few aliases:</p>
<p>This created a new box (of the default object type) in your inventory. Use the command <code class="docutils literal notranslate"><span class="pre">inventory</span></code> (or <code class="docutils literal notranslate"><span class="pre">i</span></code>) to see it. Now, box is a rather short name, lets rename it and tack on a few aliases.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>name box = very large box;box;very;crate
</pre></div>
</div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>MUD Clients and Semi-Colons:
Some traditional MUD clients use the semi-colon <code class="docutils literal notranslate"><span class="pre">;</span></code> to separate client inputs. If so, the above line will give an error and youll need to change your client to use another command-separator or put it in verbatim mode. If you still have trouble, use the Evennia web client instead.</p>
<p>MUD clients and semi-colon:
Some traditional MUD clients use the semi-colon <code class="docutils literal notranslate"><span class="pre">;</span></code> to separate client inputs. If so, the above line will give an error. You need to change your client to use another command-separator or to put it in verbatim mode. If you still have trouble, use the Evennia web client instead.</p>
</div>
<p>We have now renamed the box as <em>very large box</em> — and this is what we will see when looking at it. However, we will also recognize it by any of the other names we have offered as arguments to the name command above (i.e., <em>crate</em> or simply <em>box</em> as before). We also could have given these aliases directly after the name in the initial <code class="docutils literal notranslate"><span class="pre">create</span></code> object command. This is true for all creation commands — you can always provide a list of <code class="docutils literal notranslate"><span class="pre">;</span></code>-separated aliases to the name of your new object. In our example, if you had not wanted to change the box objects name itself, but to add aliases only, you could use the <code class="docutils literal notranslate"><span class="pre">alias</span></code> command.</p>
<p>At this point in the building tutorial, our Character is currently carrying the box. Lets drop it:</p>
<p>We now renamed the box to <em>very large box</em> (and this is what we will see when looking at it), but we will also recognize it by any of the other names we give - like <em>crate</em> or simply <em>box</em> as before. We could have given these aliases directly after the name in the <code class="docutils literal notranslate"><span class="pre">create</span></code> command. This is true for all creation commands - you can always tag on a list of <code class="docutils literal notranslate"><span class="pre">;</span></code>-separated aliases to the name of your new object. If you had wanted to not change the name itself, but to only add aliases, you could have used the <code class="docutils literal notranslate"><span class="pre">alias</span></code> command.</p>
<p>We are currently carrying the box. Lets drop it (there is also a shortcut to create and drop in
one go by using the <code class="docutils literal notranslate"><span class="pre">/drop</span></code> switch, for example <code class="docutils literal notranslate"><span class="pre">create/drop</span> <span class="pre">box</span></code>).</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>drop box
</pre></div>
</div>
<p>Hey presto, — there it is on the ground, in all its normality. There is also a shortcut to both create and drop an object in one go by using the <code class="docutils literal notranslate"><span class="pre">/drop</span></code> switch (e.g, <code class="docutils literal notranslate"><span class="pre">create/drop</span> <span class="pre">box</span></code>).</p>
<p>Let us take a closer look at our new box:</p>
<p>Hey presto - there it is on the ground, in all its normality.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>examine box
</pre></div>
</div>
<p>The examine command will show some technical details about the box object. For now, we will ignore what this
<p>This will show some technical details about the box object. For now we will ignore what this
information means.</p>
<p>Try to <code class="docutils literal notranslate"><span class="pre">look</span></code> at the box to see the (default) description:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; look box
<p>Try to <code class="docutils literal notranslate"><span class="pre">look</span></code> at the box to see the (default) description.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>look box
You see nothing special.
</pre></div>
</div>
<p>The default description is not very exciting. Lets add some flavor:</p>
<p>The description you get is not very exciting. Lets add some flavor.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>desc box = This is a large and very heavy box.
</pre></div>
</div>
<p>If you try the <code class="docutils literal notranslate"><span class="pre">get</span></code> command, we will pick up the box. So far so good. But, if we really want this to be a large and heavy box, people should <em>not</em> be able to run off with it so easily. To prevent this, we must lock it down. This is done by assigning a <em>lock</em> to it. TO do so, first make sure the box was dropped in the room, then use the lock command:</p>
<p>If you try the <code class="docutils literal notranslate"><span class="pre">get</span></code> command, we will pick up the box. So far so good, but if we really want this to be a large and heavy box, people should <em>not</em> be able to run off with it that easily. To prevent this we need to lock it down. This is done by assigning a <em>Lock</em> to it. Make sure the box was dropped in the room, then try this:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>lock box = get:false()
</pre></div>
</div>
<p>Locks represent a rather <a class="reference internal" href="../../../Components/Locks.html"><span class="doc std std-doc">big topic</span></a> but, for now, this will do what we want. The above command will lock the box so no one can lift it — with one exception. Remember that superusers override all locks and will pick it up anyway. Make sure you are quelling your superuser powers, and try to get it again:</p>
<p>Locks represent a rather <a class="reference internal" href="../../../Components/Locks.html"><span class="doc std std-doc">big topic</span></a>, but for now that will do what we want. This will lock the box so no one can lift it. The exception is superusers, they override all locks and will pick it
up anyway. Make sure you are quelling your superuser powers and try to get the box now:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; get box
You can&#39;t get that.
</pre></div>
</div>
<p>Think this default error message looks dull? The <code class="docutils literal notranslate"><span class="pre">get</span></code> command looks for an <a class="reference internal" href="../../../Components/Attributes.html"><span class="doc std std-doc">Attribute</span></a> named <code class="docutils literal notranslate"><span class="pre">get_err_msg</span></code> to return as a custom error message. We set attributes using the <code class="docutils literal notranslate"><span class="pre">set</span></code> command:</p>
<p>Think this default error message looks dull? The <code class="docutils literal notranslate"><span class="pre">get</span></code> command looks for an <a class="reference internal" href="../../../Components/Attributes.html"><span class="doc std std-doc">Attribute</span></a> named <code class="docutils literal notranslate"><span class="pre">get_err_msg</span></code> for returning a nicer error messageod (this can be seen from the default <code class="docutils literal notranslate"><span class="pre">get</span></code> command code). You set attributes using the <code class="docutils literal notranslate"><span class="pre">set</span></code> command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>set box/get_err_msg = It&#39;s way too heavy for you to lift.
</pre></div>
</div>
<p>Now try to get the box and you should see a more pertinent error message echoed back to you. To see what this message string is in the future, you can use examine.</p>
<p>Try to get it now and you should see a nicer error message echoed back to you. To see what this message string is in the future, you can use examine.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>examine box/get_err_msg
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Examine</span></code> will return the value of attributes, including color codes. For instance, <code class="docutils literal notranslate"><span class="pre">examine</span> <span class="pre">here/desc</span></code> would return the raw description of the current room (including color codes), so that you can copy-and-paste to set its description to something else.</p>
<p>You create new Commands — or modify existing ones — in Python code outside the game. We explore doing so later in the <a class="reference internal" href="Beginner-Tutorial-Adding-Commands.html"><span class="doc std std-doc">Commands tutorial</span></a>.</p>
<p>Examine will return the value of attributes, including color codes. <code class="docutils literal notranslate"><span class="pre">examine</span> <span class="pre">here/desc</span></code> would return the raw description of your current room (including color codes), so that you can copy-and-paste to set its description to something else.</p>
<p>You create new Commands (or modify existing ones) in Python outside the game. We will get to that later, in the <a class="reference internal" href="Beginner-Tutorial-Adding-Commands.html"><span class="doc std std-doc">Commands tutorial</span></a>.</p>
</section>
<section id="get-a-personality">
<h2><span class="section-number">1.5. </span>Get a Personality<a class="headerlink" href="#get-a-personality" title="Permalink to this headline"></a></h2>
<p><a class="reference internal" href="../../../Components/Scripts.html"><span class="doc std std-doc">Scripts</span></a> are powerful out-of-character objects useful for many “under the hood” things. One of their optional abilities is to do things on a timer. To try out our first script, lets apply one to ourselves. There is an example script in <code class="docutils literal notranslate"><span class="pre">evennia/contrib/tutorials/bodyfunctions/bodyfunctions.py</span></code> that is called <code class="docutils literal notranslate"><span class="pre">BodyFunctions</span></code>. To add this to our self, we may use the <code class="docutils literal notranslate"><span class="pre">script</span></code> command:</p>
<p><a class="reference internal" href="../../../Components/Scripts.html"><span class="doc std std-doc">Scripts</span></a> are powerful out-of-character objects useful for many “under the hood” things. One of their optional abilities is to do things on a timer. To try out a first script, lets put one on ourselves. There is an example script in <code class="docutils literal notranslate"><span class="pre">evennia/contrib/tutorials/bodyfunctions/bodyfunctions.py</span></code> that is called <code class="docutils literal notranslate"><span class="pre">BodyFunctions</span></code>. To add this to us we will use the <code class="docutils literal notranslate"><span class="pre">script</span></code> command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>script self = tutorials.bodyfunctions.BodyFunctions
</pre></div>
</div>
<p>The above string tells Evennia to dig up the Python code at the place we indicate. It already knows to look in the <code class="docutils literal notranslate"><span class="pre">contrib/</span></code> folder, so we dont have to give the full path.</p>
<p>This string will tell Evennia to dig up the Python code at the place we indicate. It already knows to look in the <code class="docutils literal notranslate"><span class="pre">contrib/</span></code> folder, so we dont have to give the full path.</p>
<blockquote>
<div><p>Note also how we use <code class="docutils literal notranslate"><span class="pre">.</span></code> instead of <code class="docutils literal notranslate"><span class="pre">/</span></code> (or <code class="docutils literal notranslate"><span class="pre">\</span></code> on Windows). This convention is a so-called “Python-path.” In a Python-path, you separate the parts of the path with <code class="docutils literal notranslate"><span class="pre">.</span></code> and skip the <code class="docutils literal notranslate"><span class="pre">.py</span></code> file-ending. Importantly, it also allows you to point to Python code <em>inside</em> files as in our example where the <code class="docutils literal notranslate"><span class="pre">BodyFunctions</span></code> class is inside the <code class="docutils literal notranslate"><span class="pre">bodyfunctions.py</span></code> file. Well get to classes later. These “Python-paths” are used extensively throughout Evennia.</p>
<div><p>Note also how we use <code class="docutils literal notranslate"><span class="pre">.</span></code> instead of <code class="docutils literal notranslate"><span class="pre">/</span></code> (or <code class="docutils literal notranslate"><span class="pre">\</span></code> on Windows). This is a so-called “Python path”. In a Python-path, &gt; you separate the parts of the path with <code class="docutils literal notranslate"><span class="pre">.</span></code> and skip the <code class="docutils literal notranslate"><span class="pre">.py</span></code> file-ending. Importantly, it also allows you to point to Python code <em>inside</em> files, like the <code class="docutils literal notranslate"><span class="pre">BodyFunctions</span></code> class inside <code class="docutils literal notranslate"><span class="pre">bodyfunctions.py</span></code> (well get to classes later). These “Python-paths” are used extensively throughout Evennia.</p>
</div></blockquote>
<p>Wait a while and you will notice yourself starting to make random observations</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>script self =
<p>Wait a while and you will notice yourself starting making random observations </p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>script self
</pre></div>
</div>
<p>The above command will show details about scripts on the given object, in this case your self. The <code class="docutils literal notranslate"><span class="pre">examine</span></code> command also includes such details.</p>
<p>You will see how long it is until it “fires” next. Dont be alarmed if nothing happens when the countdown reaches zero — this particular script has a randomizer to determine if it will say something or not. So you will not see output every time it fires.</p>
<p>When you are tired of your characters “insights,” stop the script with:</p>
<p>This will show details about scripts on yourself (also <code class="docutils literal notranslate"><span class="pre">examine</span></code> works). You will see how long it is until it “fires” next. Dont be alarmed if nothing happens when the countdown reaches zero - this particular script has a randomizer to determine if it will say something or not. So you will not see output every time it fires.</p>
<p>When you are tired of your characters “insights”, kill the script with</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>script/stop self = tutorials.bodyfunctions.BodyFunctions
</pre></div>
</div>
<p>You may create your own scripts in Python, outside the game; the path you give to <code class="docutils literal notranslate"><span class="pre">script</span></code> is literally the Python path to your script file. The <a class="reference internal" href="../../../Components/Scripts.html"><span class="doc std std-doc">Scripts</span></a> page explains more details.</p>
<p>You create your own scripts in Python, outside the game; the path you give to <code class="docutils literal notranslate"><span class="pre">script</span></code> is literally the Python path to your script file. The <a class="reference internal" href="../../../Components/Scripts.html"><span class="doc std std-doc">Scripts</span></a> page explains more details.</p>
</section>
<section id="pushing-your-buttons">
<h2><span class="section-number">1.6. </span>Pushing Your Buttons<a class="headerlink" href="#pushing-your-buttons" title="Permalink to this headline"></a></h2>
<p>If we get back to the box we made, there is only so much fun you can have with it at this point. Its just a dumb generic object. If you renamed it to <code class="docutils literal notranslate"><span class="pre">stone</span></code> and changed its description, no one would be the wiser. However, with the combined use of custom <a class="reference internal" href="../../../Components/Typeclasses.html"><span class="doc std std-doc">Typeclasses</span></a>, <a class="reference internal" href="../../../Components/Scripts.html"><span class="doc std std-doc">Scripts</span></a> and object-based <a class="reference internal" href="../../../Components/Commands.html"><span class="doc std std-doc">Commands</span></a>, you can expand it — and other items — to be as unique, complex, and interactive as you want.</p>
<p>So, lets work though just such an example. So far, we have only created objects that use the default object typeclass named simply <code class="docutils literal notranslate"><span class="pre">Object</span></code>. Lets create an object that is a little more interesting. Under
<code class="docutils literal notranslate"><span class="pre">evennia/contrib/tutorials</span></code> there is a module <code class="docutils literal notranslate"><span class="pre">red_button.py</span></code>. It contains the enigmatic <code class="docutils literal notranslate"><span class="pre">RedButton</span></code> class.</p>
<p>If we get back to the box we made, there is only so much fun you can have with it at this point. Its just a dumb generic object. If you renamed it to <code class="docutils literal notranslate"><span class="pre">stone</span></code> and changed its description, no one would be the wiser. However, with the combined use of custom <a class="reference internal" href="../../../Components/Typeclasses.html"><span class="doc std std-doc">Typeclasses</span></a>, <a class="reference internal" href="../../../Components/Scripts.html"><span class="doc std std-doc">Scripts</span></a>
and object-based <a class="reference internal" href="../../../Components/Commands.html"><span class="doc std std-doc">Commands</span></a>, you could expand it and other items to be as unique, complex
and interactive as you want.</p>
<p>Lets take an example. So far we have only created objects that use the default object typeclass named simply <code class="docutils literal notranslate"><span class="pre">Object</span></code>. Lets create an object that is a little more interesting. Under
<code class="docutils literal notranslate"><span class="pre">evennia/contrib/tutorials</span></code> there is a module <code class="docutils literal notranslate"><span class="pre">red_button.py</span></code>. It contains the enigmatic <code class="docutils literal notranslate"><span class="pre">RedButton</span></code> class.</p>
<p>Lets make us one of <em>those</em>!</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>create/drop button:tutorials.red_button.RedButton
</pre></div>
</div>
<p>Enter the above command with Python-path and there you go — one red button! Just as in the Script example earlier, we have specified a Python-path to the Python code that we want Evennia to use for creating the object.</p>
<p>The RedButton is an example object intended to show off a few of Evennias features. You will find that the <a class="reference internal" href="../../../Components/Typeclasses.html"><span class="doc std std-doc">Typeclass</span></a> and <a class="reference internal" href="../../../Components/Commands.html"><span class="doc std std-doc">Commands</span></a> controlling it are inside <a class="reference internal" href="../../../api/evennia.contrib.tutorials.red_button.html"><span class="doc std std-doc">evennia/contrib/tutorials/red_button</span></a>.</p>
<p>The same way we did with the Script earlier, we specify a “Python-path” to the Python code we want Evennia to use for creating the object. There you go - one red button.</p>
<p>The RedButton is an example object intended to show off a few of Evennias features. You will find that the <a class="reference internal" href="../../../Components/Typeclasses.html"><span class="doc std std-doc">Typeclass</span></a> and <a class="reference internal" href="../../../Components/Commands.html"><span class="doc std std-doc">Commands</span></a> controlling it are inside <a class="reference internal" href="../../../api/evennia.contrib.tutorials.red_button.html"><span class="doc std std-doc">evennia/contrib/tutorials/red_button</span></a></p>
<p>If you wait for a while (make sure you dropped it!) the button will blink invitingly.</p>
<p>Why dont you try to push it…?</p>
<p>Why dont you try to push it …?</p>
<p>Surely a big red button is meant to be pushed.</p>
<p>You know you want to.</p>
<div class="admonition warning">
@ -278,23 +271,23 @@ You can&#39;t get that.
</section>
<section id="making-yourself-a-house">
<h2><span class="section-number">1.7. </span>Making Yourself a House<a class="headerlink" href="#making-yourself-a-house" title="Permalink to this headline"></a></h2>
<p>The main command for shaping your game world is <code class="docutils literal notranslate"><span class="pre">dig</span></code>. For example, if you are standing in Limbo, you can dig a route to your new house location like this:</p>
<p>The main command for shaping the game world is <code class="docutils literal notranslate"><span class="pre">dig</span></code>. For example, if you are standing in Limbo, you can dig a route to your new house location like this:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>dig house = large red door;door;in,to the outside;out
</pre></div>
</div>
<p>The above command will create a new room named “house.” It will also create an exit from your current location named large red door and a corresponding exit named to the outside in the new house room leading back to Limbo. In above, we also define a few aliases to those exits so that players dont need to type the full exit name.</p>
<p>If you wanted to use regular compass directions (north, west, southwest, etc.), you could do that with <code class="docutils literal notranslate"><span class="pre">dig</span></code>, too. However, Evennia also has a specialized version of <code class="docutils literal notranslate"><span class="pre">dig</span></code> that helps with cardinal directions (as well as up/down and in/out). Its called <code class="docutils literal notranslate"><span class="pre">tunnel</span></code>:</p>
<p>This will create a new room named house. Spaces at the start/end of names and aliases are ignored so you could put more air if you wanted. This call will directly create an exit from your current location named large red door and a corresponding exit named to the outside in the house room leading back to Limbo. We also define a few aliases to those exits, so people dont have to write the full thing all the time.</p>
<p>If you wanted to use normal compass directions (north, west, southwest etc), you could do that with <code class="docutils literal notranslate"><span class="pre">dig</span></code> too. But Evennia also has a limited version of <code class="docutils literal notranslate"><span class="pre">dig</span></code> that helps for compass directions (and also up/down and in/out). Its called <code class="docutils literal notranslate"><span class="pre">tunnel</span></code>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>tunnel sw = cliff
</pre></div>
</div>
<p>This will create a new room named “cliff” with a “southwest” exit leading there, and a “northeast” path leading back from the cliff to your current location.</p>
<p>You can create new exits from where you are standing, using the <code class="docutils literal notranslate"><span class="pre">open</span></code> command:</p>
<p>This will create a new room “cliff” with an exit “southwest” leading there and a path “northeast” leading back from the cliff to your current location.</p>
<p>You can create new exits from where you are, using the <code class="docutils literal notranslate"><span class="pre">open</span></code> command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>open north;n = house
</pre></div>
</div>
<p>This opens an exit <code class="docutils literal notranslate"><span class="pre">north</span></code> (with an alias <code class="docutils literal notranslate"><span class="pre">n</span></code>) to the previously created room <code class="docutils literal notranslate"><span class="pre">house</span></code>.</p>
<p>If you have many rooms named <code class="docutils literal notranslate"><span class="pre">house</span></code>, you will get a list of matches and must select to which specific one you want to link.</p>
<p>Next, follow the northern exit to your “house” by walking north. You can also <code class="docutils literal notranslate"><span class="pre">teleport</span></code> to it:</p>
<p>If you have many rooms named <code class="docutils literal notranslate"><span class="pre">house</span></code> you will get a list of matches and have to select which one you want to link to.</p>
<p>Follow the north exit to your house or <code class="docutils literal notranslate"><span class="pre">teleport</span></code> to it:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>north
</pre></div>
</div>
@ -302,49 +295,48 @@ You can&#39;t get that.
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>teleport house
</pre></div>
</div>
<p>To open an exit back to Limbo manually (in case you didnt do so automatically by using the <code class="docutils literal notranslate"><span class="pre">dig</span></code> command):</p>
<p>To manually open an exit back to Limbo (if you didnt do so with the <code class="docutils literal notranslate"><span class="pre">dig</span></code> command):</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>open door = limbo
</pre></div>
</div>
<p>(You can also use the <code class="docutils literal notranslate"><span class="pre">#dbref</span></code> of Limbo, which you can find by using <code class="docutils literal notranslate"><span class="pre">examine</span> <span class="pre">here</span></code> when standing in Limbo.)</p>
<p>(You can also us the #dbref of limbo, which you can find by using <code class="docutils literal notranslate"><span class="pre">examine</span> <span class="pre">here</span></code> when in limbo).</p>
</section>
<section id="reshuffling-the-world">
<h2><span class="section-number">1.8. </span>Reshuffling the World<a class="headerlink" href="#reshuffling-the-world" title="Permalink to this headline"></a></h2>
<p>Assuming you are back at <code class="docutils literal notranslate"><span class="pre">Limbo</span></code>, lets teleport the <em>large box</em> to our <code class="docutils literal notranslate"><span class="pre">house</span></code>:</p>
<p>You can find things using the <code class="docutils literal notranslate"><span class="pre">find</span></code> command. Assuming you are back at <code class="docutils literal notranslate"><span class="pre">Limbo</span></code>, lets teleport the <em>large box</em> to our house.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>teleport box = house
very large box is leaving Limbo, heading for house.
Teleported very large box -&gt; house.
</pre></div>
</div>
<p>You can find things in the game world, such as our <code class="docutils literal notranslate"><span class="pre">box</span></code>, by using the <code class="docutils literal notranslate"><span class="pre">find</span></code> command:</p>
<p>We can still find the box by using find:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>find box
One Match(#1-#8):
very large box(#8) - src.objects.objects.Object
</pre></div>
</div>
<p>Knowing the <code class="docutils literal notranslate"><span class="pre">#dbref</span></code> of the box (#8 in this example), you can grab the box and get it back here without actually going to the <code class="docutils literal notranslate"><span class="pre">house</span></code> first:</p>
<p>Knowing the <code class="docutils literal notranslate"><span class="pre">#dbref</span></code> of the box (#8 in this example), you can grab the box and get it back here without actually yourself going to <code class="docutils literal notranslate"><span class="pre">house</span></code> first:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>teleport #8 = here
</pre></div>
</div>
<p>As mentioned, <code class="docutils literal notranslate"><span class="pre">here</span></code> is an alias for “your current location.” The box should now be back in Limbo with you.</p>
<p>We are getting tired of the box. Lets destroy it:</p>
<p>As mentioned, <code class="docutils literal notranslate"><span class="pre">here</span></code> is an alias for your current location. The box should now be back in Limbo with you. We are getting tired of the box. Lets destroy it.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>destroy box
</pre></div>
</div>
<p>Issuing the `destroy`` command will ask you for confirmation. Once you confirm, the box will be gone.</p>
<p>You can <code class="docutils literal notranslate"><span class="pre">destroy</span></code> many objects in one go by providing a comma-separated list of objects (or a range of <code class="docutils literal notranslate"><span class="pre">#dbrefs</span></code>, if they are not in the same location) to the command.</p>
<p>It will ask you for confirmation. Once you give it, the box will be gone.</p>
<p>You can destroy many objects in one go by giving a comma-separated list of objects (or a range of #dbrefs, if they are not in the same location) to the command.</p>
</section>
<section id="adding-a-help-entry">
<h2><span class="section-number">1.9. </span>Adding a Help Entry<a class="headerlink" href="#adding-a-help-entry" title="Permalink to this headline"></a></h2>
<p>Command-related <code class="docutils literal notranslate"><span class="pre">help</span></code> entries are something that you modify in Python code — well cover that when we explain how to add Commands — but you may also add non-command-related help entries. For example, to explain something about the history of your game world:</p>
<p>The Command-help is something you modify in Python code. Well get to that when we get to how to add Commands. But you can also add regular help entries, for example to explain something about the history of your game world:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>sethelp History = At the dawn of time ...
</pre></div>
</div>
<p>You will now find your new <code class="docutils literal notranslate"><span class="pre">History</span></code> entry in the <code class="docutils literal notranslate"><span class="pre">help</span></code> list, and can read your help-text with <code class="docutils literal notranslate"><span class="pre">help</span> <span class="pre">History</span></code>.</p>
<p>You will now find your new <code class="docutils literal notranslate"><span class="pre">History</span></code> entry in the <code class="docutils literal notranslate"><span class="pre">help</span></code> list and read your help-text with <code class="docutils literal notranslate"><span class="pre">help</span> <span class="pre">History</span></code>.</p>
</section>
<section id="adding-a-world">
<h2><span class="section-number">1.10. </span>Adding a World<a class="headerlink" href="#adding-a-world" title="Permalink to this headline"></a></h2>
<p>After this brief introduction to building and using in-game commands, you may be ready to see a more fleshed-out example. Fortunately, Evennia comes with an tutorial world for you to explore — which we will try in the next lesson.</p>
<p>After this brief introduction to building and using in-game commands you may be ready to see a more fleshed-out example. Evennia comes with a tutorial world for you to explore. We will try that out in the next lesson.</p>
</section>
</section>
@ -367,18 +359,15 @@ You can&#39;t get that.
<a href="Beginner-Tutorial-Tutorial-World.html" title="2. The Tutorial World"
>next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Part1-Overview.html" title="Part 1: What We Have"
<a href="Beginner-Tutorial-Part1-Overview.html" title="Part 1: What we have"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">1. </span>Using Commands and Building Stuff</a></li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">1. </span>Using commands and building stuff</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="9. Parsing Command input" href="Beginner-Tutorial-More-on-Commands.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-More-on-Commands.html" title="9. Parsing Command input"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">10. </span>Creating things</a></li>
</ul>
</div>
</div>
<div class="document">
@ -105,18 +107,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Creating-Things.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -332,15 +322,12 @@ channel/sub channel name
<a href="Beginner-Tutorial-More-on-Commands.html" title="9. Parsing Command input"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">10. </span>Creating things</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="11. Searching for things" href="Beginner-Tutorial-Searching-Things.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Searching-Things.html" title="11. Searching for things"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">12. </span>Advanced searching - Django Database queries</a></li>
</ul>
</div>
</div>
<div class="document">
@ -103,18 +105,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Django-queries.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -535,15 +525,12 @@ in a format like the following:</p>
<a href="Beginner-Tutorial-Searching-Things.html" title="11. Searching for things"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">12. </span>Advanced searching - Django Database queries</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="5. Introduction to Python classes and objects" href="Beginner-Tutorial-Python-classes-and-objects.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Python-classes-and-objects.html" title="5. Introduction to Python classes and objects"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">6. </span>Overview of the Evennia library</a></li>
</ul>
</div>
</div>
<div class="document">
@ -99,18 +101,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Evennia-Library-Overview.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -261,15 +251,12 @@ from evennia.some_module.other_module import SomeClass
<a href="Beginner-Tutorial-Python-classes-and-objects.html" title="5. Introduction to Python classes and objects"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">6. </span>Overview of the Evennia library</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="3. Intro to using Python with Evennia" href="Beginner-Tutorial-Python-basic-introduction.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Python-basic-introduction.html" title="3. Intro to using Python with Evennia"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">4. </span>Overview of your new Game Dir</a></li>
</ul>
</div>
</div>
<div class="document">
@ -105,18 +107,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Gamedir-Overview.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -277,15 +267,12 @@ only particular parts of a default template without touching others.</p></li>
<a href="Beginner-Tutorial-Python-basic-introduction.html" title="3. Intro to using Python with Evennia"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">4. </span>Overview of your new Game Dir</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="6. Overview of the Evennia library" href="Beginner-Tutorial-Evennia-Library-Overview.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Evennia-Library-Overview.html" title="6. Overview of the Evennia library"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">7. </span>Making objects persistent</a></li>
</ul>
</div>
</div>
<div class="document">
@ -116,18 +118,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Learning-Typeclasses.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -277,8 +267,8 @@ called <code class="docutils literal notranslate"><span class="pre">create_objec
</div>
<p>Boom, Cuddly should now be in the room with you, a little less scary than Smaug. You specify the
python-path to the code you want and then set the key and location (if you had the <code class="docutils literal notranslate"><span class="pre">Monster</span></code> class already imported, you could have passed that too). Evennia sets things up and saves for you.</p>
<p>If you want to find Cuddly from anywhere (not just in the same room), you can use Evennias <code class="docutils literal notranslate"><span class="pre">search_object</span></code> function:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; py cuddly = evennia.search_object(&quot;Cuddly&quot;)[0] ; cuddly.move_around()
<p>If you want to find Smaug from anywhere (not just in the same room), you can use Evennias <code class="docutils literal notranslate"><span class="pre">search_object</span></code> function:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; cuddly = evennia.search_object(&quot;Cuddly&quot;)[0] ; cuddly.move_around()
Cuddly is moving!
</pre></div>
</div>
@ -529,7 +519,7 @@ Strength is 10.
<section id="attributes">
<h3><span class="section-number">7.3.2. </span>Attributes<a class="headerlink" href="#attributes" title="Permalink to this headline"></a></h3>
<p>So what happens when we increase our strength? This would be one way:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; py self.strength = self.strength + 1
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; py self.strength = self.str + 1
&gt; py self.strength
11
</pre></div>
@ -550,7 +540,8 @@ Strength is 10.
</div>
<p>After a reload all our changes were forgotten. When we change properties like this, it only changes in memory, not in the database (nor do we modify the python modules code). So when we reloaded, the fresh <code class="docutils literal notranslate"><span class="pre">Character</span></code> class was loaded, and it still has the original stats we wrote in it.</p>
<p>In principle we could change the python code. But we dont want to do that manually every time. And more importantly since we have the stats hardcoded in the class, <em>every</em> character instance in the game will have exactly the same <code class="docutils literal notranslate"><span class="pre">str</span></code>, <code class="docutils literal notranslate"><span class="pre">dex</span></code> and <code class="docutils literal notranslate"><span class="pre">int</span></code> now! This is clearly not what we want.</p>
<p>Evennia offers a special, persistent type of property for this, called an <code class="docutils literal notranslate"><span class="pre">Attribute</span></code>. Rework your <code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/characters.py</span></code> like this:</p>
<p>Evennia offers a special, persistent type of property for this, called an <code class="docutils literal notranslate"><span class="pre">Attribute</span></code>. Rework your
<code class="docutils literal notranslate"><span class="pre">mygame/typeclasses/characters.py</span></code> like this:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span>
<span class="k">class</span> <span class="nc">Character</span><span class="p">(</span><span class="n">DefaultCharacter</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
@ -639,7 +630,7 @@ set a random value from 3 to 18 to each stat. Simple, but for some classical RPG
</aside>
<p>Hm, this is the same values we set before. They are not random. The reason for this is of course that, as said, <code class="docutils literal notranslate"><span class="pre">at_object_creation</span></code> only runs <em>once</em>, the very first time a character is created. Our character object was already created long before, so it will not be called again.</p>
<p>Its simple enough to run it manually though:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; py self.at_object_creation()
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; self.at_object_creation()
&gt; py self.get_stats()
(5, 4, 8)
</pre></div>
@ -671,7 +662,7 @@ foo
<p>A python <em>for-loop</em> allows us to loop over something. Above, we made a <em>list</em> of two numbers and a string. In every iteration of the loop, the variable <code class="docutils literal notranslate"><span class="pre">a</span></code> becomes one element in turn, and we print that.</p>
<p>For our list, we want to loop over all Characters, and want to call <code class="docutils literal notranslate"><span class="pre">.at_object_creation</span></code> on each. This is how this is done (still in python multi-line mode):</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; from typeclasses.characters import Character
&gt; for char in Character.objects.all():
&gt; for char in Character.objects.all()
&gt; char.at_object_creation()
</pre></div>
</div>
@ -684,7 +675,7 @@ foo
of all of them that we then immediately loop over. Boom, we just updated all Characters, including ourselves:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; quit()
Closing the Python console.
&gt; py self.get_stats()
&gt; self.get_stats()
(3, 18, 10)
</pre></div>
</div>
@ -724,15 +715,12 @@ Oh, and if you created any other rooms before, make sure they get the new flag t
<a href="Beginner-Tutorial-Evennia-Library-Overview.html" title="6. Overview of the Evennia library"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">7. </span>Making objects persistent</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -17,12 +17,10 @@
<link rel="shortcut icon" href="../../../_static/favicon.ico"/>
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<link rel="next" title="Part 2: What We Want" href="../Part2/Beginner-Tutorial-Part2-Overview.html" />
<link rel="next" title="Part 2: What we want" href="../Part2/Beginner-Tutorial-Part2-Overview.html" />
<link rel="prev" title="12. Advanced searching - Django Database queries" href="Beginner-Tutorial-Django-queries.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -34,18 +32,22 @@
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../Part2/Beginner-Tutorial-Part2-Overview.html" title="Part 2: What We Want"
<a href="../Part2/Beginner-Tutorial-Part2-Overview.html" title="Part 2: What we want"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Django-queries.html" title="12. Advanced searching - Django Database queries"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">13. </span>Building a chair you can sit on</a></li>
</ul>
</div>
</div>
<div class="document">
@ -89,7 +91,7 @@
title="previous chapter"><span class="section-number">12. </span>Advanced searching - Django Database queries</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="../Part2/Beginner-Tutorial-Part2-Overview.html"
title="next chapter">Part 2: What We Want</a></p>
title="next chapter">Part 2: What we want</a></p>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
@ -108,18 +110,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Making-A-Sittable-Object.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -162,7 +152,7 @@ This requires a change to our Character typeclass. Open <code class="docutils li
</div>
<p>When moving somewhere, <a class="reference internal" href="../../../api/evennia.objects.objects.html#evennia.objects.objects.DefaultObject.move_to" title="evennia.objects.objects.DefaultObject.move_to"><span class="xref myst py py-meth">character.move_to</span></a> is called. This in turn
will call <code class="docutils literal notranslate"><span class="pre">character.at_pre_move</span></code>. If this returns <code class="docutils literal notranslate"><span class="pre">False</span></code>, the move is aborted.</p>
<p>Here we look for an Attribute <code class="docutils literal notranslate"><span class="pre">is_sitting</span></code> (which we will assign below) to determine if we are stuck on the chair or not.</p>
<p>Here we look for an Attribute <code class="docutils literal notranslate"><span class="pre">is_resting</span></code> (which we will assign below) to determine if we are stuck on the chair or not.</p>
</section>
<section id="making-the-chair-itself">
<h2><span class="section-number">13.2. </span>Making the Chair itself<a class="headerlink" href="#making-the-chair-itself" title="Permalink to this headline"></a></h2>
@ -261,7 +251,7 @@ will call <code class="docutils literal notranslate"><span class="pre">character
<span class="k">else</span><span class="p">:</span>
<span class="hll"> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">sitter</span> <span class="o">=</span> <span class="kc">None</span>
</span><span class="hll"> <span class="k">del</span> <span class="n">stander</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">is_sitting</span>
</span><span class="hll"> <span class="n">stander</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You stand up from </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
</span><span class="hll"> <span class="n">stander</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You stand up from </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
</span></pre></div></td></tr></table></div>
</div>
<p>This is the inverse of sitting down; we need to do some cleanup.</p>
@ -276,9 +266,9 @@ will call <code class="docutils literal notranslate"><span class="pre">character
<section id="sitting-on-or-in">
<h3><span class="section-number">13.2.1. </span>Sitting on or in?<a class="headerlink" href="#sitting-on-or-in" title="Permalink to this headline"></a></h3>
<p>Its fine to sit on a chair. But what if our Sittable is an armchair?</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;</span> <span class="n">py</span> <span class="n">armchair</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">create_object</span><span class="p">(</span><span class="s2">&quot;typeclasses.sittables.Sittable&quot;</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s2">&quot;armchair&quot;</span><span class="p">,</span> <span class="n">location</span><span class="o">=</span><span class="n">here</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="n">py</span> <span class="n">armchair</span><span class="o">.</span><span class="n">do_sit</span><span class="p">(</span><span class="n">me</span><span class="p">)</span>
<span class="n">You</span> <span class="n">sit</span> <span class="n">on</span> <span class="n">armchair</span><span class="o">.</span>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;</span> <span class="n">armchair</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">create_object</span><span class="p">(</span><span class="s2">&quot;typeclasses.sittables.Sittable&quot;</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s2">&quot;armchair&quot;</span><span class="p">,</span> <span class="n">location</span><span class="o">=</span><span class="n">here</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="n">armchair</span><span class="o">.</span><span class="n">do_sit</span><span class="p">(</span><span class="n">me</span><span class="p">)</span>
<span class="o">&gt;</span> <span class="n">You</span> <span class="n">sit</span> <span class="n">on</span> <span class="n">armchair</span><span class="o">.</span>
</pre></div>
</div>
<p>This is not grammatically correct, you actually sit “in” an armchair rather than “on” it. Its also possible to both sit in or on a chair depending on the type of chair (English is weird). We want to be able to control this.</p>
@ -327,9 +317,9 @@ will call <code class="docutils literal notranslate"><span class="pre">character
<span class="normal">42</span>
<span class="normal">43</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># in mygame/typeclasses/sittables.py</span>
<span class="kn">from</span> <span class="nn">typeclasses.objects</span> <span class="kn">import</span> <span class="n">Object</span>
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultObject</span>
<span class="k">class</span> <span class="nc">Sittable</span><span class="p">(</span><span class="n">Object</span><span class="p">):</span>
<span class="k">class</span> <span class="nc">Sittable</span><span class="p">(</span><span class="n">DefaultObject</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">do_sit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sitter</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
@ -343,16 +333,16 @@ will call <code class="docutils literal notranslate"><span class="pre">character
</span> <span class="n">current</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">sitter</span>
<span class="k">if</span> <span class="n">current</span><span class="p">:</span>
<span class="k">if</span> <span class="n">current</span> <span class="o">==</span> <span class="n">sitter</span><span class="p">:</span>
<span class="hll"> <span class="n">sitter</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You are already sitting </span><span class="si">{</span><span class="n">adjective</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
</span> <span class="k">else</span><span class="p">:</span>
<span class="n">sitter</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You are already sitting </span><span class="si">{</span><span class="n">adjective</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">sitter</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span>
<span class="hll"> <span class="sa">f</span><span class="s2">&quot;You can&#39;t sit </span><span class="si">{</span><span class="n">adjective</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2"> &quot;</span>
</span> <span class="sa">f</span><span class="s2">&quot;- </span><span class="si">{</span><span class="n">current</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2"> is already sitting there!&quot;</span><span class="p">)</span>
<span class="k">return</span>
<span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">sitter</span> <span class="o">=</span> <span class="n">sitter</span>
<span class="n">sitter</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">is_sitting</span> <span class="o">=</span> <span class="bp">self</span>
<span class="hll"> <span class="n">sitter</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You sit </span><span class="si">{</span><span class="n">adjective</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
</span>
<span class="n">sitter</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You sit </span><span class="si">{</span><span class="n">adjective</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">do_stand</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">stander</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Called when trying to stand from this object.</span>
@ -363,16 +353,16 @@ will call <code class="docutils literal notranslate"><span class="pre">character
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">current</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">sitter</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">stander</span> <span class="o">==</span> <span class="n">current</span><span class="p">:</span>
<span class="hll"> <span class="n">stander</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You are not sitting </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">adjective</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
</span> <span class="k">else</span><span class="p">:</span>
<span class="n">stander</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You are not sitting </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">adjective</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">sitter</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">del</span> <span class="n">stander</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">is_sitting</span>
<span class="hll"> <span class="n">stander</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You stand up from </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
<span class="hll"> <span class="n">stander</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;You stand up from </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
</span></pre></div></td></tr></table></div>
</div>
<ul class="simple">
<li><p><strong>Line 15</strong>: We grab the <code class="docutils literal notranslate"><span class="pre">adjective</span></code> Attribute. Using <code class="docutils literal notranslate"><span class="pre">self.db.adjective</span> <span class="pre">or</span> <span class="pre">&quot;on&quot;</span></code> here means that if the Attribute is not set (is <code class="docutils literal notranslate"><span class="pre">None</span></code>/falsy) the default “on” string will be assumed.</p></li>
<li><p><strong>Lines 19,22,27,39, and 43</strong>: We use this adjective to modify the return text we see.</p></li>
<li><p><strong>Lines 22 and 43</strong>: We use this adjective to modify the return text we see.</p></li>
</ul>
<p><code class="docutils literal notranslate"><span class="pre">reload</span></code> the server. An advantage of using Attributes like this is that they can be modified on the fly, in-game. Lets look at a builder could use this by normal building commands (no need for <code class="docutils literal notranslate"><span class="pre">py</span></code>):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;</span> <span class="nb">set</span> <span class="n">armchair</span><span class="o">/</span><span class="n">adjective</span> <span class="o">=</span> <span class="ow">in</span>
@ -418,13 +408,13 @@ You sit down and a whoopie cushion makes a loud fart noise!
<p>This way to implement <code class="docutils literal notranslate"><span class="pre">sit</span></code> and <code class="docutils literal notranslate"><span class="pre">stand</span></code> puts new cmdsets on the Sittable itself.
As weve learned before, commands on objects are made available to others in the room.
This makes the command easy but instead adds some complexity in the management of the CmdSet.</p>
<p>This is how it could look if <code class="docutils literal notranslate"><span class="pre">armchair</span></code> is in the room (Extra credits: Change the sit message on the armchair to match this output instead of getting the default <code class="docutils literal notranslate"><span class="pre">You</span> <span class="pre">sit</span> <span class="pre">in</span> <span class="pre">armchair</span></code>!):</p>
<p>This is how it could look if <code class="docutils literal notranslate"><span class="pre">armchair</span></code> is in the room (if you overrode the sit message):</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; sit
As you sit down in armchair, life feels easier.
</pre></div>
</div>
<p>What happens if there are sittables <code class="docutils literal notranslate"><span class="pre">sofa</span></code> and <code class="docutils literal notranslate"><span class="pre">barstool</span></code> also in the room? Evennia will
automatically handle this for us and allow us to specify which one we want:</p>
<p>What happens if there are sittables <code class="docutils literal notranslate"><span class="pre">sofa</span></code> and <code class="docutils literal notranslate"><span class="pre">barstool</span></code> also in the room? Evennia will automatically
handle this for us and allow us to specify which one we want:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; sit
More than one match for &#39;sit&#39; (please narrow target):
sit-1 (armchair)
@ -511,10 +501,10 @@ As you sit down in armchair, life feels easier.
<span class="normal">11</span>
<span class="normal">12</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># in mygame/typeclasses/sittables.py</span>
<span class="kn">from</span> <span class="nn">typeclasses.objects</span> <span class="kn">import</span> <span class="n">Object</span>
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultObject</span>
<span class="hll"><span class="kn">from</span> <span class="nn">commands.sittables</span> <span class="kn">import</span> <span class="n">CmdSetSit</span>
</span>
<span class="k">class</span> <span class="nc">Sittable</span><span class="p">(</span><span class="n">Object</span><span class="p">):</span>
<span class="k">class</span> <span class="nc">Sittable</span><span class="p">(</span><span class="n">DefaultObject</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> (docstring)</span>
<span class="sd"> &quot;&quot;&quot;</span>
@ -931,21 +921,18 @@ You stand up from sofa.
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../Part2/Beginner-Tutorial-Part2-Overview.html" title="Part 2: What We Want"
<a href="../Part2/Beginner-Tutorial-Part2-Overview.html" title="Part 2: What we want"
>next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Django-queries.html" title="12. Advanced searching - Django Database queries"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">13. </span>Building a chair you can sit on</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="8. Adding custom commands" href="Beginner-Tutorial-Adding-Commands.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Adding-Commands.html" title="8. Adding custom commands"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">9. </span>Parsing Command input</a></li>
</ul>
</div>
</div>
<div class="document">
@ -107,18 +109,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-More-on-Commands.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -637,15 +627,12 @@ Get What?
<a href="Beginner-Tutorial-Adding-Commands.html" title="8. Adding custom commands"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">9. </span>Parsing Command input</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -6,7 +6,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Part 1: What We Have &#8212; Evennia 2.x documentation</title>
<title>Part 1: What we have &#8212; Evennia 2.x documentation</title>
<link rel="stylesheet" href="../../../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
@ -17,12 +17,10 @@
<link rel="shortcut icon" href="../../../_static/favicon.ico"/>
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<link rel="next" title="1. Using Commands and Building Stuff" href="Beginner-Tutorial-Building-Quickstart.html" />
<link rel="next" title="1. Using commands and building stuff" href="Beginner-Tutorial-Building-Quickstart.html" />
<link rel="prev" title="Beginner Tutorial" href="../Beginner-Tutorial-Overview.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -34,17 +32,21 @@
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Building-Quickstart.html" title="1. Using Commands and Building Stuff"
<a href="Beginner-Tutorial-Building-Quickstart.html" title="1. Using commands and building stuff"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="../Beginner-Tutorial-Overview.html" title="Beginner Tutorial"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" accesskey="U">Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Part 1: What We Have</a></li>
<li class="nav-item nav-item-this"><a href="">Part 1: What we have</a></li>
</ul>
</div>
</div>
<div class="document">
@ -66,7 +68,7 @@
<script>$('#searchbox').show(0);</script>
<h3><a href="../../../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Part 1: What We Have</a><ul>
<li><a class="reference internal" href="#">Part 1: What we have</a><ul>
<li><a class="reference internal" href="#lessons">Lessons</a></li>
</ul>
</li>
@ -77,7 +79,7 @@
title="previous chapter">Beginner Tutorial</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="Beginner-Tutorial-Building-Quickstart.html"
title="next chapter"><span class="section-number">1. </span>Using Commands and Building Stuff</a></p>
title="next chapter"><span class="section-number">1. </span>Using commands and building stuff</a></p>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
@ -96,51 +98,39 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Part1-Overview.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section class="tex2jax_ignore mathjax_ignore" id="part-1-what-we-have">
<h1>Part 1: What We Have<a class="headerlink" href="#part-1-what-we-have" title="Permalink to this headline"></a></h1>
<h1>Part 1: What we have<a class="headerlink" href="#part-1-what-we-have" title="Permalink to this headline"></a></h1>
<aside class="sidebar">
<p class="sidebar-title">Beginner Tutorial Parts</p>
<ul class="simple">
<li><p><a class="reference internal" href="../Beginner-Tutorial-Overview.html"><span class="doc std std-doc">Introduction</span></a>
<br>Getting set up.</p></li>
<li><p><em>Part 1: <a class="reference internal" href="#"><span class="doc std std-doc">What We Have</span></a></em>
<li><p>Part 1: <strong><a class="reference internal" href="#"><span class="doc std std-doc">What we have</span></a></strong>
<br>A tour of Evennia and how to use the tools, including an introduction to Python.</p></li>
<li><p>Part 2: <a class="reference internal" href="../Part2/Beginner-Tutorial-Part2-Overview.html"><span class="doc std std-doc">What We Want</span></a>
<br>Planning our tutorial game and what to consider when planning your own.</p></li>
<li><p>Part 3: <a class="reference internal" href="../Part3/Beginner-Tutorial-Part3-Overview.html"><span class="doc std std-doc">How We Get There</span></a>
<br>Getting down to the meat of extending Evennia to make your game.</p></li>
<li><p>Part 4: <a class="reference internal" href="../Part4/Beginner-Tutorial-Part4-Overview.html"><span class="doc std std-doc">Using What We Created</span></a>
<br>Building a tech-demo and world content to go with our code.</p></li>
<li><p>Part 5: <a class="reference internal" href="../Part5/Beginner-Tutorial-Part5-Overview.html"><span class="doc std std-doc">Showing the World</span></a>
<br>Taking our new game online and letting players try it out.</p></li>
<li><p>Part 2: <a class="reference internal" href="../Part2/Beginner-Tutorial-Part2-Overview.html"><span class="doc std std-doc">What we want</span></a>
<br>Planning our tutorial game and what to think about when planning your own in the future.</p></li>
<li><p>Part 3: <a class="reference internal" href="../Part3/Beginner-Tutorial-Part3-Overview.html"><span class="doc std std-doc">How we get there</span></a>
<br>Getting down to the meat of extending Evennia to make our game</p></li>
<li><p>Part 4: <a class="reference internal" href="../Part4/Beginner-Tutorial-Part4-Overview.html"><span class="doc std std-doc">Using what we created</span></a>
<br>Building a tech-demo and world content to go with our code</p></li>
<li><p>Part 5: <a class="reference internal" href="../Part5/Beginner-Tutorial-Part5-Overview.html"><span class="doc std std-doc">Showing the world</span></a>
<br>Taking our new game online and let players try it out</p></li>
</ul>
</aside>
<p>In this first part, well focus on what we have out of the box with Evennia. Well familiarize you with the tools and how to find things that you are looking for. We will also dive into some of the things youll need to know to utilize the system fully, including giving you a brief rundown of Python concepts. If you are an experienced Python programmer, some sections may feel a bit basic yet seeing things in the context of Evennia will still be worthwhile.</p>
<p>In this first part well focus on what we get out of the box in Evennia - well get used to the tools and how to find things we are looking for. We will also dive into some of things youll need to know to fully utilize the system, including giving you a brief rundown of Python concepts. If you are an experienced Python programmer, some sections may feel a bit basic, but seeing things in the context of Evennia will still be worth learning.</p>
<section id="lessons">
<h2>Lessons<a class="headerlink" href="#lessons" title="Permalink to this headline"></a></h2>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="Beginner-Tutorial-Building-Quickstart.html">1. Using Commands and Building Stuff</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Beginner-Tutorial-Building-Quickstart.html#getting-help">1.1. Getting Help</a></li>
<li class="toctree-l2"><a class="reference internal" href="Beginner-Tutorial-Building-Quickstart.html#looking-around">1.2. Looking Around</a></li>
<li class="toctree-l2"><a class="reference internal" href="Beginner-Tutorial-Building-Quickstart.html#stepping-down-from-godhood">1.3. Stepping Down from Godhood</a></li>
<li class="toctree-l1"><a class="reference internal" href="Beginner-Tutorial-Building-Quickstart.html">1. Using commands and building stuff</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Beginner-Tutorial-Building-Quickstart.html#getting-help">1.1. Getting help</a></li>
<li class="toctree-l2"><a class="reference internal" href="Beginner-Tutorial-Building-Quickstart.html#looking-around">1.2. Looking around</a></li>
<li class="toctree-l2"><a class="reference internal" href="Beginner-Tutorial-Building-Quickstart.html#stepping-down-from-godhood">1.3. Stepping Down From Godhood</a></li>
<li class="toctree-l2"><a class="reference internal" href="Beginner-Tutorial-Building-Quickstart.html#creating-an-object">1.4. Creating an Object</a></li>
<li class="toctree-l2"><a class="reference internal" href="Beginner-Tutorial-Building-Quickstart.html#get-a-personality">1.5. Get a Personality</a></li>
<li class="toctree-l2"><a class="reference internal" href="Beginner-Tutorial-Building-Quickstart.html#pushing-your-buttons">1.6. Pushing Your Buttons</a></li>
@ -263,20 +253,17 @@
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Building-Quickstart.html" title="1. Using Commands and Building Stuff"
<a href="Beginner-Tutorial-Building-Quickstart.html" title="1. Using commands and building stuff"
>next</a> |</li>
<li class="right" >
<a href="../Beginner-Tutorial-Overview.html" title="Beginner Tutorial"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Part 1: What We Have</a></li>
<li class="nav-item nav-item-this"><a href="">Part 1: What we have</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="2. The Tutorial World" href="Beginner-Tutorial-Tutorial-World.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Tutorial-World.html" title="2. The Tutorial World"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">3. </span>Intro to using Python with Evennia</a></li>
</ul>
</div>
</div>
<div class="document">
@ -115,18 +117,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Python-basic-introduction.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -681,15 +671,12 @@ practice you will be writing most your code in Python modules.</p>
<a href="Beginner-Tutorial-Tutorial-World.html" title="2. The Tutorial World"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">3. </span>Intro to using Python with Evennia</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="4. Overview of your new Game Dir" href="Beginner-Tutorial-Gamedir-Overview.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Gamedir-Overview.html" title="4. Overview of your new Game Dir"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">5. </span>Introduction to Python classes and objects</a></li>
</ul>
</div>
</div>
<div class="document">
@ -105,18 +107,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Python-classes-and-objects.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -190,11 +180,12 @@ all one by one:</p>
</div>
<p>If there were <em>a lot</em> of functions, you could instead just import <code class="docutils literal notranslate"><span class="pre">test</span></code> and get the function
from there when you need (without having to give the full <code class="docutils literal notranslate"><span class="pre">world.test</span></code> every time):</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; from world import test ; test.hello_world(me)
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; from world import test ; test.hello_world(me
Hello World!
</pre></div>
</div>
<p>You can also <em>rename</em> stuff you import. Say for example that the module you import to already has a function <code class="docutils literal notranslate"><span class="pre">hello_world</span></code> but we also want to use the one from <code class="docutils literal notranslate"><span class="pre">world/test.py</span></code>:</p>
<p>You can also <em>rename</em> stuff you import. Say for example that the module you import to already
has a function <code class="docutils literal notranslate"><span class="pre">hello_world</span></code> but we also want to use the one from <code class="docutils literal notranslate"><span class="pre">world/test.py</span></code>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>from world.test import hello_world as test_hello_world
</pre></div>
</div>
@ -529,15 +520,12 @@ The world trembles.
<a href="Beginner-Tutorial-Gamedir-Overview.html" title="4. Overview of your new Game Dir"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">5. </span>Introduction to Python classes and objects</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="10. Creating things" href="Beginner-Tutorial-Creating-Things.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Creating-Things.html" title="10. Creating things"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">11. </span>Searching for things</a></li>
</ul>
</div>
</div>
<div class="document">
@ -110,18 +112,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Searching-Things.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -129,26 +119,27 @@
<section class="tex2jax_ignore mathjax_ignore" id="searching-for-things">
<h1><span class="section-number">11. </span>Searching for things<a class="headerlink" href="#searching-for-things" title="Permalink to this headline"></a></h1>
<p>We have gone through how to create the various entities in Evennia. But creating something is of little use if we cannot find and use it afterwards.</p>
<p>We have gone through how to create the various entities in Evennia. But creating something is of little use
if we cannot find and use it afterwards.</p>
<section id="main-search-functions">
<h2><span class="section-number">11.1. </span>Main search functions<a class="headerlink" href="#main-search-functions" title="Permalink to this headline"></a></h2>
<p>The base tools are the <code class="docutils literal notranslate"><span class="pre">evennia.search_*</span></code> functions, such as <code class="docutils literal notranslate"><span class="pre">evennia.search_object</span></code>.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">evennia</span>
<span class="n">roses</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">search_object</span><span class="p">(</span><span class="s2">&quot;rose&quot;</span><span class="p">)</span>
<span class="n">accts</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">search_account</span><span class="p">(</span><span class="s2">&quot;MyAccountName&quot;</span><span class="p">,</span> <span class="n">email</span><span class="o">=</span><span class="s2">&quot;foo@bar.com&quot;</span><span class="p">)</span>
<span class="n">roses</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">search_object</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="s2">&quot;rose&quot;</span><span class="p">)</span>
<span class="n">accts</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">search_account</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="s2">&quot;MyAccountName&quot;</span><span class="p">,</span> <span class="n">email</span><span class="o">=</span><span class="s2">&quot;foo@bar.com&quot;</span><span class="p">)</span>
</pre></div>
</div>
<aside class="sidebar">
<p class="sidebar-title">Querysets</p>
<p>What is returned from the main search functions is actually a <code class="docutils literal notranslate"><span class="pre">queryset</span></code>. They can be treated like lists except that they cant modified in-place. Well discuss querysets in the <code class="docutils literal notranslate"><span class="pre">next</span> <span class="pre">lesson</span></code> <Django-queries>`_.</p>
</aside>
<p>This searches by <code class="docutils literal notranslate"><span class="pre">key</span></code> of the object. Strings are always case-insensitive, so searching for <code class="docutils literal notranslate"><span class="pre">&quot;rose&quot;</span></code>, <code class="docutils literal notranslate"><span class="pre">&quot;Rose&quot;</span></code> or <code class="docutils literal notranslate"><span class="pre">&quot;rOsE&quot;</span></code> give the same results. Its important to remember that what is returned from these search methods is a <em>listing</em> of zero, one or more elements - all the matches to your search. To get the first match:</p>
<p>Strings are always case-insensitive, so searching for <code class="docutils literal notranslate"><span class="pre">&quot;rose&quot;</span></code>, <code class="docutils literal notranslate"><span class="pre">&quot;Rose&quot;</span></code> or <code class="docutils literal notranslate"><span class="pre">&quot;rOsE&quot;</span></code> give the same results. Its important to remember that what is returned from these search methods is a <em>listing</em> of zero, one or more elements - all the matches to your search. To get the first match:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>rose = roses[0]
</pre></div>
</div>
<p>Often you really want all matches to the search parameters you specify. In other situations, having zero or more than one match is a sign of a problem and you need to handle this case yourself.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span> <span class="n">the_one_ring</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">search_object</span><span class="p">(</span><span class="s2">&quot;The one Ring&quot;</span><span class="p">)</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span> <span class="n">the_one_ring</span> <span class="o">=</span> <span class="n">evennia</span><span class="o">.</span><span class="n">search_object</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="s2">&quot;The one Ring&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">the_one_ring</span><span class="p">:</span>
<span class="c1"># handle not finding the ring at all</span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">the_one_ring</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
@ -164,40 +155,39 @@
<section id="searching-using-object-search">
<h2><span class="section-number">11.2. </span>Searching using Object.search<a class="headerlink" href="#searching-using-object-search" title="Permalink to this headline"></a></h2>
<p>On the <code class="docutils literal notranslate"><span class="pre">DefaultObject</span></code> is a <code class="docutils literal notranslate"><span class="pre">.search</span></code> method which we have already tried out when we made Commands. For this to be used you must already have an object available:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>obj = evennia.search_object(&quot;My Object&quot;)[0] # assuming this exists
rose = obj.search(&quot;rose&quot;)
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>rose = obj.search(&quot;rose&quot;)
</pre></div>
</div>
<p>This searches for objects based on <code class="docutils literal notranslate"><span class="pre">key</span></code> or aliases. The <code class="docutils literal notranslate"><span class="pre">.search</span></code> method wraps <code class="docutils literal notranslate"><span class="pre">evennia.search_object</span></code> and handles its output in various ways.</p>
<ul class="simple">
<li><p>By default it will always search for objects among those in <code class="docutils literal notranslate"><span class="pre">obj.location.contents</span></code> and <code class="docutils literal notranslate"><span class="pre">obj.contents</span></code> (that is, things in objs inventory or in the same room).</p></li>
<li><p>It will always return exactly one match. If it found zero or more than one match, the return is <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is different from <code class="docutils literal notranslate"><span class="pre">evennia.search</span></code>, which always returns a list.</p></li>
<li><p>On a no-match or multimatch, <code class="docutils literal notranslate"><span class="pre">.search</span></code> will automatically send an error message to <code class="docutils literal notranslate"><span class="pre">obj</span></code>. So you dont have to worry about reporting messages if the result is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></li>
<li><p>It will always return exactly one match. If it found zero or more than one match, the return is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></li>
<li><p>On a no-match or multimatch, <code class="docutils literal notranslate"><span class="pre">.search</span></code> will automatically send an error message to <code class="docutils literal notranslate"><span class="pre">obj</span></code>.</p></li>
</ul>
<p>So this method handles error messaging for you. A very common way to use it is in commands:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
<span class="k">class</span> <span class="nc">CmdQuickFind</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; </span>
<span class="sd"> Find an item in your current location.</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; </span>
<span class="sd"> Find an item in your current location.</span>
<span class="sd"> Usage: </span>
<span class="sd"> quickfind &lt;query&gt;</span>
<span class="sd"> Usage: </span>
<span class="sd"> quickfind &lt;query&gt;</span>
<span class="sd"> </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">key</span> <span class="o">=</span> <span class="s2">&quot;quickfind&quot;</span>
<span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">query</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span>
<span class="n">query</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span>
<span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">query</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">result</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">result</span>
<span class="k">return</span>
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Found match for </span><span class="si">{</span><span class="n">query</span><span class="si">}</span><span class="s2">: </span><span class="si">{</span><span class="n">result</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Found match for </span><span class="si">{</span><span class="n">query</span><span class="si">}</span><span class="s2">: </span><span class="si">{</span><span class="n">foo</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>Remember, <code class="docutils literal notranslate"><span class="pre">self.caller</span></code> is the one calling the command. This is usually a Character, which
inherits from <code class="docutils literal notranslate"><span class="pre">DefaultObject</span></code>. So it has <code class="docutils literal notranslate"><span class="pre">.search()</span></code> available on it.</p>
inherits from <code class="docutils literal notranslate"><span class="pre">DefaultObject</span></code>!</p>
<p>This simple little Command takes its arguments and searches for a match. If it cant find it, <code class="docutils literal notranslate"><span class="pre">result</span></code> will be <code class="docutils literal notranslate"><span class="pre">None</span></code>. The error has already been reported to <code class="docutils literal notranslate"><span class="pre">self.caller</span></code> so we just abort with <code class="docutils literal notranslate"><span class="pre">return</span></code>.</p>
<p>With the <code class="docutils literal notranslate"><span class="pre">global_search</span></code> flag, you can use <code class="docutils literal notranslate"><span class="pre">.search</span></code> to find anything, not just stuff in the same room:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>volcano = self.caller.search(&quot;Vesuvio&quot;, global_search=True)
@ -430,15 +420,12 @@ We can also find what is inside each object. This is a list of things.</p>
<a href="Beginner-Tutorial-Creating-Things.html" title="10. Creating things"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">11. </span>Searching for things</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -18,11 +18,9 @@
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<link rel="next" title="3. Intro to using Python with Evennia" href="Beginner-Tutorial-Python-basic-introduction.html" />
<link rel="prev" title="1. Using Commands and Building Stuff" href="Beginner-Tutorial-Building-Quickstart.html" />
<link rel="prev" title="1. Using commands and building stuff" href="Beginner-Tutorial-Building-Quickstart.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -37,15 +35,19 @@
<a href="Beginner-Tutorial-Python-basic-introduction.html" title="3. Intro to using Python with Evennia"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Building-Quickstart.html" title="1. Using Commands and Building Stuff"
<a href="Beginner-Tutorial-Building-Quickstart.html" title="1. Using commands and building stuff"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" accesskey="U">Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">2. </span>The Tutorial World</a></li>
</ul>
</div>
</div>
<div class="document">
@ -80,7 +82,7 @@
<h4>Previous topic</h4>
<p class="topless"><a href="Beginner-Tutorial-Building-Quickstart.html"
title="previous chapter"><span class="section-number">1. </span>Using Commands and Building Stuff</a></p>
title="previous chapter"><span class="section-number">1. </span>Using commands and building stuff</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="Beginner-Tutorial-Python-basic-introduction.html"
title="next chapter"><span class="section-number">3. </span>Intro to using Python with Evennia</a></p>
@ -102,18 +104,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Tutorial-World.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -121,22 +111,27 @@
<section class="tex2jax_ignore mathjax_ignore" id="the-tutorial-world">
<h1><span class="section-number">2. </span>The Tutorial World<a class="headerlink" href="#the-tutorial-world" title="Permalink to this headline"></a></h1>
<p>The <em>Tutorial World</em> is a small, functioning MUD-style game world shipped with Evennia.
Its a small showcase of what is possible. It may also be useful for those who have an easier
<p>The <em>Tutorial World</em> is a small and functioning MUD-style game world shipped with Evennia.
Its a small showcase of what is possible. It can also be useful for those who have an easier
time learning by deconstructing existing code.</p>
<p>To install the tutorial world, stand in the Limbo room and input:</p>
<p>Stand in the Limbo room and install it with</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>batchcommand tutorial_world.build
</pre></div>
</div>
<p>This command runs the build script in <a class="reference external" href="https://github.com/evennia/evennia/blob/main/evennia/contrib/tutorials/tutorial_world/build.ev">evennia/contrib/tutorials/tutorial_world/build.ev</a>.
Basically, this script is a list of build-commands executed in sequence by the <code class="docutils literal notranslate"><span class="pre">batchcommand</span></code> command. Wait for the building to complete and dont run it twice.</p>
<p>What this does is to run the build script
<a class="reference external" href="https://github.com/evennia/evennia/blob/main/evennia/contrib/tutorials/tutorial_world/build.ev">evennia/contrib/tutorials/tutorial_world/build.ev</a>.
This is pretty much just a list of build-commands executed in sequence by the <code class="docutils literal notranslate"><span class="pre">batchcommand</span></code> command.
Wait for the building to complete and dont run it twice.</p>
<blockquote>
<div><p>After having run the batchcommand, the <code class="docutils literal notranslate"><span class="pre">intro</span></code> command becomes available in Limbo. Try it out for in-game help using an example of <a class="reference internal" href="../../../Components/EvMenu.html"><span class="doc std std-doc">EvMenu</span></a>, Evennias in-built
<div><p>After having run the batchcommand, the <code class="docutils literal notranslate"><span class="pre">intro</span></code> command also becomes available in Limbo. Try it out to
for in-game help and to get an example of <a class="reference internal" href="../../../Components/EvMenu.html"><span class="doc std std-doc">EvMenu</span></a>, Evennias in-built
menu generation system!</p>
</div></blockquote>
<p>The tutorial world consists of a single-player quest and has some 20 rooms to explore as you seek to discover the whereabouts of a mythical weapon.</p>
<p>A new exit should have appeared named <em>Tutorial</em>. Enter the tutorial world by typing <code class="docutils literal notranslate"><span class="pre">tutorial</span></code>.</p>
<p>You will automatically <code class="docutils literal notranslate"><span class="pre">quell</span></code> when you enter (and <code class="docutils literal notranslate"><span class="pre">unquell</span></code> when you leave), so you can play the way it was intended. Whether you are triumphant or use the <code class="docutils literal notranslate"><span class="pre">give</span> <span class="pre">up</span></code> command, you will eventually end up back in Limbo.</p>
<p>The game consists of a single-player quest and has some 20 rooms that you can explore as you seek
to discover the whereabouts of a mythical weapon.</p>
<p>A new exit should have appeared named <em>Tutorial</em>. Enter by writing <code class="docutils literal notranslate"><span class="pre">tutorial</span></code>.</p>
<p>You will automatically <code class="docutils literal notranslate"><span class="pre">quell</span></code> when you enter (and <code class="docutils literal notranslate"><span class="pre">unquell</span></code> when you leave), so you can play the way it was intended.
Both if you are triumphant or if you use the <code class="docutils literal notranslate"><span class="pre">give</span> <span class="pre">up</span></code> command you will eventually end up back in Limbo.</p>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>Only LOSERS and QUITTERS use the <code class="docutils literal notranslate"><span class="pre">give</span> <span class="pre">up</span></code> command.</p>
@ -145,8 +140,12 @@ menu generation system!</p>
<h2><span class="section-number">2.1. </span>Gameplay<a class="headerlink" href="#gameplay" title="Permalink to this headline"></a></h2>
<p><img alt="the castle off the moor" src="https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/22916c25-6299-453d-a221-446ec839f567/da2pmzu-46d63c6d-9cdc-41dd-87d6-1106db5a5e1a.jpg/v1/fill/w_600,h_849,q_75,strp/the_castle_off_the_moor_by_griatch_art_da2pmzu-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3siaGVpZ2h0IjoiPD04NDkiLCJwYXRoIjoiXC9mXC8yMjkxNmMyNS02Mjk5LTQ1M2QtYTIyMS00NDZlYzgzOWY1NjdcL2RhMnBtenUtNDZkNjNjNmQtOWNkYy00MWRkLTg3ZDYtMTEwNmRiNWE1ZTFhLmpwZyIsIndpZHRoIjoiPD02MDAifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.omuS3D1RmFiZCy9OSXiIita-HxVGrBok3_7asq0rflw" />
(image by Griatch)</p>
<p><em>To get into the mood of our miniature quest, imagine you are an adventurer out to find fame and fortune. You have heard rumours of an old castle ruin by the coast. In its depths, a warrior princess was buried together with her powerful magical weapon — a valuable prize, if true. Of course, this is a chance for adventure that you simply cannot turn down!</em></p>
<p><em>You reach the ocean in the midst of a raging thunderstorm. With wind and rain screaming in your face, you stand where the moor meets the sea along a high, rocky coast…</em></p>
<p><em>To get into the mood of this miniature quest, imagine you are an adventurer out to find fame and
fortune. You have heard rumours of an old castle ruin by the coast. In its depth a warrior princess
was buried together with her powerful magical weapon - a valuable prize, if its true. Of course
this is a chance to adventure that you cannot turn down!</em></p>
<p><em>You reach the ocean in the midst of a raging thunderstorm. With wind and rain screaming in your
face you stand where the moor meets the sea along a high, rocky coast …</em></p>
<hr class="docutils" />
<section id="gameplay-hints">
<h3><span class="section-number">2.1.1. </span>Gameplay hints<a class="headerlink" href="#gameplay-hints" title="Permalink to this headline"></a></h3>
@ -231,18 +230,15 @@ The build-script is <a class="reference external" href="https://github.com/evenn
<a href="Beginner-Tutorial-Python-basic-introduction.html" title="3. Intro to using Python with Evennia"
>next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Building-Quickstart.html" title="1. Using Commands and Building Stuff"
<a href="Beginner-Tutorial-Building-Quickstart.html" title="1. Using commands and building stuff"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What We Have</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part1-Overview.html" >Part 1: What we have</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">2. </span>The Tutorial World</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="1. Where do I begin?" href="Beginner-Tutorial-Planning-Where-Do-I-Begin.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Planning-Where-Do-I-Begin.html" title="1. Where do I begin?"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part2-Overview.html" accesskey="U">Part 2: What We Want</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part2-Overview.html" accesskey="U">Part 2: What we want</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">2. </span>On Planning a Game</a></li>
</ul>
</div>
</div>
<div class="document">
@ -112,18 +114,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Game-Planning.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -351,15 +341,12 @@ have made their dream game a reality!</p>
<a href="Beginner-Tutorial-Planning-Where-Do-I-Begin.html" title="1. Where do I begin?"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part2-Overview.html" >Part 2: What We Want</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part2-Overview.html" >Part 2: What we want</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">2. </span>On Planning a Game</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -6,7 +6,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Part 2: What We Want &#8212; Evennia 2.x documentation</title>
<title>Part 2: What we want &#8212; Evennia 2.x documentation</title>
<link rel="stylesheet" href="../../../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
@ -21,8 +21,6 @@
<link rel="prev" title="13. Building a chair you can sit on" href="../Part1/Beginner-Tutorial-Making-A-Sittable-Object.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,11 +38,15 @@
<a href="../Part1/Beginner-Tutorial-Making-A-Sittable-Object.html" title="13. Building a chair you can sit on"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" accesskey="U">Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Part 2: What We Want</a></li>
<li class="nav-item nav-item-this"><a href="">Part 2: What we want</a></li>
</ul>
</div>
</div>
<div class="document">
@ -66,7 +68,7 @@
<script>$('#searchbox').show(0);</script>
<h3><a href="../../../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Part 2: What We Want</a><ul>
<li><a class="reference internal" href="#">Part 2: What we want</a><ul>
<li><a class="reference internal" href="#lessons">Lessons</a></li>
</ul>
</li>
@ -96,44 +98,34 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Part2-Overview.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section class="tex2jax_ignore mathjax_ignore" id="part-2-what-we-want">
<h1>Part 2: What We Want<a class="headerlink" href="#part-2-what-we-want" title="Permalink to this headline"></a></h1>
<h1>Part 2: What we want<a class="headerlink" href="#part-2-what-we-want" title="Permalink to this headline"></a></h1>
<aside class="sidebar">
<p class="sidebar-title">Beginner Tutorial Parts</p>
<ul class="simple">
<li><p><a class="reference internal" href="../Beginner-Tutorial-Overview.html"><span class="doc std std-doc">Introduction</span></a>
<br>Getting set up.</p></li>
<li><p>Part 1: <a class="reference internal" href="../Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">What We Have</span></a>
<li><p>Part 1: <a class="reference internal" href="../Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">What we have</span></a>
<br>A tour of Evennia and how to use the tools, including an introduction to Python.</p></li>
<li><p><em>Part 2: <a class="reference internal" href="#"><span class="doc std std-doc">What We Want</span></a></em>
<br>Planning our tutorial game and what to consider when planning your own.</p></li>
<li><p>Part 3: <a class="reference internal" href="../Part3/Beginner-Tutorial-Part3-Overview.html"><span class="doc std std-doc">How We Get There</span></a>
<br>Getting down to the meat of extending Evennia to make your game.</p></li>
<li><p>Part 4: <a class="reference internal" href="../Part4/Beginner-Tutorial-Part4-Overview.html"><span class="doc std std-doc">Using What We Created</span></a>
<br>Building a tech-demo and world content to go with our code.</p></li>
<li><p>Part 5: <a class="reference internal" href="../Part5/Beginner-Tutorial-Part5-Overview.html"><span class="doc std std-doc">Showing the World</span></a>
<br>Taking our new game online and letting players try it out.</p></li>
<li><p><strong>Part 2: <a class="reference internal" href="#"><span class="doc std std-doc">What we want</span></a></strong>
<br>Planning our tutorial game and what to think about when planning your own in the future.</p></li>
<li><p>Part 3: <a class="reference internal" href="../Part3/Beginner-Tutorial-Part3-Overview.html"><span class="doc std std-doc">How we get there</span></a>
<br>Getting down to the meat of extending Evennia to make our game</p></li>
<li><p>Part 4: <a class="reference internal" href="../Part4/Beginner-Tutorial-Part4-Overview.html"><span class="doc std std-doc">Using what we created</span></a>
<br>Building a tech-demo and world content to go with our code</p></li>
<li><p>Part 5: <a class="reference internal" href="../Part5/Beginner-Tutorial-Part5-Overview.html"><span class="doc std std-doc">Showing the world</span></a>
<br>Taking our new game online and let players try it out</p></li>
</ul>
</aside>
<p>In Part Two of the Evennia Beginner Tutorial, well take a step back to plan the type of tutorial game that you will create. This part is more theoretical in that we wont do any hands-on programming.</p>
<p>In the process, well address the common questions of “where to start” and “what to think about” when creating a multiplayer online text game.</p>
<p>In Part two of the Evennia Beginner Tutorial well take a step back and plan out the kind of tutorial game we want to make. This is a more theoretical part where we wont do any hands-on
programming.</p>
<p>In the process well go through the common questions of “where to start”
and “what to think about” when creating a multiplayer online text game.</p>
<section id="lessons">
<h2>Lessons<a class="headerlink" href="#lessons" title="Permalink to this headline"></a></h2>
<div class="toctree-wrapper compound">
@ -194,14 +186,11 @@
<a href="../Part1/Beginner-Tutorial-Making-A-Sittable-Object.html" title="13. Building a chair you can sit on"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Part 2: What We Want</a></li>
<li class="nav-item nav-item-this"><a href="">Part 2: What we want</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -17,12 +17,10 @@
<link rel="shortcut icon" href="../../../_static/favicon.ico"/>
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<link rel="next" title="Part 3: How We Get There (Example Game)" href="../Part3/Beginner-Tutorial-Part3-Overview.html" />
<link rel="next" title="Part 3: How we get there (example game)" href="../Part3/Beginner-Tutorial-Part3-Overview.html" />
<link rel="prev" title="2. On Planning a Game" href="Beginner-Tutorial-Game-Planning.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -34,18 +32,22 @@
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../Part3/Beginner-Tutorial-Part3-Overview.html" title="Part 3: How We Get There (Example Game)"
<a href="../Part3/Beginner-Tutorial-Part3-Overview.html" title="Part 3: How we get there (example game)"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Game-Planning.html" title="2. On Planning a Game"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part2-Overview.html" accesskey="U">Part 2: What We Want</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part2-Overview.html" accesskey="U">Part 2: What we want</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">3. </span>Planning our tutorial game</a></li>
</ul>
</div>
</div>
<div class="document">
@ -129,7 +131,7 @@
title="previous chapter"><span class="section-number">2. </span>On Planning a Game</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="../Part3/Beginner-Tutorial-Part3-Overview.html"
title="next chapter">Part 3: How We Get There (Example Game)</a></p>
title="next chapter">Part 3: How we get there (example game)</a></p>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
@ -148,18 +150,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Planning-The-Tutorial-Game.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -576,21 +566,18 @@ playable game!</p>
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../Part3/Beginner-Tutorial-Part3-Overview.html" title="Part 3: How We Get There (Example Game)"
<a href="../Part3/Beginner-Tutorial-Part3-Overview.html" title="Part 3: How we get there (example game)"
>next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Game-Planning.html" title="2. On Planning a Game"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part2-Overview.html" >Part 2: What We Want</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part2-Overview.html" >Part 2: What we want</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">3. </span>Planning our tutorial game</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -18,11 +18,9 @@
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<link rel="next" title="2. On Planning a Game" href="Beginner-Tutorial-Game-Planning.html" />
<link rel="prev" title="Part 2: What We Want" href="Beginner-Tutorial-Part2-Overview.html" />
<link rel="prev" title="Part 2: What we want" href="Beginner-Tutorial-Part2-Overview.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -37,15 +35,19 @@
<a href="Beginner-Tutorial-Game-Planning.html" title="2. On Planning a Game"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Part2-Overview.html" title="Part 2: What We Want"
<a href="Beginner-Tutorial-Part2-Overview.html" title="Part 2: What we want"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part2-Overview.html" accesskey="U">Part 2: What We Want</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part2-Overview.html" accesskey="U">Part 2: What we want</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">1. </span>Where do I begin?</a></li>
</ul>
</div>
</div>
<div class="document">
@ -82,7 +84,7 @@
<h4>Previous topic</h4>
<p class="topless"><a href="Beginner-Tutorial-Part2-Overview.html"
title="previous chapter">Part 2: What We Want</a></p>
title="previous chapter">Part 2: What we want</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="Beginner-Tutorial-Game-Planning.html"
title="next chapter"><span class="section-number">2. </span>On Planning a Game</a></p>
@ -104,18 +106,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Planning-Where-Do-I-Begin.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -277,18 +267,15 @@ then try to answer those questions for the sake of creating our little tutorial
<a href="Beginner-Tutorial-Game-Planning.html" title="2. On Planning a Game"
>next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Part2-Overview.html" title="Part 2: What We Want"
<a href="Beginner-Tutorial-Part2-Overview.html" title="Part 2: What we want"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part2-Overview.html" >Part 2: What We Want</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part2-Overview.html" >Part 2: What we want</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">1. </span>Where do I begin?</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="11. Turnbased Combat" href="Beginner-Tutorial-Combat-Turnbased.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Combat-Turnbased.html" title="11. Turnbased Combat"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">12. </span>NPC and monster AI</a></li>
</ul>
</div>
</div>
<div class="document">
@ -89,18 +91,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-AI.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -136,15 +126,12 @@
<a href="Beginner-Tutorial-Combat-Turnbased.html" title="11. Turnbased Combat"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">12. </span>NPC and monster AI</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="2. Rules and dice rolling" href="Beginner-Tutorial-Rules.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Rules.html" title="2. Rules and dice rolling"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">3. </span>Player Characters</a></li>
</ul>
</div>
</div>
<div class="document">
@ -107,18 +109,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Characters.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -551,15 +541,12 @@ then on.</p>
<a href="Beginner-Tutorial-Rules.html" title="2. Rules and dice rolling"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">3. </span>Player Characters</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="5. Handling Equipment" href="Beginner-Tutorial-Equipment.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Equipment.html" title="5. Handling Equipment"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">6. </span>Character Generation</a></li>
</ul>
</div>
</div>
<div class="document">
@ -110,18 +112,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Chargen.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -696,7 +686,7 @@ we use <code class="docutils literal notranslate"><span class="pre">caller.msg()
<span class="n">tmp_character</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;tmp_character&quot;</span><span class="p">]</span>
<span class="n">new_character</span> <span class="o">=</span> <span class="n">tmp_character</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">caller</span><span class="p">)</span>
<span class="n">caller</span><span class="o">.</span><span class="n">account</span><span class="o">.</span><span class="n">add_character</span><span class="p">(</span><span class="n">new_character</span><span class="p">)</span>
<span class="n">caller</span><span class="o">.</span><span class="n">account</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">_playable_characters</span> <span class="o">=</span> <span class="p">[</span><span class="n">new_character</span><span class="p">]</span>
<span class="n">text</span> <span class="o">=</span> <span class="s2">&quot;Character created!&quot;</span>
@ -722,6 +712,7 @@ we use <code class="docutils literal notranslate"><span class="pre">caller.msg()
<span class="c1"># this generates all random components of the character</span>
<span class="n">tmp_character</span> <span class="o">=</span> <span class="n">TemporaryCharacterSheet</span><span class="p">()</span>
<span class="n">tmp_character</span><span class="o">.</span><span class="n">generate</span><span class="p">()</span>
<span class="n">EvMenu</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">menutree</span><span class="p">,</span> <span class="n">session</span><span class="o">=</span><span class="n">session</span><span class="p">,</span>
<span class="n">startnode</span><span class="o">=</span><span class="s2">&quot;node_chargen&quot;</span><span class="p">,</span> <span class="c1"># &lt;----- </span>
@ -763,15 +754,12 @@ characters - how they store their stats, handle their equipment and how to creat
<a href="Beginner-Tutorial-Equipment.html" title="5. Handling Equipment"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">6. </span>Character Generation</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="8. Non-Player-Characters" href="Beginner-Tutorial-NPCs.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-NPCs.html" title="8. Non-Player-Characters"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">9. </span>Combat base framework</a></li>
</ul>
</div>
</div>
<div class="document">
@ -114,18 +116,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Combat-Base.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -473,7 +463,9 @@
<span class="normal">46</span>
<span class="normal">47</span>
<span class="normal">48</span>
<span class="normal">49</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># in evadventure/combat_base.py</span>
<span class="normal">49</span>
<span class="normal">50</span>
<span class="normal">51</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># in evadventure/combat_base.py</span>
<span class="c1"># ...</span>
@ -488,20 +480,22 @@
<span class="k">def</span> <span class="nf">get_combat_summary</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">combatant</span><span class="p">):</span>
<span class="hll"> <span class="n">allies</span><span class="p">,</span> <span class="n">enemies</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_sides</span><span class="p">(</span><span class="n">combatant</span><span class="p">)</span>
</span> <span class="c1"># we must include outselves at the top of the list (we are not returned from get_sides)</span>
<span class="hll"> <span class="n">allies</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">combatant</span><span class="p">)</span>
</span> <span class="n">nallies</span><span class="p">,</span> <span class="n">nenemies</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">allies</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="n">enemies</span><span class="p">)</span>
<span class="hll">
</span> <span class="c1"># prepare colors and hurt-levels</span>
<span class="n">allies</span> <span class="o">=</span> <span class="p">[</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">ally</span><span class="si">}</span><span class="s2"> (</span><span class="si">{</span><span class="n">ally</span><span class="o">.</span><span class="n">hurt_level</span><span class="si">}</span><span class="s2">)&quot;</span> <span class="k">for</span> <span class="n">ally</span> <span class="ow">in</span> <span class="n">allies</span><span class="p">]</span>
<span class="n">enemies</span> <span class="o">=</span> <span class="p">[</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">enemy</span><span class="si">}</span><span class="s2"> (</span><span class="si">{</span><span class="n">enemy</span><span class="o">.</span><span class="n">hurt_level</span><span class="si">}</span><span class="s2">)&quot;</span> <span class="k">for</span> <span class="n">enemy</span> <span class="ow">in</span> <span class="n">enemies</span><span class="p">]</span>
<span class="hll">
</span><span class="hll"> <span class="c1"># the center column with the &#39;vs&#39;</span>
</span> <span class="n">vs_column</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;&quot;</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">nallies</span><span class="p">,</span> <span class="n">nenemies</span><span class="p">))]</span>
<span class="c1"># prepare colors and hurt-levels</span>
<span class="hll"> <span class="n">allies</span> <span class="o">=</span> <span class="p">[</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">ally</span><span class="si">}</span><span class="s2"> (</span><span class="si">{</span><span class="n">ally</span><span class="o">.</span><span class="n">hurt_level</span><span class="si">}</span><span class="s2">)&quot;</span> <span class="k">for</span> <span class="n">ally</span> <span class="ow">in</span> <span class="n">allies</span><span class="p">]</span>
</span><span class="hll"> <span class="n">enemies</span> <span class="o">=</span> <span class="p">[</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">enemy</span><span class="si">}</span><span class="s2"> (</span><span class="si">{</span><span class="n">enemy</span><span class="o">.</span><span class="n">hurt_level</span><span class="si">}</span><span class="s2">)&quot;</span> <span class="k">for</span> <span class="n">enemy</span> <span class="ow">in</span> <span class="n">enemies</span><span class="p">]</span>
</span>
<span class="c1"># the center column with the &#39;vs&#39;</span>
<span class="n">vs_column</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;&quot;</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">nallies</span><span class="p">,</span> <span class="n">nenemies</span><span class="p">))]</span>
<span class="n">vs_column</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="n">vs_column</span><span class="p">)</span> <span class="o">//</span> <span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;|wvs|n&quot;</span>
<span class="c1"># the two allies / enemies columns should be centered vertically</span>
<span class="n">diff</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">nallies</span> <span class="o">-</span> <span class="n">nenemies</span><span class="p">)</span>
<span class="hll"> <span class="n">top_empty</span> <span class="o">=</span> <span class="n">diff</span> <span class="o">//</span> <span class="mi">2</span>
</span> <span class="n">bot_empty</span> <span class="o">=</span> <span class="n">diff</span> <span class="o">-</span> <span class="n">top_empty</span>
<span class="hll"> <span class="c1"># the two allies / enemies columns should be centered vertically</span>
</span> <span class="n">diff</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">nallies</span> <span class="o">-</span> <span class="n">nenemies</span><span class="p">)</span>
<span class="n">top_empty</span> <span class="o">=</span> <span class="n">diff</span> <span class="o">//</span> <span class="mi">2</span>
<span class="n">bot_empty</span> <span class="o">=</span> <span class="n">diff</span> <span class="o">-</span> <span class="n">top_empty</span>
<span class="n">topfill</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;&quot;</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">top_empty</span><span class="p">)]</span>
<span class="n">botfill</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;&quot;</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">bot_empty</span><span class="p">)]</span>
@ -511,10 +505,10 @@
<span class="n">allies</span> <span class="o">=</span> <span class="n">topfill</span> <span class="o">+</span> <span class="n">allies</span> <span class="o">+</span> <span class="n">botfill</span>
<span class="c1"># make a table with three columns</span>
<span class="k">return</span> <span class="n">evtable</span><span class="o">.</span><span class="n">EvTable</span><span class="p">(</span>
<span class="n">table</span><span class="o">=</span><span class="p">[</span>
<span class="hll"> <span class="n">evtable</span><span class="o">.</span><span class="n">EvColumn</span><span class="p">(</span><span class="o">*</span><span class="n">allies</span><span class="p">,</span> <span class="n">align</span><span class="o">=</span><span class="s2">&quot;l&quot;</span><span class="p">),</span>
</span> <span class="n">evtable</span><span class="o">.</span><span class="n">EvColumn</span><span class="p">(</span><span class="o">*</span><span class="n">vs_column</span><span class="p">,</span> <span class="n">align</span><span class="o">=</span><span class="s2">&quot;c&quot;</span><span class="p">),</span>
<span class="hll"> <span class="k">return</span> <span class="n">evtable</span><span class="o">.</span><span class="n">EvTable</span><span class="p">(</span>
</span> <span class="n">table</span><span class="o">=</span><span class="p">[</span>
<span class="n">evtable</span><span class="o">.</span><span class="n">EvColumn</span><span class="p">(</span><span class="o">*</span><span class="n">allies</span><span class="p">,</span> <span class="n">align</span><span class="o">=</span><span class="s2">&quot;l&quot;</span><span class="p">),</span>
<span class="n">evtable</span><span class="o">.</span><span class="n">EvColumn</span><span class="p">(</span><span class="o">*</span><span class="n">vs_column</span><span class="p">,</span> <span class="n">align</span><span class="o">=</span><span class="s2">&quot;c&quot;</span><span class="p">),</span>
<span class="n">evtable</span><span class="o">.</span><span class="n">EvColumn</span><span class="p">(</span><span class="o">*</span><span class="n">enemies</span><span class="p">,</span> <span class="n">align</span><span class="o">=</span><span class="s2">&quot;r&quot;</span><span class="p">),</span>
<span class="p">],</span>
<span class="n">border</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
@ -968,15 +962,12 @@
<a href="Beginner-Tutorial-NPCs.html" title="8. Non-Player-Characters"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">9. </span>Combat base framework</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="10. Twitch Combat" href="Beginner-Tutorial-Combat-Twitch.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Combat-Twitch.html" title="10. Twitch Combat"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">11. </span>Turnbased Combat</a></li>
</ul>
</div>
</div>
<div class="document">
@ -126,18 +128,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Combat-Turnbased.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -149,66 +139,66 @@
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>&gt;<span class="w"> </span>attack<span class="w"> </span>Troll
______________________________________________________________________________
<span class="w"> </span>You<span class="w"> </span><span class="o">(</span>Perfect<span class="o">)</span><span class="w"> </span>vs<span class="w"> </span>Troll<span class="w"> </span><span class="o">(</span>Perfect<span class="o">)</span>
<span class="w"> </span>You<span class="w"> </span><span class="o">(</span>Perfect<span class="o">)</span><span class="w"> </span>vs<span class="w"> </span>Troll<span class="w"> </span><span class="o">(</span>Perfect<span class="o">)</span><span class="w"> </span>
<span class="w"> </span>Your<span class="w"> </span>queued<span class="w"> </span>action:<span class="w"> </span><span class="o">[</span>attack<span class="o">]</span><span class="w"> </span><span class="o">(</span>22s<span class="w"> </span><span class="k">until</span><span class="w"> </span>next<span class="w"> </span>round,
<span class="w"> </span>or<span class="w"> </span><span class="k">until</span><span class="w"> </span>all<span class="w"> </span>combatants<span class="w"> </span>have<span class="w"> </span>chosen<span class="w"> </span>their<span class="w"> </span>next<span class="w"> </span>action<span class="o">)</span>.
______________________________________________________________________________
<span class="w"> </span><span class="m">1</span>:<span class="w"> </span>attack<span class="w"> </span>an<span class="w"> </span>enemy
<span class="w"> </span><span class="m">2</span>:<span class="w"> </span>Stunt<span class="w"> </span>-<span class="w"> </span>gain<span class="w"> </span>a<span class="w"> </span>later<span class="w"> </span>advantage<span class="w"> </span>against<span class="w"> </span>a<span class="w"> </span>target
<span class="w"> </span><span class="m">3</span>:<span class="w"> </span>Stunt<span class="w"> </span>-<span class="w"> </span>give<span class="w"> </span>an<span class="w"> </span>enemy<span class="w"> </span>disadvantage<span class="w"> </span>against<span class="w"> </span>yourself<span class="w"> </span>or<span class="w"> </span>an<span class="w"> </span>ally
<span class="w"> </span><span class="m">4</span>:<span class="w"> </span>Use<span class="w"> </span>an<span class="w"> </span>item<span class="w"> </span>on<span class="w"> </span>yourself<span class="w"> </span>or<span class="w"> </span>an<span class="w"> </span>ally
<span class="w"> </span><span class="m">5</span>:<span class="w"> </span>Use<span class="w"> </span>an<span class="w"> </span>item<span class="w"> </span>on<span class="w"> </span>an<span class="w"> </span>enemy
<span class="w"> </span><span class="m">6</span>:<span class="w"> </span>Wield/swap<span class="w"> </span>with<span class="w"> </span>an<span class="w"> </span>item<span class="w"> </span>from<span class="w"> </span>inventory
<span class="w"> </span><span class="m">7</span>:<span class="w"> </span>flee!
<span class="w"> </span><span class="m">8</span>:<span class="w"> </span>hold,<span class="w"> </span>doing<span class="w"> </span>nothing
<span class="w"> </span><span class="m">1</span>:<span class="w"> </span>attack<span class="w"> </span>an<span class="w"> </span>enemy<span class="w"> </span>
<span class="w"> </span><span class="m">2</span>:<span class="w"> </span>Stunt<span class="w"> </span>-<span class="w"> </span>gain<span class="w"> </span>a<span class="w"> </span>later<span class="w"> </span>advantage<span class="w"> </span>against<span class="w"> </span>a<span class="w"> </span>target<span class="w"> </span>
<span class="w"> </span><span class="m">3</span>:<span class="w"> </span>Stunt<span class="w"> </span>-<span class="w"> </span>give<span class="w"> </span>an<span class="w"> </span>enemy<span class="w"> </span>disadvantage<span class="w"> </span>against<span class="w"> </span>yourself<span class="w"> </span>or<span class="w"> </span>an<span class="w"> </span>ally<span class="w"> </span>
<span class="w"> </span><span class="m">4</span>:<span class="w"> </span>Use<span class="w"> </span>an<span class="w"> </span>item<span class="w"> </span>on<span class="w"> </span>yourself<span class="w"> </span>or<span class="w"> </span>an<span class="w"> </span>ally<span class="w"> </span>
<span class="w"> </span><span class="m">5</span>:<span class="w"> </span>Use<span class="w"> </span>an<span class="w"> </span>item<span class="w"> </span>on<span class="w"> </span>an<span class="w"> </span>enemy<span class="w"> </span>
<span class="w"> </span><span class="m">6</span>:<span class="w"> </span>Wield/swap<span class="w"> </span>with<span class="w"> </span>an<span class="w"> </span>item<span class="w"> </span>from<span class="w"> </span>inventory<span class="w"> </span>
<span class="w"> </span><span class="m">7</span>:<span class="w"> </span>flee!<span class="w"> </span>
<span class="w"> </span><span class="m">8</span>:<span class="w"> </span>hold,<span class="w"> </span>doing<span class="w"> </span>nothing<span class="w"> </span>
&gt;<span class="w"> </span><span class="m">4</span>
&gt;<span class="w"> </span><span class="m">4</span><span class="w"> </span>
_______________________________________________________________________________
Select<span class="w"> </span>the<span class="w"> </span>item
_______________________________________________________________________________
<span class="w"> </span><span class="m">1</span>:<span class="w"> </span>Potion<span class="w"> </span>of<span class="w"> </span>Strength
<span class="w"> </span><span class="m">2</span>.<span class="w"> </span>Potion<span class="w"> </span>of<span class="w"> </span>Dexterity
<span class="w"> </span><span class="m">2</span>.<span class="w"> </span>Potion<span class="w"> </span>of<span class="w"> </span>Dexterity<span class="w"> </span>
<span class="w"> </span><span class="m">3</span>.<span class="w"> </span>Green<span class="w"> </span>Apple
<span class="w"> </span><span class="m">4</span>.<span class="w"> </span>Throwing<span class="w"> </span>Daggers
<span class="w"> </span>back
<span class="w"> </span>abort
<span class="w"> </span><span class="m">4</span>.<span class="w"> </span>Throwing<span class="w"> </span>Daggers<span class="w"> </span>
<span class="w"> </span>back<span class="w"> </span>
<span class="w"> </span>abort<span class="w"> </span>
&gt;<span class="w"> </span><span class="m">1</span>
&gt;<span class="w"> </span><span class="m">1</span><span class="w"> </span>
_______________________________________________________________________________
Choose<span class="w"> </span>an<span class="w"> </span>ally<span class="w"> </span>to<span class="w"> </span>target.
_______________________________________________________________________________
<span class="w"> </span><span class="m">1</span>:<span class="w"> </span>Yourself
<span class="w"> </span>back
<span class="w"> </span>abort
<span class="w"> </span>back<span class="w"> </span>
<span class="w"> </span>abort<span class="w"> </span>
&gt;<span class="w"> </span><span class="m">1</span>
_______________________________________________________________________________
<span class="w"> </span>You<span class="w"> </span><span class="o">(</span>Perfect<span class="o">)</span><span class="w"> </span>vs<span class="w"> </span>Troll<span class="w"> </span><span class="o">(</span>Perfect<span class="o">)</span>
<span class="w"> </span>You<span class="w"> </span><span class="o">(</span>Perfect<span class="o">)</span><span class="w"> </span>vs<span class="w"> </span>Troll<span class="w"> </span><span class="o">(</span>Perfect<span class="o">)</span><span class="w"> </span>
<span class="w"> </span>Your<span class="w"> </span>queued<span class="w"> </span>action:<span class="w"> </span><span class="o">[</span>use<span class="o">]</span><span class="w"> </span><span class="o">(</span>6s<span class="w"> </span><span class="k">until</span><span class="w"> </span>next<span class="w"> </span>round,
<span class="w"> </span>or<span class="w"> </span><span class="k">until</span><span class="w"> </span>all<span class="w"> </span>combatants<span class="w"> </span>have<span class="w"> </span>chosen<span class="w"> </span>their<span class="w"> </span>next<span class="w"> </span>action<span class="o">)</span>.
_______________________________________________________________________________
<span class="w"> </span><span class="m">1</span>:<span class="w"> </span>attack<span class="w"> </span>an<span class="w"> </span>enemy
<span class="w"> </span><span class="m">2</span>:<span class="w"> </span>Stunt<span class="w"> </span>-<span class="w"> </span>gain<span class="w"> </span>a<span class="w"> </span>later<span class="w"> </span>advantage<span class="w"> </span>against<span class="w"> </span>a<span class="w"> </span>target
<span class="w"> </span><span class="m">3</span>:<span class="w"> </span>Stunt<span class="w"> </span>-<span class="w"> </span>give<span class="w"> </span>an<span class="w"> </span>enemy<span class="w"> </span>disadvantage<span class="w"> </span>against<span class="w"> </span>yourself<span class="w"> </span>or<span class="w"> </span>an<span class="w"> </span>ally
<span class="w"> </span><span class="m">4</span>:<span class="w"> </span>Use<span class="w"> </span>an<span class="w"> </span>item<span class="w"> </span>on<span class="w"> </span>yourself<span class="w"> </span>or<span class="w"> </span>an<span class="w"> </span>ally
<span class="w"> </span><span class="m">5</span>:<span class="w"> </span>Use<span class="w"> </span>an<span class="w"> </span>item<span class="w"> </span>on<span class="w"> </span>an<span class="w"> </span>enemy
<span class="w"> </span><span class="m">6</span>:<span class="w"> </span>Wield/swap<span class="w"> </span>with<span class="w"> </span>an<span class="w"> </span>item<span class="w"> </span>from<span class="w"> </span>inventory
<span class="w"> </span><span class="m">7</span>:<span class="w"> </span>flee!
<span class="w"> </span><span class="m">8</span>:<span class="w"> </span>hold,<span class="w"> </span>doing<span class="w"> </span>nothing
<span class="w"> </span><span class="m">1</span>:<span class="w"> </span>attack<span class="w"> </span>an<span class="w"> </span>enemy<span class="w"> </span>
<span class="w"> </span><span class="m">2</span>:<span class="w"> </span>Stunt<span class="w"> </span>-<span class="w"> </span>gain<span class="w"> </span>a<span class="w"> </span>later<span class="w"> </span>advantage<span class="w"> </span>against<span class="w"> </span>a<span class="w"> </span>target<span class="w"> </span>
<span class="w"> </span><span class="m">3</span>:<span class="w"> </span>Stunt<span class="w"> </span>-<span class="w"> </span>give<span class="w"> </span>an<span class="w"> </span>enemy<span class="w"> </span>disadvantage<span class="w"> </span>against<span class="w"> </span>yourself<span class="w"> </span>or<span class="w"> </span>an<span class="w"> </span>ally<span class="w"> </span>
<span class="w"> </span><span class="m">4</span>:<span class="w"> </span>Use<span class="w"> </span>an<span class="w"> </span>item<span class="w"> </span>on<span class="w"> </span>yourself<span class="w"> </span>or<span class="w"> </span>an<span class="w"> </span>ally<span class="w"> </span>
<span class="w"> </span><span class="m">5</span>:<span class="w"> </span>Use<span class="w"> </span>an<span class="w"> </span>item<span class="w"> </span>on<span class="w"> </span>an<span class="w"> </span>enemy<span class="w"> </span>
<span class="w"> </span><span class="m">6</span>:<span class="w"> </span>Wield/swap<span class="w"> </span>with<span class="w"> </span>an<span class="w"> </span>item<span class="w"> </span>from<span class="w"> </span>inventory<span class="w"> </span>
<span class="w"> </span><span class="m">7</span>:<span class="w"> </span>flee!<span class="w"> </span>
<span class="w"> </span><span class="m">8</span>:<span class="w"> </span>hold,<span class="w"> </span>doing<span class="w"> </span>nothing<span class="w"> </span>
Troll<span class="w"> </span>attacks<span class="w"> </span>You<span class="w"> </span>with<span class="w"> </span>Claws:<span class="w"> </span>Roll<span class="w"> </span>vs<span class="w"> </span>armor<span class="w"> </span><span class="o">(</span><span class="m">12</span><span class="o">)</span>:
<span class="w"> </span>rolled<span class="w"> </span><span class="m">4</span><span class="w"> </span>on<span class="w"> </span>d20<span class="w"> </span>+<span class="w"> </span>strength<span class="o">(</span>+3<span class="o">)</span><span class="w"> </span>vs<span class="w"> </span><span class="m">12</span><span class="w"> </span>-&gt;<span class="w"> </span>Fail
<span class="w"> </span>Troll<span class="w"> </span>missed<span class="w"> </span>you.
You<span class="w"> </span>use<span class="w"> </span>Potion<span class="w"> </span>of<span class="w"> </span>Strength.
<span class="w"> </span>Renewed<span class="w"> </span>strength<span class="w"> </span>coarses<span class="w"> </span>through<span class="w"> </span>your<span class="w"> </span>body!
<span class="w"> </span>rolled<span class="w"> </span><span class="m">4</span><span class="w"> </span>on<span class="w"> </span>d20<span class="w"> </span>+<span class="w"> </span>strength<span class="o">(</span>+3<span class="o">)</span><span class="w"> </span>vs<span class="w"> </span><span class="m">12</span><span class="w"> </span>-&gt;<span class="w"> </span>Fail<span class="w"> </span>
<span class="w"> </span>Troll<span class="w"> </span>missed<span class="w"> </span>you.<span class="w"> </span>
<span class="w"> </span>
You<span class="w"> </span>use<span class="w"> </span>Potion<span class="w"> </span>of<span class="w"> </span>Strength.<span class="w"> </span>
<span class="w"> </span>Renewed<span class="w"> </span>strength<span class="w"> </span>coarses<span class="w"> </span>through<span class="w"> </span>your<span class="w"> </span>body!<span class="w"> </span>
<span class="w"> </span>Potion<span class="w"> </span>of<span class="w"> </span>Strength<span class="w"> </span>was<span class="w"> </span>used<span class="w"> </span>up.
</pre></div>
</div>
@ -236,7 +226,7 @@ You<span class="w"> </span>use<span class="w"> </span>Potion<span class="w"> </s
<blockquote>
<div><p>Create a new module <code class="docutils literal notranslate"><span class="pre">evadventure/combat_turnbased.py</span></code>.</p>
</div></blockquote>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="kn">from</span> <span class="nn">.combat_base</span> <span class="kn">import</span> <span class="p">(</span>
<span class="n">CombatActionAttack</span><span class="p">,</span>
@ -263,13 +253,13 @@ You<span class="w"> </span>use<span class="w"> </span>Potion<span class="w"> </s
<span class="c1"># fallback action if not selecting anything</span>
<span class="n">fallback_action_dict</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">({</span><span class="s2">&quot;key&quot;</span><span class="p">:</span> <span class="s2">&quot;hold&quot;</span><span class="p">},</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="c1"># track which turn we are on</span>
<span class="c1"># track which turn we are on </span>
<span class="n">turn</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="c1"># who is involved in combat, and their queued action</span>
<span class="c1"># as {combatant: actiondict, ...}</span>
<span class="n">combatants</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="nb">dict</span><span class="p">)</span>
<span class="c1"># who has advantage against whom. This is a structure</span>
<span class="c1"># who has advantage against whom. This is a structure </span>
<span class="c1"># like {&quot;combatant&quot;: {enemy1: True, enemy2: True}}</span>
<span class="n">advantage_matrix</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="n">defaultdict</span><span class="p">(</span><span class="nb">dict</span><span class="p">))</span>
<span class="c1"># same for disadvantages</span>
@ -291,17 +281,17 @@ You<span class="w"> </span>use<span class="w"> </span>Potion<span class="w"> </s
<section id="getting-the-sides-of-combat">
<h3><span class="section-number">11.2.1. </span>Getting the sides of combat<a class="headerlink" href="#getting-the-sides-of-combat" title="Permalink to this headline"></a></h3>
<p>The two sides are different depending on if we are in an <a class="reference internal" href="Beginner-Tutorial-Rooms.html"><span class="doc std std-doc">PvP room</span></a> or not: In a PvP room everyone else is your enemy. Otherwise only NPCs in combat is your enemy (you are assumed to be teaming up with your fellow players).</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">class</span> <span class="nc">EvadventureTurnbasedCombatHandler</span><span class="p">(</span><span class="n">EvAdventureCombatBaseHandler</span><span class="p">):</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">get_sides</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">combatant</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Get a listing of the two &#39;sides&#39; of this combat,</span>
<span class="sd"> Get a listing of the two &#39;sides&#39; of this combat, </span>
<span class="sd"> m the perspective of the provided combatant.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">obj</span><span class="o">.</span><span class="n">allow_pvp</span><span class="p">:</span>
@ -314,11 +304,11 @@ You<span class="w"> </span>use<span class="w"> </span>Potion<span class="w"> </s
<span class="n">npcs</span> <span class="o">=</span> <span class="p">[</span><span class="n">comb</span> <span class="k">for</span> <span class="n">comb</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">combatants</span> <span class="k">if</span> <span class="n">comb</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">pcs</span><span class="p">]</span>
<span class="k">if</span> <span class="n">combatant</span> <span class="ow">in</span> <span class="n">pcs</span><span class="p">:</span>
<span class="c1"># combatant is a PC, so NPCs are all enemies</span>
<span class="n">allies</span> <span class="o">=</span> <span class="n">pcs</span>
<span class="n">allies</span> <span class="o">=</span> <span class="p">[</span><span class="n">comb</span> <span class="k">for</span> <span class="n">comb</span> <span class="ow">in</span> <span class="n">pcs</span> <span class="k">if</span> <span class="n">comb</span> <span class="o">!=</span> <span class="n">combatant</span><span class="p">]</span>
<span class="n">enemies</span> <span class="o">=</span> <span class="n">npcs</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># combatant is an NPC, so PCs are all enemies</span>
<span class="n">allies</span> <span class="o">=</span> <span class="n">npcs</span>
<span class="n">allies</span> <span class="o">=</span> <span class="p">[</span><span class="n">comb</span> <span class="k">for</span> <span class="n">comb</span> <span class="ow">in</span> <span class="n">npcs</span> <span class="k">if</span> <span class="n">comb</span> <span class="o">!=</span> <span class="n">combatant</span><span class="p">]</span>
<span class="n">enemies</span> <span class="o">=</span> <span class="n">pcs</span>
<span class="k">return</span> <span class="n">allies</span><span class="p">,</span> <span class="n">enemies</span>
</pre></div>
@ -328,13 +318,13 @@ You<span class="w"> </span>use<span class="w"> </span>Potion<span class="w"> </s
</section>
<section id="tracking-advantage-disadvantage">
<h3><span class="section-number">11.2.2. </span>Tracking Advantage/Disadvantage<a class="headerlink" href="#tracking-advantage-disadvantage" title="Permalink to this headline"></a></h3>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">class</span> <span class="nc">EvadventureTurnbasedCombatHandler</span><span class="p">(</span><span class="n">EvAdventureCombatBaseHandler</span><span class="p">):</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">give_advantage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">combatant</span><span class="p">,</span> <span class="n">target</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">advantage_matrix</span><span class="p">[</span><span class="n">combatant</span><span class="p">][</span><span class="n">target</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
@ -344,7 +334,7 @@ You<span class="w"> </span>use<span class="w"> </span>Potion<span class="w"> </s
<span class="k">def</span> <span class="nf">has_advantage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">combatant</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">return</span> <span class="p">(</span>
<span class="n">target</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">fleeing_combatants</span>
<span class="n">target</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">fleeing_combatants</span>
<span class="ow">or</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">advantage_matrix</span><span class="p">[</span><span class="n">combatant</span><span class="p">]</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="kc">False</span><span class="p">))</span>
<span class="p">)</span>
<span class="k">def</span> <span class="nf">has_disadvantage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">combatant</span><span class="p">,</span> <span class="n">target</span><span class="p">):</span>
@ -363,13 +353,13 @@ You<span class="w"> </span>use<span class="w"> </span>Potion<span class="w"> </s
<h3><span class="section-number">11.2.3. </span>Adding and removing combatants<a class="headerlink" href="#adding-and-removing-combatants" title="Permalink to this headline"></a></h3>
<p>Since the combat handler is shared we must be able to add- and remove combatants easily.
This is new compared to the base handler.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">class</span> <span class="nc">EvadventureTurnbasedCombatHandler</span><span class="p">(</span><span class="n">EvAdventureCombatBaseHandler</span><span class="p">):</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">add_combatant</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">combatant</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
@ -386,7 +376,7 @@ This is new compared to the base handler.</p>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">combatants</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">combatant</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="c1"># clean up menu if it exists</span>
<span class="c1"># TODO!</span>
<span class="c1"># TODO! </span>
</pre></div>
</div>
<p>We simply add the the combatant with the fallback action-dict to start with. We return a <code class="docutils literal notranslate"><span class="pre">bool</span></code> from <code class="docutils literal notranslate"><span class="pre">add_combatant</span></code> so that the calling function will know if they were actually added anew or not (we may want to do some extra setup if they are new).</p>
@ -395,24 +385,24 @@ This is new compared to the base handler.</p>
<section id="flee-action">
<h3><span class="section-number">11.2.4. </span>Flee Action<a class="headerlink" href="#flee-action" title="Permalink to this headline"></a></h3>
<p>Since you cant just move away from the room to flee turnbased combat, we need to add a new <code class="docutils literal notranslate"><span class="pre">CombatAction</span></code> subclass like the ones we created in the <a class="reference internal" href="Beginner-Tutorial-Combat-Base.html#actions"><span class="std std-doc">base combat lesson</span></a>.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="kn">from</span> <span class="nn">.combat_base</span> <span class="kn">import</span> <span class="n">CombatAction</span>
<span class="kn">from</span> <span class="nn">.combat_base</span> <span class="kn">import</span> <span class="n">CombatAction</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">class</span> <span class="nc">CombatActionFlee</span><span class="p">(</span><span class="n">CombatAction</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Start (or continue) fleeing/disengaging from combat.</span>
<span class="sd"> action_dict = {</span>
<span class="sd"> </span>
<span class="sd"> action_dict = { </span>
<span class="sd"> &quot;key&quot;: &quot;flee&quot;,</span>
<span class="sd"> }</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">combathandler</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">combathandler</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">combatant</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">combathandler</span><span class="o">.</span><span class="n">fleeing_combatants</span><span class="p">:</span>
<span class="c1"># we record the turn on which we started fleeing</span>
<span class="n">combathandler</span><span class="o">.</span><span class="n">fleeing_combatants</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">combatant</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">combathandler</span><span class="o">.</span><span class="n">turn</span>
@ -438,10 +428,10 @@ This is new compared to the base handler.</p>
<span class="s2">&quot;stunt&quot;</span><span class="p">:</span> <span class="n">CombatActionStunt</span><span class="p">,</span>
<span class="s2">&quot;use&quot;</span><span class="p">:</span> <span class="n">CombatActionUseItem</span><span class="p">,</span>
<span class="s2">&quot;wield&quot;</span><span class="p">:</span> <span class="n">CombatActionWield</span><span class="p">,</span>
<span class="s2">&quot;flee&quot;</span><span class="p">:</span> <span class="n">CombatActionFlee</span> <span class="c1"># &lt; ---- added!</span>
<span class="s2">&quot;flee&quot;</span><span class="p">:</span> <span class="n">CombatActionFlee</span> <span class="c1"># &lt; ---- added! </span>
<span class="p">}</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
</pre></div>
</div>
<p>We create the action to make use of the <code class="docutils literal notranslate"><span class="pre">fleeing_combatants</span></code> dict we set up in the combat handler. This dict stores the fleeing combatant along with the <code class="docutils literal notranslate"><span class="pre">turn</span></code> its fleeing started. If performing the <code class="docutils literal notranslate"><span class="pre">flee</span></code> action multiple times, we will just display how many turns are remaining.</p>
@ -449,13 +439,13 @@ This is new compared to the base handler.</p>
</section>
<section id="queue-action">
<h3><span class="section-number">11.2.5. </span>Queue action<a class="headerlink" href="#queue-action" title="Permalink to this headline"></a></h3>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">class</span> <span class="nc">EvadventureTurnbasedCombatHandler</span><span class="p">(</span><span class="n">EvAdventureCombatBaseHandler</span><span class="p">):</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">queue_action</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">combatant</span><span class="p">,</span> <span class="n">action_dict</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">combatants</span><span class="p">[</span><span class="n">combatant</span><span class="p">]</span> <span class="o">=</span> <span class="n">action_dict</span>
@ -525,15 +515,15 @@ This is new compared to the base handler.</p>
<span class="normal">49</span>
<span class="normal">50</span>
<span class="normal">51</span>
<span class="normal">52</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<span class="normal">52</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">class</span> <span class="nc">EvadventureTurnbasedCombatHandler</span><span class="p">(</span><span class="n">EvAdventureCombatBaseHandler</span><span class="p">):</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">execute_next_action</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">combatant</span><span class="p">):</span>
<span class="c1"># this gets the next dict and rotates the queue</span>
@ -545,11 +535,11 @@ This is new compared to the base handler.</p>
</span>
<span class="n">action</span><span class="o">.</span><span class="n">execute</span><span class="p">()</span>
<span class="n">action</span><span class="o">.</span><span class="n">post_execute</span><span class="p">()</span>
<span class="hll"> <span class="k">if</span> <span class="n">action_dict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;repeat&quot;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
</span> <span class="c1"># queue the action again *without updating the</span>
</span> <span class="c1"># queue the action again *without updating the </span>
<span class="c1"># *.ndb.did_action list* (otherwise</span>
<span class="c1"># we&#39;d always auto-end the turn if everyone used</span>
<span class="c1"># we&#39;d always auto-end the turn if everyone used </span>
<span class="c1"># repeating actions and there&#39;d be</span>
<span class="c1"># no time to change it before the next round)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">combatants</span><span class="p">[</span><span class="n">combatant</span><span class="p">]</span> <span class="o">=</span> <span class="n">action_dict</span>
@ -560,8 +550,8 @@ This is new compared to the base handler.</p>
<span class="k">def</span> <span class="nf">at_repeat</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> This method is called every time Script repeats</span>
<span class="sd"> (every `interval` seconds). Performs a full turn of</span>
<span class="sd"> This method is called every time Script repeats </span>
<span class="sd"> (every `interval` seconds). Performs a full turn of </span>
<span class="sd"> combat, performing everyone&#39;s actions in random order.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">turn</span> <span class="o">+=</span> <span class="mi">1</span>
@ -665,22 +655,22 @@ This is new compared to the base handler.</p>
<span class="normal">68</span>
<span class="normal">69</span>
<span class="normal">70</span>
<span class="normal">71</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<span class="normal">71</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">from</span> <span class="nn">evennia.utils.utils</span> <span class="kn">import</span> <span class="n">list_to_string</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">class</span> <span class="nc">EvadventureTurnbasedCombatHandler</span><span class="p">(</span><span class="n">EvAdventureCombatBaseHandler</span><span class="p">):</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">stop_combat</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Stop the combat immediately.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="sd"> </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">for</span> <span class="n">combatant</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">combatants</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">remove_combatant</span><span class="p">(</span><span class="n">combatant</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
@ -692,7 +682,7 @@ This is new compared to the base handler.</p>
<span class="c1"># check if anyone is defeated</span>
<span class="k">for</span> <span class="n">combatant</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">combatants</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
<span class="k">if</span> <span class="n">combatant</span><span class="o">.</span><span class="n">hp</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
<span class="hll"> <span class="c1"># PCs roll on the death table here, NPCs die.</span>
<span class="hll"> <span class="c1"># PCs roll on the death table here, NPCs die. </span>
</span> <span class="c1"># Even if PCs survive, they</span>
<span class="c1"># are still out of the fight.</span>
<span class="n">combatant</span><span class="o">.</span><span class="n">at_defeat</span><span class="p">()</span>
@ -701,7 +691,7 @@ This is new compared to the base handler.</p>
<span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">&quot;|r$You() $conj(fall) to the ground, defeated.|n&quot;</span><span class="p">,</span> <span class="n">combatant</span><span class="o">=</span><span class="n">combatant</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">combatants</span><span class="p">[</span><span class="n">combatant</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fallback_action_dict</span>
<span class="c1"># check if anyone managed to flee</span>
<span class="n">flee_timeout</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">flee_timeout</span>
<span class="k">for</span> <span class="n">combatant</span><span class="p">,</span> <span class="n">started_fleeing</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">fleeing_combatants</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
@ -709,7 +699,7 @@ This is new compared to the base handler.</p>
</span> <span class="c1"># if they are still alive/fleeing and have been fleeing long enough, escape</span>
<span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">&quot;|y$You() successfully $conj(flee) from combat.|n&quot;</span><span class="p">,</span> <span class="n">combatant</span><span class="o">=</span><span class="n">combatant</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">remove_combatant</span><span class="p">(</span><span class="n">combatant</span><span class="p">)</span>
<span class="c1"># check if one side won the battle</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">combatants</span><span class="p">:</span>
<span class="c1"># noone left in combat - maybe they killed each other or all fled</span>
@ -752,20 +742,20 @@ This is new compared to the base handler.</p>
<p>Since we are using the timer-component of the <a class="reference internal" href="../../../Components/Scripts.html"><span class="doc std std-doc">Script</span></a> to tick our combat, we also need a helper method to start that.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia.utils.utils</span> <span class="kn">import</span> <span class="n">list_to_string</span>
<span class="c1"># in evadventure/combat_turnbased.py</span>
<span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">class</span> <span class="nc">EvadventureTurnbasedCombatHandler</span><span class="p">(</span><span class="n">EvAdventureCombatBaseHandler</span><span class="p">):</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">start_combat</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; </span>
<span class="sd"> This actually starts the combat. It&#39;s safe to run this multiple times</span>
<span class="sd"> since it will only start combat if it isn&#39;t already running.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="sd"> </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_active</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">start</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
@ -778,11 +768,11 @@ This is new compared to the base handler.</p>
<h2><span class="section-number">11.3. </span>Using EvMenu for the combat menu<a class="headerlink" href="#using-evmenu-for-the-combat-menu" title="Permalink to this headline"></a></h2>
<p>The <em>EvMenu</em> used to create in-game menues in Evennia. We used a simple EvMenu already in the <a class="reference internal" href="Beginner-Tutorial-Chargen.html"><span class="doc std std-doc">Character Generation Lesson</span></a>. This time well need to be a bit more advanced. While <a class="reference internal" href="../../../Components/EvMenu.html"><span class="doc std std-doc">The EvMenu documentation</span></a> describe its functionality in more detail, we will give a quick overview of how it works here.</p>
<p>An EvMenu is made up of <em>nodes</em>, which are regular functions on this form (somewhat simplified here, there are more options):</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">node_somenodename</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">node_somenodename</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">text</span> <span class="o">=</span> <span class="s2">&quot;some text to show in the node&quot;</span>
<span class="n">options</span> <span class="o">=</span> <span class="p">[</span>
<span class="p">{</span>
<span class="p">{</span>
<span class="s2">&quot;key&quot;</span><span class="p">:</span> <span class="s2">&quot;Option 1&quot;</span><span class="p">,</span> <span class="c1"># skip this to get a number</span>
<span class="s2">&quot;desc&quot;</span><span class="p">:</span> <span class="s2">&quot;Describing what happens when choosing this option.&quot;</span>
<span class="s2">&quot;goto&quot;</span><span class="p">:</span> <span class="s2">&quot;name of the node to go to&quot;</span> <span class="c1"># OR (callable, {kwargs}}) returning said name</span>
@ -798,7 +788,7 @@ This is new compared to the base handler.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># example of a EvMenu node index</span>
<span class="p">{</span>
<span class="s2">&quot;start&quot;</span><span class="p">:</span> <span class="n">node_combat_main</span><span class="p">,</span>
<span class="s2">&quot;node1&quot;</span><span class="p">:</span> <span class="n">node_func1</span><span class="p">,</span>
<span class="s2">&quot;node1&quot;</span><span class="p">:</span> <span class="n">node_func1</span><span class="p">,</span>
<span class="s2">&quot;node2&quot;</span><span class="p">:</span> <span class="n">node_func2</span><span class="p">,</span>
<span class="s2">&quot;some name&quot;</span><span class="p">:</span> <span class="n">node_somenodename</span><span class="p">,</span>
<span class="s2">&quot;end&quot;</span><span class="p">:</span> <span class="n">node_abort_menu</span><span class="p">,</span>
@ -808,9 +798,9 @@ This is new compared to the base handler.</p>
<p>Each <code class="docutils literal notranslate"><span class="pre">option</span></code> dict has a key <code class="docutils literal notranslate"><span class="pre">&quot;goto&quot;</span></code> that determines which node the player should jump to if they choose that option. Inside the menu, each node needs to be referenced with these names (like <code class="docutils literal notranslate"><span class="pre">&quot;start&quot;</span></code>, <code class="docutils literal notranslate"><span class="pre">&quot;node1&quot;</span></code> etc).</p>
<p>The <code class="docutils literal notranslate"><span class="pre">&quot;goto&quot;</span></code> value of each option can either specify the name directly (like <code class="docutils literal notranslate"><span class="pre">&quot;node1&quot;</span></code>) <em>or</em> it can be given as a tuple <code class="docutils literal notranslate"><span class="pre">(callable,</span> <span class="pre">{keywords})</span></code>. This <code class="docutils literal notranslate"><span class="pre">callable</span></code> is <em>called</em> and is expected to in turn return the next node-name to use (like <code class="docutils literal notranslate"><span class="pre">&quot;node1&quot;</span></code>).</p>
<p>The <code class="docutils literal notranslate"><span class="pre">callable</span></code> (often called a “goto callable”) looks very similar to a node function:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">_goto_when_choosing_option1</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="c1"># do whatever is needed to determine the next node</span>
<span class="k">return</span> <span class="n">nodename</span> <span class="c1"># also nodename, dict works</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">_goto_when_choosing_option1</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="c1"># do whatever is needed to determine the next node </span>
<span class="k">return</span> <span class="n">nodename</span> <span class="c1"># also nodename, dict works </span>
</pre></div>
</div>
<aside class="sidebar">
@ -821,11 +811,11 @@ This is new compared to the base handler.</p>
<p>The goto-callable must return the name of the next node. Optionally, you can return both <code class="docutils literal notranslate"><span class="pre">nodename,</span> <span class="pre">{kwargs}</span></code>. If you do the next node will get those kwargs as ingoing <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code>. This way you can pass information from one node to the next. A special feature is that if <code class="docutils literal notranslate"><span class="pre">nodename</span></code> is returned as <code class="docutils literal notranslate"><span class="pre">None</span></code>, then the <em>current</em> node will be <em>rerun</em> again.</p>
<p>Heres a (somewhat contrived) example of how the goto-callable and node-function hang together:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># goto-callable</span>
<span class="k">def</span> <span class="nf">_my_goto_callable</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">_my_goto_callable</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">info_number</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;info_number&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">info_number</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="n">info_number</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;node1&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;node2&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;info_number&quot;</span><span class="p">:</span> <span class="n">info_number</span><span class="p">}</span> <span class="c1"># will be **kwargs when &quot;node2&quot; runs next</span>
@ -838,7 +828,7 @@ This is new compared to the base handler.</p>
<span class="s2">&quot;goto&quot;</span><span class="p">:</span> <span class="p">(</span><span class="n">_my_goto_callable</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;info_number&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">})</span>
<span class="p">},</span>
<span class="p">{</span>
<span class="s2">&quot;desc&quot;</span><span class="p">:</span> <span class="s2">&quot;Option two&quot;</span><span class="p">,</span>
<span class="s2">&quot;desc&quot;</span><span class="p">:</span> <span class="s2">&quot;Option two&quot;</span><span class="p">,</span>
<span class="s2">&quot;goto&quot;</span><span class="p">:</span> <span class="p">(</span><span class="n">_my_goto_callable</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;info_number&quot;</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">})</span>
<span class="p">},</span>
<span class="p">]</span>
@ -916,7 +906,7 @@ This is new compared to the base handler.</p>
<section id="the-node-index">
<h3><span class="section-number">11.4.1. </span>The node index<a class="headerlink" href="#the-node-index" title="Permalink to this headline"></a></h3>
<p>These are the nodes we need for our menu:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># not coded anywhere yet, just noting for reference</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># not coded anywhere yet, just noting for reference </span>
<span class="n">node_index</span> <span class="o">=</span> <span class="p">{</span>
<span class="c1"># node names # callables # (future callables)</span>
<span class="s2">&quot;node_choose_enemy_target&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="c1"># node_choose_enemy_target,</span>
@ -934,11 +924,11 @@ This is new compared to the base handler.</p>
</section>
<section id="getting-or-setting-the-combathandler">
<h3><span class="section-number">11.4.2. </span>Getting or setting the combathandler<a class="headerlink" href="#getting-or-setting-the-combathandler" title="Permalink to this headline"></a></h3>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">EvMenu</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">_get_combathandler</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">turn_timeout</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">flee_time</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">combathandler_key</span><span class="o">=</span><span class="s2">&quot;combathandler&quot;</span><span class="p">):</span>
<span class="k">return</span> <span class="n">EvAdventureTurnbasedCombatHandler</span><span class="o">.</span><span class="n">get_or_create_combathandler</span><span class="p">(</span>
@ -954,9 +944,9 @@ This is new compared to the base handler.</p>
<section id="queue-an-action">
<h3><span class="section-number">11.4.3. </span>Queue an action<a class="headerlink" href="#queue-an-action" title="Permalink to this headline"></a></h3>
<p>This is our first “goto function”. This will be called to actually queue our finished action-dict with the combat handler. After doing that, it should return us to the base <code class="docutils literal notranslate"><span class="pre">node_combat</span></code>.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">_queue_action</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">action_dict</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;action_dict&quot;</span><span class="p">]</span>
@ -970,11 +960,11 @@ This is new compared to the base handler.</p>
<section id="rerun-a-node">
<h3><span class="section-number">11.4.4. </span>Rerun a node<a class="headerlink" href="#rerun-a-node" title="Permalink to this headline"></a></h3>
<p>A special feature of goto callables is the ability to rerun the same node by returning <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">_rerun_current_node</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">_rerun_current_node</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">return</span> <span class="kc">None</span><span class="p">,</span> <span class="n">kwargs</span>
</pre></div>
</div>
@ -985,14 +975,14 @@ This is new compared to the base handler.</p>
<p>Our particualr menu is very symmetric - you select an option and then you will just select a series of option before you come back. So we will make another goto-function to help us easily do this. To understand, lets first show how we plan to use this:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in the base combat-node function (just shown as an example)</span>
<span class="n">options</span> <span class="o">=</span> <span class="p">[</span>
<span class="n">options</span> <span class="o">=</span> <span class="p">[</span>
<span class="c1"># ...</span>
<span class="s2">&quot;desc&quot;</span><span class="p">:</span> <span class="s2">&quot;use an item on an enemy&quot;</span><span class="p">,</span>
<span class="s2">&quot;desc&quot;</span><span class="p">:</span> <span class="s2">&quot;use an item on an enemy&quot;</span><span class="p">,</span>
<span class="s2">&quot;goto&quot;</span><span class="p">:</span> <span class="p">(</span>
<span class="n">_step_wizard</span><span class="p">,</span>
<span class="n">_step_wizard</span><span class="p">,</span>
<span class="p">{</span>
<span class="s2">&quot;steps&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;node_choose_use_item&quot;</span><span class="p">,</span> <span class="s2">&quot;node_choose_enemy_target&quot;</span><span class="p">],</span>
<span class="s2">&quot;action_dict&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;key&quot;</span><span class="p">:</span> <span class="s2">&quot;use&quot;</span><span class="p">,</span> <span class="s2">&quot;item&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s2">&quot;target&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">},</span>
<span class="s2">&quot;action_dict&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;key&quot;</span><span class="p">:</span> <span class="s2">&quot;use&quot;</span><span class="p">,</span> <span class="s2">&quot;item&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s2">&quot;target&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">},</span>
<span class="p">}</span>
<span class="p">)</span>
<span class="p">]</span>
@ -1003,46 +993,46 @@ This is new compared to the base handler.</p>
<p>Furthermore, we want the ability to go “back” to the previous node like this:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in some other node (shown only as an example)</span>
<span class="k">def</span> <span class="nf">some_node</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">some_node</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="c1"># ...</span>
<span class="n">options</span> <span class="o">=</span> <span class="p">[</span>
<span class="c1"># ...</span>
<span class="p">{</span>
<span class="c1"># ... </span>
<span class="n">options</span> <span class="o">=</span> <span class="p">[</span>
<span class="c1"># ... </span>
<span class="p">{</span>
<span class="s2">&quot;key&quot;</span><span class="p">:</span> <span class="s2">&quot;back&quot;</span><span class="p">,</span>
<span class="s2">&quot;goto&quot;</span><span class="p">:</span> <span class="p">(</span> <span class="n">_step_wizard</span><span class="p">,</span> <span class="p">{</span><span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="s2">&quot;step&quot;</span><span class="p">:</span> <span class="s2">&quot;back&quot;</span><span class="p">}})</span>
<span class="p">},</span>
<span class="p">]</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
</pre></div>
</div>
<p>Note the use of <code class="docutils literal notranslate"><span class="pre">**</span></code> here. <code class="docutils literal notranslate"><span class="pre">{**dict1,</span> <span class="pre">**dict2}</span></code> is a powerful one-liner syntax to combine two dicts into one. This preserves (and passes on) the incoming <code class="docutils literal notranslate"><span class="pre">kwargs</span></code> and just adds a new key “step” to it. The end effect is similar to if we had done <code class="docutils literal notranslate"><span class="pre">kwargs[&quot;step&quot;]</span> <span class="pre">=</span> <span class="pre">&quot;back&quot;</span></code> on a separate line (except we end up with a <em>new</em> <code class="docutils literal notranslate"><span class="pre">dict</span></code> when using the <code class="docutils literal notranslate"><span class="pre">**</span></code>-approach).</p>
<p>So lets implement a <code class="docutils literal notranslate"><span class="pre">_step_wizard</span></code> goto-function to handle this!</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
<span class="k">def</span> <span class="nf">_step_wizard</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">_step_wizard</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="c1"># get the steps and count them</span>
<span class="c1"># get the steps and count them </span>
<span class="n">steps</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;steps&quot;</span><span class="p">,</span> <span class="p">[])</span>
<span class="n">nsteps</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">steps</span><span class="p">)</span>
<span class="c1"># track which step we are on</span>
<span class="n">istep</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;istep&quot;</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="c1"># track which step we are on </span>
<span class="n">istep</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;istep&quot;</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="c1"># check if we are going back (forward is default)</span>
<span class="n">step_direction</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;step&quot;</span><span class="p">,</span> <span class="s2">&quot;forward&quot;</span><span class="p">)</span>
<span class="n">step_direction</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;step&quot;</span><span class="p">,</span> <span class="s2">&quot;forward&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">step_direction</span> <span class="o">==</span> <span class="s2">&quot;back&quot;</span><span class="p">:</span>
<span class="c1"># step back in wizard</span>
<span class="c1"># step back in wizard </span>
<span class="k">if</span> <span class="n">istep</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
<span class="c1"># back to the start</span>
<span class="c1"># back to the start </span>
<span class="k">return</span> <span class="s2">&quot;node_combat&quot;</span>
<span class="n">istep</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;istep&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">istep</span> <span class="o">-</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">steps</span><span class="p">[</span><span class="n">istep</span><span class="p">],</span> <span class="n">kwargs</span>
<span class="k">return</span> <span class="n">steps</span><span class="p">[</span><span class="n">istep</span><span class="p">],</span> <span class="n">kwargs</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># step to the next step in wizard</span>
<span class="k">if</span> <span class="n">istep</span> <span class="o">&gt;=</span> <span class="n">nsteps</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span>
@ -1058,18 +1048,18 @@ This is new compared to the base handler.</p>
<p>This depends on passing around <code class="docutils literal notranslate"><span class="pre">steps</span></code>, <code class="docutils literal notranslate"><span class="pre">step</span></code> and <code class="docutils literal notranslate"><span class="pre">istep</span></code> with the <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code>. If <code class="docutils literal notranslate"><span class="pre">step</span></code> is “back” then we will go back in the sequence of <code class="docutils literal notranslate"><span class="pre">steps</span></code> otherwise forward. We increase/decrease the <code class="docutils literal notranslate"><span class="pre">istep</span></code> key value to track just where we are.</p>
<p>If we reach the end we call our <code class="docutils literal notranslate"><span class="pre">_queue_action</span></code> helper function directly. If we back up to the beginning we return to the base node.</p>
<p>We will make one final helper function, to quickly add the <code class="docutils literal notranslate"><span class="pre">back</span></code> (and <code class="docutils literal notranslate"><span class="pre">abort</span></code>) options to the nodes that need it:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
<span class="n">_get_default_wizard_options</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">return</span> <span class="p">[</span>
<span class="p">{</span>
<span class="s2">&quot;key&quot;</span><span class="p">:</span> <span class="s2">&quot;back&quot;</span><span class="p">,</span>
<span class="s2">&quot;key&quot;</span><span class="p">:</span> <span class="s2">&quot;back&quot;</span><span class="p">,</span>
<span class="s2">&quot;goto&quot;</span><span class="p">:</span> <span class="p">(</span><span class="n">_step_wizard</span><span class="p">,</span> <span class="p">{</span><span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="s2">&quot;step&quot;</span><span class="p">:</span> <span class="s2">&quot;back&quot;</span><span class="p">}})</span>
<span class="p">},</span>
<span class="p">{</span>
<span class="s2">&quot;key&quot;</span><span class="p">:</span> <span class="s2">&quot;abort&quot;</span><span class="p">,</span>
<span class="s2">&quot;key&quot;</span><span class="p">:</span> <span class="s2">&quot;abort&quot;</span><span class="p">,</span>
<span class="s2">&quot;goto&quot;</span><span class="p">:</span> <span class="s2">&quot;node_combat&quot;</span>
<span class="p">},</span>
<span class="p">{</span>
@ -1122,7 +1112,7 @@ This is new compared to the base handler.</p>
<span class="normal">33</span>
<span class="normal">34</span>
<span class="normal">35</span>
<span class="normal">36</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<span class="normal">36</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
@ -1148,15 +1138,15 @@ This is new compared to the base handler.</p>
</span> <span class="k">return</span> <span class="n">text</span><span class="p">,</span> <span class="n">options</span>
<span class="k">def</span> <span class="nf">node_choose_enemy_recipient</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">node_choose_enemy_recipient</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="c1"># almost the same, except storing &quot;recipient&quot;</span>
<span class="k">def</span> <span class="nf">node_choose_allied_target</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">node_choose_allied_target</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="c1"># almost the same, except using allies + yourself</span>
<span class="k">def</span> <span class="nf">node_choose_allied_recipient</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">node_choose_allied_recipient</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="c1"># almost the same, except using allies + yourself and storing &quot;recipient&quot;</span>
</pre></div></td></tr></table></div>
</div>
@ -1176,12 +1166,12 @@ This is new compared to the base handler.</p>
</li>
<li><p><strong>Line 23</strong>: We extend the <code class="docutils literal notranslate"><span class="pre">options</span></code> list with the default wizard options (<code class="docutils literal notranslate"><span class="pre">back</span></code>, <code class="docutils literal notranslate"><span class="pre">abort</span></code>). Since we made a helper function for this, this is only one line.</p></li>
</ul>
<p>Creating the three other needed nodes <code class="docutils literal notranslate"><span class="pre">node_choose_enemy_recipient</span></code>, <code class="docutils literal notranslate"><span class="pre">node_choose_allied_target</span></code> and <code class="docutils literal notranslate"><span class="pre">node_choose_allied_recipient</span></code> are following the same pattern; they just use either the <code class="docutils literal notranslate"><span class="pre">allies</span></code> or <code class="docutils literal notranslate"><span class="pre">enemies</span></code> return from <code class="docutils literal notranslate"><span class="pre">combathandler.get_sides().</span> <span class="pre">It</span> <span class="pre">then</span> <span class="pre">sets</span> <span class="pre">either</span> <span class="pre">the</span> </code>target<code class="docutils literal notranslate"><span class="pre">or</span></code>recipient<code class="docutils literal notranslate"><span class="pre">field</span> <span class="pre">in</span> <span class="pre">the</span></code>action_dict`. We leave these up to the reader to implement.</p>
<p>Creating the three other needed nodes <code class="docutils literal notranslate"><span class="pre">node_choose_enemy_recipient</span></code>, <code class="docutils literal notranslate"><span class="pre">node_choose_allied_target</span></code> and <code class="docutils literal notranslate"><span class="pre">node_choose_allied_recipient</span></code> are following the same pattern; they just use either the <code class="docutils literal notranslate"><span class="pre">allies</span></code> or <code class="docutils literal notranslate"><span class="pre">enemies</span></code> return from <code class="docutils literal notranslate"><span class="pre">combathandler.get_sides()</span></code> (for the <code class="docutils literal notranslate"><span class="pre">allies</span></code>, dont forget to add <code class="docutils literal notranslate"><span class="pre">caller</span></code> so you can target yourself!). It then sets either the <code class="docutils literal notranslate"><span class="pre">target</span></code> or <code class="docutils literal notranslate"><span class="pre">recipient</span></code> field in the <code class="docutils literal notranslate"><span class="pre">action_dict</span></code>. We leave these up to the reader to implement.</p>
</section>
<section id="choose-an-ability">
<h3><span class="section-number">11.4.7. </span>Choose an Ability<a class="headerlink" href="#choose-an-ability" title="Permalink to this headline"></a></h3>
<p>For Stunts, we need to be able to select which <em>Knave</em> Ability (STR, DEX etc) you want to boost/foil.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="kn">from</span> <span class="nn">.enums</span> <span class="kn">import</span> <span class="n">Ability</span>
@ -1199,7 +1189,7 @@ This is new compared to the base handler.</p>
<span class="p">{</span>
<span class="o">**</span><span class="n">kwargs</span><span class="p">,</span>
<span class="o">**</span><span class="p">{</span>
<span class="s2">&quot;action_dict&quot;</span><span class="p">:</span> <span class="p">{</span><span class="o">**</span><span class="n">action_dict</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="s2">&quot;stunt_type&quot;</span><span class="p">:</span> <span class="n">abi</span><span class="p">,</span> <span class="s2">&quot;defense_type&quot;</span><span class="p">:</span> <span class="n">abi</span><span class="p">}},</span>
<span class="s2">&quot;action_dict&quot;</span><span class="p">:</span> <span class="p">{</span><span class="o">**</span><span class="n">action_dict</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="s2">&quot;stunt_type&quot;</span><span class="p">:</span> <span class="n">abi</span><span class="p">,</span> <span class="s2">&quot;defense_type&quot;</span><span class="p">:</span> <span class="n">abi</span><span class="p">}},</span>
<span class="p">},</span>
<span class="p">},</span>
<span class="p">),</span>
@ -1223,7 +1213,7 @@ This is new compared to the base handler.</p>
</section>
<section id="choose-an-item-to-use-or-wield">
<h3><span class="section-number">11.4.8. </span>Choose an item to use or wield<a class="headerlink" href="#choose-an-item-to-use-or-wield" title="Permalink to this headline"></a></h3>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
@ -1248,7 +1238,7 @@ This is new compared to the base handler.</p>
<span class="k">return</span> <span class="n">text</span><span class="p">,</span> <span class="n">options</span>
<span class="k">def</span> <span class="nf">node_choose_wield_item</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">node_choose_wield_item</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">raw_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="c1"># same except using caller.equipment.get_wieldable_objects_from_backpack()</span>
</pre></div>
@ -1259,7 +1249,7 @@ This is new compared to the base handler.</p>
<section id="the-main-menu-node">
<h3><span class="section-number">11.4.9. </span>The main menu node<a class="headerlink" href="#the-main-menu-node" title="Permalink to this headline"></a></h3>
<p>This ties it all together.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
@ -1362,9 +1352,9 @@ This is new compared to the base handler.</p>
<section id="attack-command">
<h2><span class="section-number">11.5. </span>Attack Command<a class="headerlink" href="#attack-command" title="Permalink to this headline"></a></h2>
<p>We will only need one single Command to run the Turnbased combat system. This is the <code class="docutils literal notranslate"><span class="pre">attack</span></code> command. Once you use it once, you will be in the menu.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span><span class="p">,</span> <span class="n">CmdSet</span><span class="p">,</span> <span class="n">EvMenu</span>
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span><span class="p">,</span> <span class="n">CmdSet</span><span class="p">,</span> <span class="n">EvMenu</span>
<span class="c1"># ...</span>
@ -1457,13 +1447,13 @@ This is new compared to the base handler.</p>
<h2><span class="section-number">11.6. </span>Making sure the menu stops<a class="headerlink" href="#making-sure-the-menu-stops" title="Permalink to this headline"></a></h2>
<p>The combat can end for a bunch of reasons. When that happens, we must make sure to clean up the menu so we go back normal operation. We will add this to the <code class="docutils literal notranslate"><span class="pre">remove_combatant</span></code> method on the combat handler (we left a TODO there before):</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span>
<span class="c1"># in evadventure/combat_turnbased.py</span>
<span class="c1"># in evadventure/combat_turnbased.py </span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">class</span> <span class="nc">EvadventureTurnbasedCombatHandler</span><span class="p">(</span><span class="n">EvAdventureCombatBaseHandler</span><span class="p">):</span>
<span class="c1"># ...</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">remove_combatant</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">combatant</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Remove a combatant from the battle.</span>
@ -1471,7 +1461,7 @@ This is new compared to the base handler.</p>
<span class="bp">self</span><span class="o">.</span><span class="n">combatants</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">combatant</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="c1"># clean up menu if it exists</span>
<span class="k">if</span> <span class="n">combatant</span><span class="o">.</span><span class="n">ndb</span><span class="o">.</span><span class="n">_evmenu</span><span class="p">:</span> <span class="c1"># &lt;--- new</span>
<span class="n">combatant</span><span class="o">.</span><span class="n">ndb</span><span class="o">.</span><span class="n">_evmenu</span><span class="o">.</span><span class="n">close_menu</span><span class="p">()</span> <span class="c1"># &#39;&#39;</span>
<span class="n">combatant</span><span class="o">.</span><span class="n">ndb</span><span class="o">.</span><span class="n">_evmenu</span><span class="o">.</span><span class="n">close_menu</span><span class="p">()</span> <span class="c1"># &#39;&#39; </span>
</pre></div>
</div>
@ -1513,7 +1503,7 @@ This is new compared to the base handler.</p>
<span class="c1">#</span>
<span class="c1"># First add mygame/server/conf/settings.py:</span>
<span class="c1">#</span>
<span class="c1"># BASE_BATCHPROCESS_PATHS += [&quot;evadventure.batchscripts&quot;]</span>
<span class="c1"># BASE_BATCH_PROCESS_PATHS += [&quot;evadventure.batchscripts&quot;]</span>
<span class="c1">#</span>
<span class="c1"># Run from in-game as `batchcode turnbased_combat_demo`</span>
<span class="c1">#</span>
@ -1572,7 +1562,7 @@ This is new compared to the base handler.</p>
<p>If editing this in an IDE, you may get errors on the <code class="docutils literal notranslate"><span class="pre">player</span> <span class="pre">=</span> <span class="pre">caller</span></code> line. This is because <code class="docutils literal notranslate"><span class="pre">caller</span></code> is not defined anywhere in this file. Instead <code class="docutils literal notranslate"><span class="pre">caller</span></code> (the one running the script) is injected by the <code class="docutils literal notranslate"><span class="pre">batchcode</span></code> runner.</p>
<p>But apart from the <code class="docutils literal notranslate"><span class="pre">#</span> <span class="pre">HEADER</span></code> and <code class="docutils literal notranslate"><span class="pre">#</span> <span class="pre">CODE</span></code> specials, this just a series of normal Evennia api calls.</p>
<p>Log into the game with a developer/superuser account and run</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; batchcmd evadventure.batchscripts.turnbased_combat_demo
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; batchcmd evadventure.batchscripts.turnbased_combat_demo
</pre></div>
</div>
<p>This should place you in the arena with the dummy (if not, check for errors in the output! Use <code class="docutils literal notranslate"><span class="pre">objects</span></code> and <code class="docutils literal notranslate"><span class="pre">delete</span></code> commands to list and delete objects if you need to start over.)</p>
@ -1607,15 +1597,12 @@ This is new compared to the base handler.</p>
<a href="Beginner-Tutorial-Combat-Twitch.html" title="10. Twitch Combat"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">11. </span>Turnbased Combat</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="9. Combat base framework" href="Beginner-Tutorial-Combat-Base.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Combat-Base.html" title="9. Combat base framework"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">10. </span>Twitch Combat</a></li>
</ul>
</div>
</div>
<div class="document">
@ -121,18 +123,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Combat-Twitch.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -288,11 +278,11 @@ The<span class="w"> </span>battle<span class="w"> </span>is<span class="w"> </sp
<span class="n">npcs</span> <span class="o">=</span> <span class="p">[</span><span class="n">comb</span> <span class="k">for</span> <span class="n">comb</span> <span class="ow">in</span> <span class="n">combatants</span> <span class="k">if</span> <span class="n">comb</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">pcs</span><span class="p">]</span>
<span class="k">if</span> <span class="n">combatant</span> <span class="ow">in</span> <span class="n">pcs</span><span class="p">:</span>
<span class="c1"># combatant is a PC, so NPCs are all enemies</span>
<span class="n">allies</span> <span class="o">=</span> <span class="n">pcs</span>
<span class="n">allies</span> <span class="o">=</span> <span class="p">[</span><span class="n">comb</span> <span class="k">for</span> <span class="n">comb</span> <span class="ow">in</span> <span class="n">pcs</span> <span class="k">if</span> <span class="n">comb</span> <span class="o">!=</span> <span class="n">combatant</span><span class="p">]</span>
<span class="n">enemies</span> <span class="o">=</span> <span class="n">npcs</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># combatant is an NPC, so PCs are all enemies</span>
<span class="n">allies</span> <span class="o">=</span> <span class="n">npcs</span>
<span class="n">allies</span> <span class="o">=</span> <span class="p">[</span><span class="n">comb</span> <span class="k">for</span> <span class="n">comb</span> <span class="ow">in</span> <span class="n">npcs</span> <span class="k">if</span> <span class="n">comb</span> <span class="o">!=</span> <span class="n">combatant</span><span class="p">]</span>
<span class="n">enemies</span> <span class="o">=</span> <span class="n">pcs</span>
<span class="k">return</span> <span class="n">allies</span><span class="p">,</span> <span class="n">enemies</span>
@ -588,7 +578,8 @@ a given combatant has advantage.</p>
<span class="normal">29</span>
<span class="normal">30</span>
<span class="normal">31</span>
<span class="normal">32</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># in evadventure/combat_twitch.py </span>
<span class="normal">32</span>
<span class="normal">33</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1"># in evadventure/combat_twitch.py </span>
<span class="k">class</span> <span class="nc">EvAdventureCombatTwitchHandler</span><span class="p">(</span><span class="n">EvAdventureCombatBaseHandler</span><span class="p">):</span>
@ -600,14 +591,15 @@ a given combatant has advantage.</p>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="hll"> <span class="n">allies</span><span class="p">,</span> <span class="n">enemies</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_sides</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">obj</span><span class="p">)</span>
</span>
</span> <span class="n">allies</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">obj</span><span class="p">)</span>
<span class="n">location</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">obj</span><span class="o">.</span><span class="n">location</span>
<span class="c1"># only keep combatants that are alive and still in the same room</span>
<span class="n">allies</span> <span class="o">=</span> <span class="p">[</span><span class="n">comb</span> <span class="k">for</span> <span class="n">comb</span> <span class="ow">in</span> <span class="n">allies</span> <span class="k">if</span> <span class="n">comb</span><span class="o">.</span><span class="n">hp</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">comb</span><span class="o">.</span><span class="n">location</span> <span class="o">==</span> <span class="n">location</span><span class="p">]</span>
<span class="hll"> <span class="n">enemies</span> <span class="o">=</span> <span class="p">[</span><span class="n">comb</span> <span class="k">for</span> <span class="n">comb</span> <span class="ow">in</span> <span class="n">enemies</span> <span class="k">if</span> <span class="n">comb</span><span class="o">.</span><span class="n">hp</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">comb</span><span class="o">.</span><span class="n">location</span> <span class="o">==</span> <span class="n">location</span><span class="p">]</span>
</span><span class="hll">
</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">allies</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">enemies</span><span class="p">:</span>
<span class="hll"> <span class="n">allies</span> <span class="o">=</span> <span class="p">[</span><span class="n">comb</span> <span class="k">for</span> <span class="n">comb</span> <span class="ow">in</span> <span class="n">allies</span> <span class="k">if</span> <span class="n">comb</span><span class="o">.</span><span class="n">hp</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">comb</span><span class="o">.</span><span class="n">location</span> <span class="o">==</span> <span class="n">location</span><span class="p">]</span>
</span><span class="hll"> <span class="n">enemies</span> <span class="o">=</span> <span class="p">[</span><span class="n">comb</span> <span class="k">for</span> <span class="n">comb</span> <span class="ow">in</span> <span class="n">enemies</span> <span class="k">if</span> <span class="n">comb</span><span class="o">.</span><span class="n">hp</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">comb</span><span class="o">.</span><span class="n">location</span> <span class="o">==</span> <span class="n">location</span><span class="p">]</span>
</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">allies</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">enemies</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">&quot;The combat is over. Noone stands.&quot;</span><span class="p">,</span> <span class="n">broadcast</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stop_combat</span><span class="p">()</span>
<span class="k">return</span>
@ -624,7 +616,7 @@ a given combatant has advantage.</p>
</div>
<p>We must make sure to check if combat is over.</p>
<ul class="simple">
<li><p><strong>Line 12</strong>: With our <code class="docutils literal notranslate"><span class="pre">.get_sides()</span></code> method we can easily get the two sides of the conflict.</p></li>
<li><p><strong>Line 12</strong>: With our <code class="docutils literal notranslate"><span class="pre">.get_sides()</span></code> method we can easily get the two sides of the conflict. Note that <code class="docutils literal notranslate"><span class="pre">combatant</span></code> is not included among the allies, so we need to add it back in on the following line.</p></li>
<li><p><strong>Lines 18, 19</strong>: We get everyone still alive <em>and still in the same room</em>. The latter condition is important in case we move away from the battle - you cant hit your enemy from another room.</p></li>
</ul>
<p>In the <code class="docutils literal notranslate"><span class="pre">stop_method</span></code> well need to do a bunch of cleanup. Well hold off on implementing this until we have the Commands written out. Read on.</p>
@ -1211,7 +1203,7 @@ You<span class="w"> </span><span class="o">(</span>Wounded<span class="o">)</spa
<section id="a-small-combat-test">
<h2><span class="section-number">10.6. </span>A small combat test<a class="headerlink" href="#a-small-combat-test" title="Permalink to this headline"></a></h2>
<aside class="sidebar">
<p>You can find an example batch-command script in <a class="reference external" href="https://github.com/evennia/evennia/blob/main/evennia/contrib/tutorials/evadventure/batchscripts/twitch_combat_demo.ev">evennia/contrib/tutorials/evadventure/batchscripts/twitch_combat_demo.ev</a></p>
<p>You can find an example batch-command script in <a class="reference external" href="https://github.com/evennia/evennia/blob/main/evennia/contrib/tutorials/evadventure/batchscripts/turnbased_combat_demo.ev">evennia/contrib/tutorials/evadventure/batchscripts/twitch_combat_demo.ev</a></p>
</aside>
<p>Showing that the individual pieces of code works (unit testing) is not enough to be sure that your combat system is actually working. We need to test all the pieces <em>together</em>. This is often called <em>functional testing</em>. While functional testing can also be automated, wouldnt it be fun to be able to actually see our code in action?</p>
<p>This is what we need for a minimal test:</p>
@ -1317,15 +1309,12 @@ You<span class="w"> </span><span class="o">(</span>Wounded<span class="o">)</spa
<a href="Beginner-Tutorial-Combat-Base.html" title="9. Combat base framework"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">10. </span>Twitch Combat</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -17,12 +17,10 @@
<link rel="shortcut icon" href="../../../_static/favicon.ico"/>
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<link rel="next" title="Part 4: Using What We Created" href="../Part4/Beginner-Tutorial-Part4-Overview.html" />
<link rel="next" title="Part 4: Using what we created" href="../Part4/Beginner-Tutorial-Part4-Overview.html" />
<link rel="prev" title="15. In-game Shops" href="Beginner-Tutorial-Shops.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -34,18 +32,22 @@
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../Part4/Beginner-Tutorial-Part4-Overview.html" title="Part 4: Using What We Created"
<a href="../Part4/Beginner-Tutorial-Part4-Overview.html" title="Part 4: Using what we created"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Shops.html" title="15. In-game Shops"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">16. </span>In-game Commands</a></li>
</ul>
</div>
</div>
<div class="document">
@ -70,7 +72,7 @@
title="previous chapter"><span class="section-number">15. </span>In-game Shops</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="../Part4/Beginner-Tutorial-Part4-Overview.html"
title="next chapter">Part 4: Using What We Created</a></p>
title="next chapter">Part 4: Using what we created</a></p>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
@ -89,18 +91,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Commands.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -130,21 +120,18 @@
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../Part4/Beginner-Tutorial-Part4-Overview.html" title="Part 4: Using What We Created"
<a href="../Part4/Beginner-Tutorial-Part4-Overview.html" title="Part 4: Using what we created"
>next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Shops.html" title="15. In-game Shops"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">16. </span>In-game Commands</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="12. NPC and monster AI" href="Beginner-Tutorial-AI.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-AI.html" title="12. NPC and monster AI"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">13. </span>Dynamically generated Dungeon</a></li>
</ul>
</div>
</div>
<div class="document">
@ -89,18 +91,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Dungeon.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -136,15 +126,12 @@
<a href="Beginner-Tutorial-AI.html" title="12. NPC and monster AI"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">13. </span>Dynamically generated Dungeon</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="4. In-game Objects and items" href="Beginner-Tutorial-Objects.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Objects.html" title="4. In-game Objects and items"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">5. </span>Handling Equipment</a></li>
</ul>
</div>
</div>
<div class="document">
@ -80,10 +82,7 @@
<li><a class="reference internal" href="#add-and-remove">5.5. <code class="docutils literal notranslate"><span class="pre">.add</span></code> and <code class="docutils literal notranslate"><span class="pre">.remove</span></code></a></li>
<li><a class="reference internal" href="#moving-things-around">5.6. Moving things around</a></li>
<li><a class="reference internal" href="#get-everything">5.7. Get everything</a></li>
<li><a class="reference internal" href="#weapon-and-armor">5.8. Weapon and armor</a><ul>
<li><a class="reference internal" href="#fixing-the-character-class">5.8.1. Fixing the Character class</a></li>
</ul>
</li>
<li><a class="reference internal" href="#weapon-and-armor">5.8. Weapon and armor</a></li>
<li><a class="reference internal" href="#extra-credits">5.9. Extra credits</a></li>
<li><a class="reference internal" href="#unit-testing">5.10. Unit Testing</a></li>
<li><a class="reference internal" href="#summary">5.11. Summary</a></li>
@ -115,18 +114,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Equipment.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -283,7 +270,6 @@ we will skip that for this tutorial.</p>
</pre></div>
</div>
<p>Above we have assumed the <code class="docutils literal notranslate"><span class="pre">EquipmentHandler</span></code> (<code class="docutils literal notranslate"><span class="pre">.equipment</span></code>) has methods <code class="docutils literal notranslate"><span class="pre">.validate_slot_usage</span></code>, <code class="docutils literal notranslate"><span class="pre">.add</span></code> and <code class="docutils literal notranslate"><span class="pre">.remove</span></code>. But we havent actually added them yet - we just put some reasonable names! Before we can use this, we need to go actually adding those methods.</p>
<p>When you do things like <code class="docutils literal notranslate"><span class="pre">create/drop</span> <span class="pre">monster:NPC</span></code>, the npc will briefly be in your inventory before being dropped on the ground. Since an NPC is not a valid thing to equip, the EquipmentHandler will complain with an <code class="docutils literal notranslate"><span class="pre">EquipmentError</span></code> (we define this see below). So we need to</p>
</section>
<section id="expanding-the-equipmenthandler">
<h2><span class="section-number">5.3. </span>Expanding the Equipmenthandler<a class="headerlink" href="#expanding-the-equipmenthandler" title="Permalink to this headline"></a></h2>
@ -333,7 +319,7 @@ we will skip that for this tutorial.</p>
<span class="n">size</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="n">size</span>
<span class="n">max_slots</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_slots</span>
<span class="n">current_slot_usage</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">count_slots</span><span class="p">()</span>
<span class="k">return</span> <span class="n">current_slot_usage</span> <span class="o">+</span> <span class="n">size</span> <span class="o">&lt;=</span> <span class="n">max_slots</span>
<span class="k">return</span> <span class="n">current_slot_usage</span> <span class="o">+</span> <span class="n">size</span> <span class="o">&lt;=</span> <span class="n">max_slots</span><span class="p">:</span>
</pre></div>
</div>
@ -413,48 +399,34 @@ together.</p>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Put something in the backpack.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">validate_slot_usage</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">slots</span><span class="p">[</span><span class="n">WieldLocation</span><span class="o">.</span><span class="n">BACKPACK</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_save</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">validate_slot_usage</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">slots</span><span class="p">[</span><span class="n">WieldLocation</span><span class="o">.</span><span class="n">BACKPACK</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_save</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">remove</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj_or_slot</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">remove</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">slot</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Remove specific object or objects from a slot.</span>
<span class="sd"> Returns a list of 0, 1 or more objects removed from inventory.</span>
<span class="sd"> Remove contents of a particular slot, for</span>
<span class="sd"> example `equipment.remove(WieldLocation.SHIELD_HAND)`</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">slots</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">slots</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj_or_slot</span><span class="p">,</span> <span class="n">WieldLocation</span><span class="p">):</span>
<span class="c1"># a slot; if this fails, obj_or_slot must be obj</span>
<span class="k">if</span> <span class="n">obj_or_slot</span> <span class="ow">is</span> <span class="n">WieldLocation</span><span class="o">.</span><span class="n">BACKPACK</span><span class="p">:</span>
<span class="c1"># empty entire backpack</span>
<span class="n">ret</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">slots</span><span class="p">[</span><span class="n">obj_or_slot</span><span class="p">])</span>
<span class="n">slots</span><span class="p">[</span><span class="n">obj_or_slot</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">slots</span><span class="p">[</span><span class="n">obj_or_slot</span><span class="p">])</span>
<span class="n">slots</span><span class="p">[</span><span class="n">obj_or_slot</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">elif</span> <span class="n">obj_or_slot</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">slots</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
<span class="c1"># obj in use/wear slot</span>
<span class="k">for</span> <span class="n">slot</span><span class="p">,</span> <span class="n">objslot</span> <span class="ow">in</span> <span class="n">slots</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="n">objslot</span> <span class="ow">is</span> <span class="n">obj_or_slot</span><span class="p">:</span>
<span class="n">slots</span><span class="p">[</span><span class="n">slot</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">objslot</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">obj_or_slot</span> <span class="ow">in</span> <span class="n">slots</span><span class="p">[</span><span class="n">WieldLocation</span><span class="o">.</span><span class="n">BACKPACK</span><span class="p">]:</span> <span class="c1"># obj in backpack slot</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">slots</span><span class="p">[</span><span class="n">WieldLocation</span><span class="o">.</span><span class="n">BACKPACK</span><span class="p">]</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">obj_or_slot</span><span class="p">)</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">obj_or_slot</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
<span class="k">pass</span>
<span class="k">if</span> <span class="n">slot</span> <span class="ow">is</span> <span class="n">WieldLocation</span><span class="o">.</span><span class="n">BACKPACK</span><span class="p">:</span>
<span class="c1"># empty entire backpack! </span>
<span class="n">ret</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">slots</span><span class="p">[</span><span class="n">slot</span><span class="p">])</span>
<span class="n">slots</span><span class="p">[</span><span class="n">slot</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">slots</span><span class="p">[</span><span class="n">slot</span><span class="p">])</span>
<span class="n">slots</span><span class="p">[</span><span class="n">slot</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">if</span> <span class="n">ret</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_save</span><span class="p">()</span>
<span class="k">return</span> <span class="n">ret</span>
</pre></div>
</div>
<p>In <code class="docutils literal notranslate"><span class="pre">.add</span></code>, we make use of <code class="docutils literal notranslate"><span class="pre">validate_slot_usage</span></code> to
<p>Both of these should be straight forward to follow. In <code class="docutils literal notranslate"><span class="pre">.add</span></code>, we make use of <code class="docutils literal notranslate"><span class="pre">validate_slot_usage</span></code> to
double-check we can actually fit the thing, then we add the item to the backpack.</p>
<p>In <code class="docutils literal notranslate"><span class="pre">.remove</span></code>, we allow emptying both by <code class="docutils literal notranslate"><span class="pre">WieldLocation</span></code> or by explicitly saying which object to remove. Note that the first <code class="docutils literal notranslate"><span class="pre">if</span></code> statement checks if <code class="docutils literal notranslate"><span class="pre">obj_or_slot</span></code> is a slot. So if that fails then code in the other <code class="docutils literal notranslate"><span class="pre">elif</span></code> can safely assume that it must instead be an object!</p>
<p>Any removed objects are returned. If we gave <code class="docutils literal notranslate"><span class="pre">BACKPACK</span></code> as the slot, we empty the backpack and return all items inside it.</p>
<p>In <code class="docutils literal notranslate"><span class="pre">.delete</span></code>, we allow emptying by <code class="docutils literal notranslate"><span class="pre">WieldLocation</span></code> - we figure out what slot it is and return
the item within (if any). If we gave <code class="docutils literal notranslate"><span class="pre">BACKPACK</span></code> as the slot, we empty the backpack and
return all items.</p>
<p>Whenever we change the equipment loadout we must make sure to <code class="docutils literal notranslate"><span class="pre">._save()</span></code> the result, or it will be lost after a server reload.</p>
</section>
<section id="moving-things-around">
@ -475,9 +447,7 @@ double-check we can actually fit the thing, then we add the item to the backpack
<span class="c1"># make sure to remove from equipment/backpack first, to avoid double-adding</span>
<span class="bp">self</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">validate_slot_usage</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
<span class="k">return</span>
<span class="n">slots</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">slots</span>
<span class="n">use_slot</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s2">&quot;inventory_use_slot&quot;</span><span class="p">,</span> <span class="n">WieldLocation</span><span class="o">.</span><span class="n">BACKPACK</span><span class="p">)</span>
@ -547,7 +517,7 @@ double-check we can actually fit the thing, then we add the item to the backpack
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># mygame/evadventure/equipment.py </span>
<span class="kn">from</span> <span class="nn">.enums</span> <span class="kn">import</span> <span class="n">WieldLocation</span><span class="p">,</span> <span class="n">Ability</span>
<span class="kn">from</span> <span class="nn">.objects</span> <span class="kn">import</span> <span class="n">get_bare_hand</span>
<span class="kn">from</span> <span class="nn">.objects</span> <span class="kn">import</span> <span class="n">get_empty_hand</span>
<span class="c1"># ... </span>
@ -586,52 +556,6 @@ double-check we can actually fit the thing, then we add the item to the backpack
</div>
<p>In the <code class="docutils literal notranslate"><span class="pre">.armor()</span></code> method we get the item (if any) out of each relevant wield-slot (body, shield, head), and grab their <code class="docutils literal notranslate"><span class="pre">armor</span></code> Attribute. We then <code class="docutils literal notranslate"><span class="pre">sum()</span></code> them all up.</p>
<p>In <code class="docutils literal notranslate"><span class="pre">.weapon()</span></code>, we simply check which of the possible weapon slots (weapon-hand or two-hands) have something in them. If not we fall back to the Bare Hands object we created in the <a class="reference internal" href="Beginner-Tutorial-Objects.html#your-bare-hands"><span class="std std-doc">Object tutorial lesson</span></a> earlier.</p>
<section id="fixing-the-character-class">
<h3><span class="section-number">5.8.1. </span>Fixing the Character class<a class="headerlink" href="#fixing-the-character-class" title="Permalink to this headline"></a></h3>
<p>So we have added our equipment handler which validate what we put in it. This will however lead to a problem when we create things like NPCs in game, e.g. with</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>create/drop monster:evadventure.npcs.EvAdventureNPC
</pre></div>
</div>
<p>The problem is that when the/ monster is created it will briefly appear in your inventory before being dropped, so this code will fire on you when you do that (assuming you are an <code class="docutils literal notranslate"><span class="pre">EvAdventureCharacter</span></code>):</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># mygame/evadventure/characters.py</span>
<span class="c1"># ... </span>
<span class="k">class</span> <span class="nc">EvAdventureCharacter</span><span class="p">(</span><span class="n">LivingMixin</span><span class="p">,</span> <span class="n">DefaultCharacter</span><span class="p">):</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">at_object_receive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">moved_object</span><span class="p">,</span> <span class="n">source_location</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; </span>
<span class="sd"> Called by Evennia when an object arrives &#39;in&#39; the character.</span>
<span class="sd"> </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">equipment</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">moved_object</span><span class="p">)</span>
</pre></div>
</div>
<p>At this means that the equipmenthandler will check the NPC, and since its not a equippable thing, an <code class="docutils literal notranslate"><span class="pre">EquipmentError</span></code> will be raised, failing the creation. Since we want to be able to create npcs etc easily, we will handle this error with a <code class="docutils literal notranslate"><span class="pre">try...except</span></code> statement like so:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># mygame/evadventure/characters.py</span>
<span class="c1"># ... </span>
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">logger</span>
<span class="kn">from</span> <span class="nn">.equipment</span> <span class="kn">import</span> <span class="n">EquipmentError</span>
<span class="k">class</span> <span class="nc">EvAdventureCharacter</span><span class="p">(</span><span class="n">LivingMixin</span><span class="p">,</span> <span class="n">DefaultCharacter</span><span class="p">):</span>
<span class="c1"># ... </span>
<span class="k">def</span> <span class="nf">at_object_receive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">moved_object</span><span class="p">,</span> <span class="n">source_location</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; </span>
<span class="sd"> Called by Evennia when an object arrives &#39;in&#39; the character.</span>
<span class="sd"> </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">equipment</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">moved_object</span><span class="p">)</span>
<span class="k">except</span> <span class="n">EquipmentError</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">log_trace</span><span class="p">()</span>
</pre></div>
</div>
<p>Using Evennias <code class="docutils literal notranslate"><span class="pre">logger.log_trace()</span></code> we catch the error and direct it to the server log. This allows you to see if there are real errors here as well, but once things work and these errors are spammy, you can also just replace the <code class="docutils literal notranslate"><span class="pre">logger.log_trace()</span></code> line with a <code class="docutils literal notranslate"><span class="pre">pass</span></code> to hide these errors.</p>
</section>
</section>
<section id="extra-credits">
<h2><span class="section-number">5.9. </span>Extra credits<a class="headerlink" href="#extra-credits" title="Permalink to this headline"></a></h2>
@ -664,9 +588,8 @@ passing these into the handlers methods.</p>
<span class="kn">from</span> <span class="nn">evennia.utils</span> <span class="kn">import</span> <span class="n">create</span>
<span class="kn">from</span> <span class="nn">evennia.utils.test_resources</span> <span class="kn">import</span> <span class="n">BaseEvenniaTest</span>
<span class="kn">from</span> <span class="nn">..objects</span> <span class="kn">import</span> <span class="n">EvAdventureObject</span><span class="p">,</span> <span class="n">EvAdventureHelmet</span><span class="p">,</span> <span class="n">EvAdventureWeapon</span>
<span class="kn">from</span> <span class="nn">..objects</span> <span class="kn">import</span> <span class="n">EvAdventureRoom</span>
<span class="kn">from</span> <span class="nn">..enums</span> <span class="kn">import</span> <span class="n">WieldLocation</span>
<span class="kn">from</span> <span class="nn">..characters</span> <span class="kn">import</span> <span class="n">EvAdventureCharacter</span>
<span class="k">class</span> <span class="nc">TestEquipment</span><span class="p">(</span><span class="n">BaseEvenniaTest</span><span class="p">):</span>
@ -718,15 +641,12 @@ passing these into the handlers methods.</p>
<a href="Beginner-Tutorial-Objects.html" title="4. In-game Objects and items"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">5. </span>Handling Equipment</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="7. In-game Rooms" href="Beginner-Tutorial-Rooms.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Rooms.html" title="7. In-game Rooms"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">8. </span>Non-Player-Characters</a></li>
</ul>
</div>
</div>
<div class="document">
@ -99,18 +101,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-NPCs.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -341,15 +331,12 @@
<a href="Beginner-Tutorial-Rooms.html" title="7. In-game Rooms"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">8. </span>Non-Player-Characters</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="3. Player Characters" href="Beginner-Tutorial-Characters.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Characters.html" title="3. Player Characters"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">4. </span>In-game Objects and items</a></li>
</ul>
</div>
</div>
<div class="document">
@ -109,18 +111,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Objects.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -354,10 +344,10 @@ types) with Evennias search functions:</p>
<span class="n">inventory_use_slot</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="n">WieldLocation</span><span class="o">.</span><span class="n">WEAPON_HAND</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">quality</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">attack_type</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="n">Ability</span><span class="o">.</span><span class="n">STR</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">defend_type</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="n">Ability</span><span class="o">.</span><span class="n">ARMOR</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">attack_type</span> <span class="o">=</span> <span class="n">AttibuteProperty</span><span class="p">(</span><span class="n">Ability</span><span class="o">.</span><span class="n">STR</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">defend_type</span> <span class="o">=</span> <span class="n">AttibuteProperty</span><span class="p">(</span><span class="n">Ability</span><span class="o">.</span><span class="n">ARMOR</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">damage_roll</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="s2">&quot;1d6&quot;</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">damage_roll</span> <span class="o">=</span> <span class="n">AttibuteProperty</span><span class="p">(</span><span class="s2">&quot;1d6&quot;</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">at_pre_use</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
@ -481,10 +471,10 @@ types) with Evennias search functions:</p>
<span class="n">inventory_use_slot</span> <span class="o">=</span> <span class="n">WieldLocation</span><span class="o">.</span><span class="n">TWO_HANDS</span> <span class="c1"># always two hands for magic</span>
<span class="n">quality</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">attack_type</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="n">Ability</span><span class="o">.</span><span class="n">INT</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">defend_type</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="n">Ability</span><span class="o">.</span><span class="n">DEX</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">attack_type</span> <span class="o">=</span> <span class="n">AttibuteProperty</span><span class="p">(</span><span class="n">Ability</span><span class="o">.</span><span class="n">INT</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">defend_type</span> <span class="o">=</span> <span class="n">AttibuteProperty</span><span class="p">(</span><span class="n">Ability</span><span class="o">.</span><span class="n">DEX</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">damage_roll</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="s2">&quot;1d8&quot;</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">damage_roll</span> <span class="o">=</span> <span class="n">AttibuteProperty</span><span class="p">(</span><span class="s2">&quot;1d8&quot;</span><span class="p">,</span> <span class="n">autocreate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">at_post_use</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Called after usage/spell was cast&quot;&quot;&quot;</span>
@ -597,15 +587,12 @@ types) with Evennias search functions:</p>
<a href="Beginner-Tutorial-Characters.html" title="3. Player Characters"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">4. </span>In-game Objects and items</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -6,7 +6,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Part 3: How We Get There (Example Game) &#8212; Evennia 2.x documentation</title>
<title>Part 3: How we get there (example game) &#8212; Evennia 2.x documentation</title>
<link rel="stylesheet" href="../../../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
@ -21,8 +21,6 @@
<link rel="prev" title="3. Planning our tutorial game" href="../Part2/Beginner-Tutorial-Planning-The-Tutorial-Game.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,11 +38,15 @@
<a href="../Part2/Beginner-Tutorial-Planning-The-Tutorial-Game.html" title="3. Planning our tutorial game"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" accesskey="U">Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Part 3: How We Get There (Example Game)</a></li>
<li class="nav-item nav-item-this"><a href="">Part 3: How we get there (example game)</a></li>
</ul>
</div>
</div>
<div class="document">
@ -66,7 +68,7 @@
<script>$('#searchbox').show(0);</script>
<h3><a href="../../../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Part 3: How We Get There (Example Game)</a><ul>
<li><a class="reference internal" href="#">Part 3: How we get there (example game)</a><ul>
<li><a class="reference internal" href="#lessons">Lessons</a></li>
</ul>
</li>
@ -96,25 +98,13 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Part3-Overview.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section class="tex2jax_ignore mathjax_ignore" id="part-3-how-we-get-there-example-game">
<h1>Part 3: How We Get There (Example Game)<a class="headerlink" href="#part-3-how-we-get-there-example-game" title="Permalink to this headline"></a></h1>
<h1>Part 3: How we get there (example game)<a class="headerlink" href="#part-3-how-we-get-there-example-game" title="Permalink to this headline"></a></h1>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>The tutorial game is under development and is not yet complete, nor tested. Use the existing lessons as inspiration and to help get you going, but dont expect out-of-the-box perfection from it at this time.</p>
@ -124,16 +114,16 @@
<ul class="simple">
<li><p><a class="reference internal" href="../Beginner-Tutorial-Overview.html"><span class="doc std std-doc">Introduction</span></a>
<br>Getting set up.</p></li>
<li><p>Part 1: <a class="reference internal" href="../Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">What We Have</span></a>
<li><p>Part 1: <a class="reference internal" href="../Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">What we have</span></a>
<br>A tour of Evennia and how to use the tools, including an introduction to Python.</p></li>
<li><p>Part 2: <a class="reference internal" href="../Part2/Beginner-Tutorial-Part2-Overview.html"><span class="doc std std-doc">What We Want</span></a>
<br>Planning our tutorial game and what to consider when planning your own.</p></li>
<li><p><em>Part 3: <a class="reference internal" href="#"><span class="doc std std-doc">How We Get There</span></a></em>
<br>Getting down to the meat of extending Evennia to make your game.</p></li>
<li><p>Part 4: <a class="reference internal" href="../Part4/Beginner-Tutorial-Part4-Overview.html"><span class="doc std std-doc">Using What We Created</span></a>
<br>Building a tech-demo and world content to go with our code.</p></li>
<li><p>Part 5: <a class="reference internal" href="../Part5/Beginner-Tutorial-Part5-Overview.html"><span class="doc std std-doc">Showing the World</span></a>
<br>Taking our new game online and letting players try it out.</p></li>
<li><p>Part 2: <a class="reference internal" href="../Part2/Beginner-Tutorial-Part2-Overview.html"><span class="doc std std-doc">What we want</span></a>
<br>Planning our tutorial game and what to think about when planning your own in the future.</p></li>
<li><p><strong>Part 3: <a class="reference internal" href="#"><span class="doc std std-doc">How we get there</span></a></strong>
<br>Getting down to the meat of extending Evennia to make our game</p></li>
<li><p>Part 4: <a class="reference internal" href="../Part4/Beginner-Tutorial-Part4-Overview.html"><span class="doc std std-doc">Using what we created</span></a>
<br>Building a tech-demo and world content to go with our code</p></li>
<li><p>Part 5: <a class="reference internal" href="../Part5/Beginner-Tutorial-Part5-Overview.html"><span class="doc std std-doc">Showing the world</span></a>
<br>Taking our new game online and let players try it out</p></li>
</ul>
</aside>
<p>In part three of the Evennia Beginner tutorial we will go through the actual creation of
@ -297,14 +287,11 @@ of experience using Evennia and be really helpful for doing your own thing later
<a href="../Part2/Beginner-Tutorial-Planning-The-Tutorial-Game.html" title="3. Planning our tutorial game"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Part 3: How We Get There (Example Game)</a></li>
<li class="nav-item nav-item-this"><a href="">Part 3: How we get there (example game)</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="13. Dynamically generated Dungeon" href="Beginner-Tutorial-Dungeon.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Dungeon.html" title="13. Dynamically generated Dungeon"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">14. </span>Game Quests</a></li>
</ul>
</div>
</div>
<div class="document">
@ -89,18 +91,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Quests.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -136,15 +126,12 @@
<a href="Beginner-Tutorial-Dungeon.html" title="13. Dynamically generated Dungeon"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">14. </span>Game Quests</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="6. Character Generation" href="Beginner-Tutorial-Chargen.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Chargen.html" title="6. Character Generation"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">7. </span>In-game Rooms</a></li>
</ul>
</div>
</div>
<div class="document">
@ -102,18 +104,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Rooms.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -410,7 +400,7 @@ Exits:<span class="w"> </span>north,<span class="w"> </span>northeast,<span clas
<p>The <a class="reference internal" href="../../../Components/TickerHandler.html"><span class="doc std std-doc">TickerHandler</span></a>. This is acts as a please tick me - subscription service. In <strong>Line 22</strong> we tell add our <code class="docutils literal notranslate"><span class="pre">.send_echo</span></code> method to the handler and tell the TickerHandler to call that method every <code class="docutils literal notranslate"><span class="pre">.echo_rate</span></code> seconds.</p>
<p>When the <code class="docutils literal notranslate"><span class="pre">.send_echo</span></code> method is called, it will use <code class="docutils literal notranslate"><span class="pre">random.random()</span></code> to check if we should <em>actually</em> do anything. In our example we only show a message 10% of the time. In that case we use Pythons <code class="docutils literal notranslate"><span class="pre">random.choice()</span></code> to grab a random text string from the <code class="docutils literal notranslate"><span class="pre">.echoes</span></code> list to send to everyone inside this room.</p>
<p>Heres how youd use this room in-game:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; dig market:evadventure.rooms.EchoingRoom = market,back
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&gt; dig market:evadventure.EchoingRoom = market,back
&gt; market
&gt; set here/echoes = [&quot;You hear a merchant shouting&quot;, &quot;You hear the clatter of coins&quot;]
&gt; py here.start_echo()
@ -487,15 +477,12 @@ Exits:<span class="w"> </span>north,<span class="w"> </span>northeast,<span clas
<a href="Beginner-Tutorial-Chargen.html" title="6. Character Generation"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">7. </span>In-game Rooms</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="1. Code structure and Utilities" href="Beginner-Tutorial-Utilities.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Utilities.html" title="1. Code structure and Utilities"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">2. </span>Rules and dice rolling</a></li>
</ul>
</div>
</div>
<div class="document">
@ -114,18 +116,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Rules.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -306,7 +296,7 @@ crazy big so the loop takes forever!</p>
<section id="rolling-with-advantage">
<h3><span class="section-number">2.3.2. </span>Rolling with advantage<a class="headerlink" href="#rolling-with-advantage" title="Permalink to this headline"></a></h3>
<p>Now that we have the generic roller, we can start using it to do a more complex roll.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/evadventure/rules.py </span>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/evadventure/rules.py </span>
<span class="c1"># ... </span>
@ -359,46 +349,46 @@ Attribute is available as <code class="docutils literal notranslate"><span class
<span class="k">class</span> <span class="nc">EvAdventureRollEngine</span><span class="p">:</span>
<span class="k">def</span> <span class="nf">roll</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
<span class="c1"># ...</span>
<span class="k">def</span> <span class="nf">roll</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
<span class="c1"># ...</span>
<span class="k">def</span> <span class="nf">roll_with_advantage_or_disadvantage</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
<span class="c1"># ...</span>
<span class="k">def</span> <span class="nf">roll_with_advantage_or_disadvantage</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
<span class="c1"># ...</span>
<span class="k">def</span> <span class="nf">saving_throw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">character</span><span class="p">,</span> <span class="n">bonus_type</span><span class="o">=</span><span class="n">Ability</span><span class="o">.</span><span class="n">STR</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span>
<span class="n">advantage</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">disadvantage</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; </span>
<span class="sd"> Do a saving throw, trying to beat a target.</span>
<span class="k">def</span> <span class="nf">saving_throw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">character</span><span class="p">,</span> <span class="n">bonus_type</span><span class="o">=</span><span class="n">Ability</span><span class="o">.</span><span class="n">STR</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span>
<span class="n">advantage</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">disadvantage</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; </span>
<span class="sd"> Do a saving throw, trying to beat a target.</span>
<span class="sd"> </span>
<span class="sd"> Args:</span>
<span class="sd"> character (Character): A character (assumed to have Ability bonuses</span>
<span class="sd"> stored on itself as Attributes).</span>
<span class="sd"> bonus_type (Ability): A valid Ability bonus enum.</span>
<span class="sd"> target (int): The target number to beat. Always 15 in Knave.</span>
<span class="sd"> advantage (bool): If character has advantage on this roll.</span>
<span class="sd"> disadvantage (bool): If character has disadvantage on this roll.</span>
<span class="sd"> Args:</span>
<span class="sd"> character (Character): A character (assumed to have Ability bonuses</span>
<span class="sd"> stored on itself as Attributes).</span>
<span class="sd"> bonus_type (Ability): A valid Ability bonus enum.</span>
<span class="sd"> target (int): The target number to beat. Always 15 in Knave.</span>
<span class="sd"> advantage (bool): If character has advantage on this roll.</span>
<span class="sd"> disadvantage (bool): If character has disadvantage on this roll.</span>
<span class="sd"> </span>
<span class="sd"> Returns:</span>
<span class="sd"> tuple: A tuple (bool, Ability), showing if the throw succeeded and </span>
<span class="sd"> the quality is one of None or Ability.CRITICAL_FAILURE/SUCCESS</span>
<span class="sd"> Returns:</span>
<span class="sd"> tuple: A tuple (bool, Ability), showing if the throw succeeded and </span>
<span class="sd"> the quality is one of None or Ability.CRITICAL_FAILURE/SUCCESS</span>
<span class="sd"> </span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># make a roll </span>
<span class="n">dice_roll</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">roll_with_advantage_or_disadvantage</span><span class="p">(</span><span class="n">advantage</span><span class="p">,</span> <span class="n">disadvantage</span><span class="p">)</span>
<span class="c1"># make a roll </span>
<span class="n">dice_roll</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">roll_with_advantage_or_disadvantage</span><span class="p">(</span><span class="n">advantage</span><span class="p">,</span> <span class="n">disadvantage</span><span class="p">)</span>
<span class="c1"># figure out if we had critical failure/success</span>
<span class="n">quality</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">if</span> <span class="n">dice_roll</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">quality</span> <span class="o">=</span> <span class="n">Ability</span><span class="o">.</span><span class="n">CRITICAL_FAILURE</span>
<span class="k">elif</span> <span class="n">dice_roll</span> <span class="o">==</span> <span class="mi">20</span><span class="p">:</span>
<span class="n">quality</span> <span class="o">=</span> <span class="n">Ability</span><span class="o">.</span><span class="n">CRITICAL_SUCCESS</span>
<span class="c1"># figure out if we had critical failure/success</span>
<span class="n">quality</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">if</span> <span class="n">dice_roll</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">quality</span> <span class="o">=</span> <span class="n">Ability</span><span class="o">.</span><span class="n">CRITICAL_FAILURE</span>
<span class="k">elif</span> <span class="n">dice_roll</span> <span class="o">==</span> <span class="mi">20</span><span class="p">:</span>
<span class="n">quality</span> <span class="o">=</span> <span class="n">Ability</span><span class="o">.</span><span class="n">CRITICAL_SUCCESS</span>
<span class="c1"># figure out bonus</span>
<span class="n">bonus</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">character</span><span class="p">,</span> <span class="n">bonus_type</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="c1"># figure out bonus</span>
<span class="n">bonus</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">character</span><span class="p">,</span> <span class="n">bonus_type</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="c1"># return a tuple (bool, quality)</span>
<span class="k">return</span> <span class="p">(</span><span class="n">dice_roll</span> <span class="o">+</span> <span class="n">bonus</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">target</span><span class="p">,</span> <span class="n">quality</span>
<span class="c1"># return a tuple (bool, quality)</span>
<span class="k">return</span> <span class="p">(</span><span class="n">dice_roll</span> <span class="o">+</span> <span class="n">bonus</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">target</span><span class="p">,</span> <span class="n">quality</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">getattr(obj,</span> <span class="pre">attrname,</span> <span class="pre">default)</span></code> function is a very useful Python tool for getting an attribute
@ -602,7 +592,9 @@ So the result for <code class="docutils literal notranslate"><span class="pre">1
</section>
<section id="roll-for-death">
<h3><span class="section-number">2.3.8. </span>Roll for death<a class="headerlink" href="#roll-for-death" title="Permalink to this headline"></a></h3>
<p>While original Knave suggests hitting 0 HP means insta-death, we will grab the optional “death table” from the “prettified” Knaves optional rules to make it a little less punishing. We also changed the result of <code class="docutils literal notranslate"><span class="pre">2</span></code> to dead since we dont simulate dismemberment in this tutorial:</p>
<p>While original Knave suggests hitting 0 HP means insta-death, we will grab the optional “death table”
from the “prettified” Knaves optional rules to make it a little less punishing. We also changed the
result of <code class="docutils literal notranslate"><span class="pre">2</span></code> to dead since we dont simulate dismemberment in this tutorial:</p>
<table class="colwidths-auto docutils align-default">
<thead>
<tr class="row-odd"><th class="text-align:center head"><p>Roll</p></th>
@ -641,17 +633,19 @@ So the result for <code class="docutils literal notranslate"><span class="pre">1
</tr>
</tbody>
</table>
<p>All the non-dead values map to a loss of 1d4 in one of the six Abilities (but you get HP back). We need to map back to this from the above table. One also cannot have less than -10 Ability bonus, if you do, you die too.</p>
<p>All the non-dead values map to a loss of 1d4 in one of the six Abilities (but you get HP back).
We need to map back to this from the above table. One also cannot have less than -10 Ability bonus,
if you do, you die too.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/evadventure/rules.py </span>
<span class="n">death_table</span> <span class="o">=</span> <span class="p">(</span>
<span class="p">(</span><span class="s2">&quot;1-2&quot;</span><span class="p">,</span> <span class="s2">&quot;dead&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;3&quot;</span><span class="p">,</span> <span class="s2">&quot;strength&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;4&quot;</span><span class="p">,</span> <span class="s2">&quot;dexterity&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;5&quot;</span><span class="p">,</span> <span class="s2">&quot;constitution&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;6&quot;</span><span class="p">,</span> <span class="s2">&quot;intelligence&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;7&quot;</span><span class="p">,</span> <span class="s2">&quot;wisdom&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;8&quot;</span><span class="p">,</span> <span class="s2">&quot;charisma&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;3&quot;</span><span class="p">:</span> <span class="s2">&quot;strength&quot;</span><span class="p">,</span>
<span class="p">(</span><span class="s2">&quot;4&quot;</span><span class="p">:</span> <span class="s2">&quot;dexterity&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;5&quot;</span><span class="p">:</span> <span class="s2">&quot;constitution&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;6&quot;</span><span class="p">:</span> <span class="s2">&quot;intelligence&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;7&quot;</span><span class="p">:</span> <span class="s2">&quot;wisdom&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;8&quot;</span><span class="p">:</span> <span class="s2">&quot;charisma&quot;</span><span class="p">),</span>
<span class="p">)</span>
@ -679,7 +673,7 @@ So the result for <code class="docutils literal notranslate"><span class="pre">1
<span class="k">pass</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># refresh 1d4 health, but suffer 1d4 ability loss</span>
<span class="bp">self</span><span class="o">.</span><span class="n">heal</span><span class="p">(</span><span class="n">character</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="s2">&quot;1d4&quot;</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">heal</span><span class="p">(</span><span class="n">character</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="s2">&quot;1d4&quot;</span><span class="p">)</span>
<span class="nb">setattr</span><span class="p">(</span><span class="n">character</span><span class="p">,</span> <span class="n">ability_name</span><span class="p">,</span> <span class="n">current_ability</span><span class="p">)</span>
<span class="n">character</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span>
@ -692,7 +686,9 @@ So the result for <code class="docutils literal notranslate"><span class="pre">1
</div>
<p>Here we roll on the death table from the rules to see what happens. We give the character
a message if they survive, to let them know what happened.</p>
<p>We dont yet know what killing the character technically means, so we mark this as <code class="docutils literal notranslate"><span class="pre">TODO</span></code> and return to it in a later lesson. We just know that we need to do <em>something</em> here to kill off the character!</p>
<p>We dont yet know what killing the character technically means, so we mark this as <code class="docutils literal notranslate"><span class="pre">TODO</span></code> and
return to it in a later lesson. We just know that we need to do <em>something</em> here to kill off the
character!</p>
</section>
</section>
<section id="testing">
@ -717,7 +713,7 @@ a message if they survive, to let them know what happened.</p>
<span class="nd">@patch</span><span class="p">(</span><span class="s2">&quot;evadventure.rules.randint&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">test_roll</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mock_randint</span><span class="p">):</span>
<span class="n">mock_randint</span><span class="o">.</span><span class="n">return_value</span> <span class="o">=</span> <span class="mi">4</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">roll_engine</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="s2">&quot;1d6&quot;</span><span class="p">),</span> <span class="mi">4</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">roll_engine</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="s2">&quot;1d6&quot;</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">roll_engine</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="s2">&quot;2d6&quot;</span><span class="p">),</span> <span class="mi">2</span> <span class="o">*</span> <span class="mi">4</span><span class="p">)</span>
<span class="c1"># test of the other rule methods below ...</span>
@ -737,9 +733,14 @@ has a complete example of rule testing.</p>
test method. We use <code class="docutils literal notranslate"><span class="pre">super().setUp()</span></code> to make sure the parent class version of this method
always fire. Then we create a fresh <code class="docutils literal notranslate"><span class="pre">EvAdventureRollEngine</span></code> we can test with.</p>
<p>In our test, we import <code class="docutils literal notranslate"><span class="pre">patch</span></code> from the <code class="docutils literal notranslate"><span class="pre">unittest.mock</span></code> library. This is a very useful tool for testing.
Normally the <code class="docutils literal notranslate"><span class="pre">randint</span></code> function we imported in <code class="docutils literal notranslate"><span class="pre">rules</span></code> will return a random value. Thats very hard to test for, since the value will be different every test.</p>
<p>With <code class="docutils literal notranslate"><span class="pre">&#64;patch</span></code> (this is called a <em>decorator</em>), we temporarily replace <code class="docutils literal notranslate"><span class="pre">rules.randint</span></code> with a mock - a dummy entity. This mock is passed into the testing method. We then take this <code class="docutils literal notranslate"><span class="pre">mock_randint</span></code> and set <code class="docutils literal notranslate"><span class="pre">.return_value</span> <span class="pre">=</span> <span class="pre">4</span></code> on it.</p>
<p>Adding <code class="docutils literal notranslate"><span class="pre">return_value</span></code> to the mock means that every time this mock is called, it will return 4. For the duration of the test we can now check with <code class="docutils literal notranslate"><span class="pre">self.assertEqual</span></code> that our <code class="docutils literal notranslate"><span class="pre">roll</span></code> method always returns a result as-if the random result was 4.</p>
Normally the <code class="docutils literal notranslate"><span class="pre">randint</span></code> function we imported in <code class="docutils literal notranslate"><span class="pre">rules</span></code> will return a random value. Thats very hard to
test for, since the value will be different every test.</p>
<p>With <code class="docutils literal notranslate"><span class="pre">&#64;patch</span></code> (this is called a <em>decorator</em>), we temporarily replace <code class="docutils literal notranslate"><span class="pre">rules.randint</span></code> with a mock - a
dummy entity. This mock is passed into the testing method. We then take this <code class="docutils literal notranslate"><span class="pre">mock_randint</span></code> and set
<code class="docutils literal notranslate"><span class="pre">.return_value</span> <span class="pre">=</span> <span class="pre">4</span></code> on it.</p>
<p>Adding <code class="docutils literal notranslate"><span class="pre">return_value</span></code> to the mock means that every time this mock is called, it will return 4. For the
duration of the test we can now check with <code class="docutils literal notranslate"><span class="pre">self.assertEqual</span></code> that our <code class="docutils literal notranslate"><span class="pre">roll</span></code> method always returns a
result as-if the random result was 4.</p>
<p>There are <a class="reference external" href="https://realpython.com/python-mock-library/">many resources for understanding mock</a>, refer to
them for further help.</p>
<blockquote>
@ -749,7 +750,9 @@ them for further help.</p>
</section>
<section id="summary">
<h2><span class="section-number">2.5. </span>Summary<a class="headerlink" href="#summary" title="Permalink to this headline"></a></h2>
<p>This concludes all the core rule mechanics of <em>Knave</em> - the rules used during play. We noticed here that we are going to soon need to establish how our <em>Character</em> actually stores data. So we will address that next.</p>
<p>This concludes all the core rule mechanics of <em>Knave</em> - the rules used during play. We noticed here
that we are going to soon need to establish how our <em>Character</em> actually stores data. So we will
address that next.</p>
</section>
</section>
@ -775,15 +778,12 @@ them for further help.</p>
<a href="Beginner-Tutorial-Utilities.html" title="1. Code structure and Utilities"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">2. </span>Rules and dice rolling</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -21,8 +21,6 @@
<link rel="prev" title="14. Game Quests" href="Beginner-Tutorial-Quests.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,12 +38,16 @@
<a href="Beginner-Tutorial-Quests.html" title="14. Game Quests"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">15. </span>In-game Shops</a></li>
</ul>
</div>
</div>
<div class="document">
@ -89,18 +91,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Shops.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -136,15 +126,12 @@
<a href="Beginner-Tutorial-Quests.html" title="14. Game Quests"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">15. </span>In-game Shops</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -18,11 +18,9 @@
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<link rel="next" title="2. Rules and dice rolling" href="Beginner-Tutorial-Rules.html" />
<link rel="prev" title="Part 3: How We Get There (Example Game)" href="Beginner-Tutorial-Part3-Overview.html" />
<link rel="prev" title="Part 3: How we get there (example game)" href="Beginner-Tutorial-Part3-Overview.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -37,15 +35,19 @@
<a href="Beginner-Tutorial-Rules.html" title="2. Rules and dice rolling"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Part3-Overview.html" title="Part 3: How We Get There (Example Game)"
<a href="Beginner-Tutorial-Part3-Overview.html" title="Part 3: How we get there (example game)"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" accesskey="U">Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">1. </span>Code structure and Utilities</a></li>
</ul>
</div>
</div>
<div class="document">
@ -82,7 +84,7 @@
<h4>Previous topic</h4>
<p class="topless"><a href="Beginner-Tutorial-Part3-Overview.html"
title="previous chapter">Part 3: How We Get There (Example Game)</a></p>
title="previous chapter">Part 3: How we get there (example game)</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="Beginner-Tutorial-Rules.html"
title="next chapter"><span class="section-number">2. </span>Rules and dice rolling</a></p>
@ -104,18 +106,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Utilities.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -267,7 +257,7 @@ folders into packages Python understands to import from.</p>
</pre></div>
</div>
<p>Heres the start of how the function could look:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/evadventure/utils.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/evadventure/time.py</span>
<span class="n">_OBJ_STATS</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
<span class="s2">|c</span><span class="si">{key}</span><span class="s2">|n</span>
@ -276,7 +266,7 @@ folders into packages Python understands to import from.</p>
<span class="si">{desc}</span>
<span class="s2">Slots: |w</span><span class="si">{size}</span><span class="s2">|n, Used from: |w</span><span class="si">{use_slot_name}</span><span class="s2">|n</span>
<span class="s2">Quality: |w</span><span class="si">{quality}</span><span class="s2">|n, Uses: |w</span><span class="si">{uses}</span><span class="s2">|n</span>
<span class="s2">Quality: |w</span><span class="si">{quality}</span><span class="s2">|n, Uses: |wuses|n</span>
<span class="s2">Attacks using |w</span><span class="si">{attack_type_name}</span><span class="s2">|n against |w</span><span class="si">{defense_type_name}</span><span class="s2">|n</span>
<span class="s2">Damage roll: |w</span><span class="si">{damage_roll}</span><span class="s2">|n</span>
<span class="s2">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
@ -301,10 +291,10 @@ folders into packages Python understands to import from.</p>
<span class="n">desc</span><span class="o">=</span><span class="n">obj</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">desc</span><span class="p">,</span>
<span class="n">size</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
<span class="n">quality</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
<span class="n">uses</span><span class="o">=</span><span class="s2">&quot;infinite&quot;</span><span class="p">,</span>
<span class="n">uses</span><span class="o">=</span><span class="s2">&quot;infinite&quot;</span>
<span class="n">use_slot_name</span><span class="o">=</span><span class="s2">&quot;backpack&quot;</span><span class="p">,</span>
<span class="n">attack_type_name</span><span class="o">=</span><span class="s2">&quot;strength&quot;</span><span class="p">,</span>
<span class="n">defense_type_name</span><span class="o">=</span><span class="s2">&quot;armor&quot;</span><span class="p">,</span>
<span class="n">attack_type_name</span><span class="o">=</span><span class="s2">&quot;strength&quot;</span>
<span class="n">defense_type_name</span><span class="o">=</span><span class="s2">&quot;armor&quot;</span>
<span class="n">damage_roll</span><span class="o">=</span><span class="s2">&quot;1d6&quot;</span>
<span class="p">)</span>
</pre></div>
@ -334,11 +324,11 @@ testing <code class="docutils literal notranslate"><span class="pre">get_obj_sta
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># mygame/evadventure/tests/test_utils.py</span>
<span class="kn">from</span> <span class="nn">evennia.utils</span> <span class="kn">import</span> <span class="n">create</span>
<span class="kn">from</span> <span class="nn">evennia.utils.test_resources</span> <span class="kn">import</span> <span class="n">EvenniaTest</span>
<span class="kn">from</span> <span class="nn">evennia.utils.test_resources</span> <span class="kn">import</span> <span class="n">BaseEvenniaTest</span>
<span class="kn">from</span> <span class="nn">..import</span> <span class="n">utils</span>
<span class="k">class</span> <span class="nc">TestUtils</span><span class="p">(</span><span class="n">EvenniaTest</span><span class="p">):</span>
<span class="k">class</span> <span class="nc">TestUtils</span><span class="p">(</span><span class="n">BaseEvenniaTest</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">test_get_obj_stats</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="c1"># make a simple object to test with </span>
<span class="n">obj</span> <span class="o">=</span> <span class="n">create</span><span class="o">.</span><span class="n">create_object</span><span class="p">(</span>
@ -352,7 +342,7 @@ testing <code class="docutils literal notranslate"><span class="pre">get_obj_sta
<span class="n">result</span><span class="p">,</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot; </span>
<span class="sd">|ctestobj|n</span>
<span class="sd">Value: ~|y10|n coins[not carried]</span>
<span class="sd">Value: ~|y10|n coins</span>
<span class="sd">A test object</span>
@ -365,11 +355,7 @@ testing <code class="docutils literal notranslate"><span class="pre">get_obj_sta
</pre></div>
</div>
<p>What happens here is that we create a new test-class <code class="docutils literal notranslate"><span class="pre">TestUtils</span></code> that inherits from <code class="docutils literal notranslate"><span class="pre">EvenniaTest</span></code>. This inheritance is what makes this a testing class.</p>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>Its useful for any game dev to know how to effectively test their code. So well try to include a <em>Testing</em> section at the end of each of the implementation lessons to follow. Writing tests for your code is optional but highly recommended. It can feel a little cumbersome or time-consuming at first … but youll thank yourself later.</p>
</div>
<p>What happens here is that we create a new test-class <code class="docutils literal notranslate"><span class="pre">TestUtils</span></code> that inherits from <code class="docutils literal notranslate"><span class="pre">BaseEvenniaTest</span></code>. This inheritance is what makes this a testing class.</p>
<p>We can have any number of methods on this class. To have a method recognized as one containing code to test, its name <em>must</em> start with <code class="docutils literal notranslate"><span class="pre">test_</span></code>. We have one - <code class="docutils literal notranslate"><span class="pre">test_get_obj_stats</span></code>.</p>
<p>In this method we create a dummy <code class="docutils literal notranslate"><span class="pre">obj</span></code> and gives it a <code class="docutils literal notranslate"><span class="pre">key</span></code> “testobj”. Note how we add the <code class="docutils literal notranslate"><span class="pre">desc</span></code> <a class="reference internal" href="../../../Components/Attributes.html"><span class="doc std std-doc">Attribute</span></a> directly in the <code class="docutils literal notranslate"><span class="pre">create_object</span></code> call by specifying the attribute as a tuple <code class="docutils literal notranslate"><span class="pre">(name,</span> <span class="pre">value)</span></code>!</p>
<p>We then get the result of passing this dummy-object through <code class="docutils literal notranslate"><span class="pre">get_obj_stats</span></code> we imported earlier.</p>
@ -377,17 +363,18 @@ testing <code class="docutils literal notranslate"><span class="pre">get_obj_sta
<section id="running-your-test">
<h3><span class="section-number">1.4.1. </span>Running your test<a class="headerlink" href="#running-your-test" title="Permalink to this headline"></a></h3>
<p>To run your test you need to stand inside your <code class="docutils literal notranslate"><span class="pre">mygame</span></code> folder and execute the following command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>evennia test --settings settings.py evadventure.tests
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>evennia test --settings settings.py .evadventure.tests
</pre></div>
</div>
<p>This will run all your <code class="docutils literal notranslate"><span class="pre">evadventure</span></code> tests (if you had more of them). To only run your utility tests you could do</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>evennia test --settings settings.py evadventure.tests.test_utils
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>evennia test --settings settings.py .evadventure.tests.test_utils
</pre></div>
</div>
<p>If all goes well, you should get an <code class="docutils literal notranslate"><span class="pre">OK</span></code> back. Otherwise you need to check the failure, maybe your return string doesnt quite match what you expected.</p>
<blockquote>
<div><p>Hint: The example unit test code above contains a deliberate error in capitalization. See if you can interpret the error and fix it!</p>
</div></blockquote>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>Its useful for any game dev to know how to effectively test their code. So well try to include a <em>Testing</em> section at the end of each of the implementation lessons to follow. Writing tests for your code is optional but highly recommended. It can feel a little cumbersome or time-consuming at first … but youll thank yourself later.</p>
</div>
</section>
</section>
<section id="summary">
@ -416,18 +403,15 @@ testing <code class="docutils literal notranslate"><span class="pre">get_obj_sta
<a href="Beginner-Tutorial-Rules.html" title="2. Rules and dice rolling"
>next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Part3-Overview.html" title="Part 3: How We Get There (Example Game)"
<a href="Beginner-Tutorial-Part3-Overview.html" title="Part 3: How we get there (example game)"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How We Get There (Example Game)</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part3-Overview.html" >Part 3: How we get there (example game)</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">1. </span>Code structure and Utilities</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -6,7 +6,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Part 4: Using What We Created &#8212; Evennia 2.x documentation</title>
<title>Part 4: Using what we created &#8212; Evennia 2.x documentation</title>
<link rel="stylesheet" href="../../../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
@ -21,8 +21,6 @@
<link rel="prev" title="16. In-game Commands" href="../Part3/Beginner-Tutorial-Commands.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,11 +38,15 @@
<a href="../Part3/Beginner-Tutorial-Commands.html" title="16. In-game Commands"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" accesskey="U">Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Part 4: Using What We Created</a></li>
<li class="nav-item nav-item-this"><a href="">Part 4: Using what we created</a></li>
</ul>
</div>
</div>
<div class="document">
@ -66,7 +68,7 @@
<script>$('#searchbox').show(0);</script>
<h3><a href="../../../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Part 4: Using What We Created</a><ul>
<li><a class="reference internal" href="#">Part 4: Using what we created</a><ul>
<li><a class="reference internal" href="#lessons">Lessons</a></li>
</ul>
</li>
@ -96,40 +98,28 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Part4-Overview.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section class="tex2jax_ignore mathjax_ignore" id="part-4-using-what-we-created">
<h1>Part 4: Using What We Created<a class="headerlink" href="#part-4-using-what-we-created" title="Permalink to this headline"></a></h1>
<h1>Part 4: Using what we created<a class="headerlink" href="#part-4-using-what-we-created" title="Permalink to this headline"></a></h1>
<aside class="sidebar">
<p class="sidebar-title">Beginner Tutorial Parts</p>
<ul class="simple">
<li><p><a class="reference internal" href="../Beginner-Tutorial-Overview.html"><span class="doc std std-doc">Introduction</span></a>
<br>Getting set up.</p></li>
<li><p>Part 1: <a class="reference internal" href="../Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">What We Have</span></a>
<li><p>Part 1: <a class="reference internal" href="../Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">What we have</span></a>
<br>A tour of Evennia and how to use the tools, including an introduction to Python.</p></li>
<li><p>Part 2: <a class="reference internal" href="../Part2/Beginner-Tutorial-Part2-Overview.html"><span class="doc std std-doc">What We Want</span></a>
<br>Planning our tutorial game and what to consider when planning your own.</p></li>
<li><p>Part 3: <a class="reference internal" href="../Part3/Beginner-Tutorial-Part3-Overview.html"><span class="doc std std-doc">How We Get There</span></a>
<br>Getting down to the meat of extending Evennia to make your game.</p></li>
<li><p><em>Part 4: <a class="reference internal" href="#"><span class="doc std std-doc">Using What We Created</span></a></em>
<br>Building a tech-demo and world content to go with our code.</p></li>
<li><p>Part 5: <a class="reference internal" href="../Part5/Beginner-Tutorial-Part5-Overview.html"><span class="doc std std-doc">Showing the World</span></a>
<br>Taking our new game online and letting players try it out.</p></li>
<li><p>Part 2: <a class="reference internal" href="../Part2/Beginner-Tutorial-Part2-Overview.html"><span class="doc std std-doc">What we want</span></a>
<br>Planning our tutorial game and what to think about when planning your own in the future.</p></li>
<li><p>Part 3: <a class="reference internal" href="../Part3/Beginner-Tutorial-Part3-Overview.html"><span class="doc std std-doc">How we get there</span></a>
<br>Getting down to the meat of extending Evennia to make our game</p></li>
<li><p><strong>Part 4: <a class="reference internal" href="#"><span class="doc std std-doc">Using what we created</span></a></strong>
<br>Building a tech-demo and world content to go with our code</p></li>
<li><p>Part 5: <a class="reference internal" href="../Part5/Beginner-Tutorial-Part5-Overview.html"><span class="doc std std-doc">Showing the world</span></a>
<br>Taking our new game online and let players try it out</p></li>
</ul>
</aside>
<p>We now have the code underpinnings of everything we need. We have also tested the various components and has a simple tech-demo to show it all works together. But there is no real coherence to it at this point - we need to actually make a world. In part four we will expand our tech demo into a more full-fledged (if small) game by use of batchcommand and batchcode processors.</p>
@ -166,14 +156,11 @@
<a href="../Part3/Beginner-Tutorial-Commands.html" title="16. In-game Commands"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Part 4: Using What We Created</a></li>
<li class="nav-item nav-item-this"><a href="">Part 4: Using what we created</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -18,11 +18,9 @@
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<link rel="next" title="Adding a Command Prompt" href="../../Howto-Command-Prompt.html" />
<link rel="prev" title="Part 5: Showing the World" href="Beginner-Tutorial-Part5-Overview.html" />
<link rel="prev" title="Part 5: Showing the world" href="Beginner-Tutorial-Part5-Overview.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -37,15 +35,19 @@
<a href="../../Howto-Command-Prompt.html" title="Adding a Command Prompt"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Part5-Overview.html" title="Part 5: Showing the World"
<a href="Beginner-Tutorial-Part5-Overview.html" title="Part 5: Showing the world"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part5-Overview.html" accesskey="U">Part 5: Showing the World</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part5-Overview.html" accesskey="U">Part 5: Showing the world</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">1. </span>Add a simple new web page</a></li>
</ul>
</div>
</div>
<div class="document">
@ -77,7 +79,7 @@
<h4>Previous topic</h4>
<p class="topless"><a href="Beginner-Tutorial-Part5-Overview.html"
title="previous chapter">Part 5: Showing the World</a></p>
title="previous chapter">Part 5: Showing the world</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="../../Howto-Command-Prompt.html"
title="next chapter">Adding a Command Prompt</a></p>
@ -99,18 +101,6 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Add-a-simple-new-web-page.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
@ -119,26 +109,22 @@
<section class="tex2jax_ignore mathjax_ignore" id="add-a-simple-new-web-page">
<h1><span class="section-number">1. </span>Add a simple new web page<a class="headerlink" href="#add-a-simple-new-web-page" title="Permalink to this headline"></a></h1>
<p>Evennia leverages <a class="reference external" href="https://docs.djangoproject.com">Django</a> which is a web development framework.
Huge professional websites are made in Django and there is extensive documentation (and books) on it.
You are encouraged to at least look at the Django basic tutorials. Here we will just give a brief
Huge professional websites are made in Django and there is extensive documentation (and books) on it
. You are encouraged to at least look at the Django basic tutorials. Here we will just give a brief
introduction for how things hang together, to get you started.</p>
<p>We assume you have installed and set up Evennia to run. A webserver and website comes along with the
default Evennia install out of the box. You can view the default website by pointing your web browser
to <code class="docutils literal notranslate"><span class="pre">http://localhost:4001</span></code>. You will see a generic welcome page with some game statistics and a link
to the Evennia web client.</p>
<p>In this tutorial, we will add a new page that you can visit at <code class="docutils literal notranslate"><span class="pre">http://localhost:4001/story</span></code>.</p>
<p>We assume you have installed and set up Evennia to run. A webserver and website comes out of the
box. You can get to that by entering <code class="docutils literal notranslate"><span class="pre">http://localhost:4001</span></code> in your web browser - you should see a
welcome page with some game statistics and a link to the web client. Let us add a new page that you
can get to by going to <code class="docutils literal notranslate"><span class="pre">http://localhost:4001/story</span></code>.</p>
<section id="create-the-view">
<h2><span class="section-number">1.1. </span>Create the view<a class="headerlink" href="#create-the-view" title="Permalink to this headline"></a></h2>
<p>A django “view” is a normal Python function that django calls to render the HTML page you will see
in the web browser. Django can do all sorts of cool stuff to a page by using the view function — like
adding dynamic content or making changes to a page on the fly — but, here, we will just have it spit
back raw HTML.</p>
<p>Open <code class="docutils literal notranslate"><span class="pre">mygame/web/website</span></code> folder and create a new module file there named <code class="docutils literal notranslate"><span class="pre">story.py</span></code>. (You could also
put it in its own folder if you wanted to be neat but, if you do, dont forget to add an empty
<code class="docutils literal notranslate"><span class="pre">__init__.py</span></code> file in the new folfder. Adding the <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code> file tells Python that modules can be
imported from the new folder. For this tutorial, heres what the example contents of your new <code class="docutils literal notranslate"><span class="pre">story.py</span></code>
module should look like:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/web/website/story.py</span>
in the web browser. Here we will just have it spit back the raw html, but Django can do all sorts of
cool stuff with the page in the view, like adding dynamic content or change it on the fly. Open
<code class="docutils literal notranslate"><span class="pre">mygame/web</span></code> folder and add a new module there named <code class="docutils literal notranslate"><span class="pre">story.py</span></code> (you could also put it in its own
folder if you wanted to be neat. Dont forget to add an empty <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code> file if you do, to tell
Python you can import from the new folder). Heres how it looks:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/web/story.py</span>
<span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">render</span>
@ -146,17 +132,16 @@ module should look like:</p>
<span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s2">&quot;story.html&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>The above view takes advantage of a shortcut provided for use by Django: <em>render</em>. The render shortcut
gives the template information from the request. For instance, it might provide the game name, and then
renders it.</p>
<p>This view takes advantage of a shortcut provided to use by Django, <em>render</em>. This shortcut gives the
template some information from the request, for instance, the game name, and then renders it.</p>
</section>
<section id="the-html-page">
<h2><span class="section-number">1.2. </span>The HTML page<a class="headerlink" href="#the-html-page" title="Permalink to this headline"></a></h2>
<p>Next, we need to find the location where Evennia (and Django) looks for HTML files, which are referred
to as <em>templates</em> in Djangos parlance. You can specify such locations in your settings (see the
<code class="docutils literal notranslate"><span class="pre">TEMPLATES</span></code> variable in <code class="docutils literal notranslate"><span class="pre">default_settings.py</span></code> for more info) but, here well use an existing one.</p>
<p>Navigate to <code class="docutils literal notranslate"><span class="pre">mygame/web/templates/website/</span></code> and create a new file there called <code class="docutils literal notranslate"><span class="pre">story.html</span></code>. This
is not an HTML tutorial, so this files content will be simple:</p>
<p>We need to find a place where Evennia (and Django) looks for html files (called <em>templates</em> in
Django parlance). You can specify such places in your settings (see the <code class="docutils literal notranslate"><span class="pre">TEMPLATES</span></code> variable in
<code class="docutils literal notranslate"><span class="pre">default_settings.py</span></code> for more info), but here well use an existing one. Go to
<code class="docutils literal notranslate"><span class="pre">mygame/template/overrides/website/</span></code> and create a page <code class="docutils literal notranslate"><span class="pre">story.html</span></code> there.</p>
<p>This is not a HTML tutorial, so well go simple:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span>{% extends &quot;base.html&quot; %}
{% block content %}
<span class="p">&lt;</span><span class="nt">div</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;row&quot;</span><span class="p">&gt;</span>
@ -170,9 +155,8 @@ is not an HTML tutorial, so this files content will be simple:</p>
{% endblock %}
</pre></div>
</div>
<p>As shown above, Django will allow us to extend our base styles easily because weve used the
<em>render</em> shortcut. If youd prefer to not take advantage of Evennias base styles, you might
instead do something like this:</p>
<p>Since weve used the <em>render</em> shortcut, Django will allow us to extend our base styles easily.</p>
<p>If youd rather not take advantage of Evennias base styles, you can do something like this instead:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span>A story about a tree<span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;</span>
@ -185,41 +169,28 @@ instead do something like this:</p>
</section>
<section id="the-url">
<h2><span class="section-number">1.3. </span>The URL<a class="headerlink" href="#the-url" title="Permalink to this headline"></a></h2>
<p>When you enter the address <code class="docutils literal notranslate"><span class="pre">http://localhost:4001/story</span></code> in your web browser, Django will parse the
stub following the port — here, <code class="docutils literal notranslate"><span class="pre">/story</span></code> — to find out to which page you would like displayed. How
does Django know what HTML file <code class="docutils literal notranslate"><span class="pre">/story</span></code> should link to? You inform Django about what address stub
patterns correspond to what files in the file <code class="docutils literal notranslate"><span class="pre">mygame/web/website/urls.py</span></code>. Open it in your editor now.</p>
<p>Django looks for the variable <code class="docutils literal notranslate"><span class="pre">urlpatterns</span></code> in this file. You will want to add your new <code class="docutils literal notranslate"><span class="pre">story</span></code> pattern
and corresponding path to <code class="docutils literal notranslate"><span class="pre">urlpatterns</span></code> list — which is then, in turn, merged with the default
<code class="docutils literal notranslate"><span class="pre">urlpatterns</span></code>. Heres how it could look:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This reroutes from an URL to a python view-function/class.</span>
<span class="sd">The main web/urls.py includes these routes for all urls (the root of the url)</span>
<span class="sd">so it can reroute to all website pages.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">django.urls</span> <span class="kn">import</span> <span class="n">path</span>
<p>When you enter the address <code class="docutils literal notranslate"><span class="pre">http://localhost:4001/story</span></code> in your web browser, Django will parse that
field to figure out which page you want to go to. You tell it which patterns are relevant in the
file
<a class="reference external" href="https://github.com/evennia/evennia/blob/main/evennia/game_template/web/urls.py">mygame/web/urls.py</a>.
Open it now</p>
<p>Django looks for the variable <code class="docutils literal notranslate"><span class="pre">urlpatterns</span></code> in this file. You want to add your new pattern to the
<code class="docutils literal notranslate"><span class="pre">custom_patterns</span></code> list we have prepared - that is then merged with the default <code class="docutils literal notranslate"><span class="pre">urlpatterns</span></code>. Heres
how it could look:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">web</span> <span class="kn">import</span> <span class="n">story</span>
<span class="kn">from</span> <span class="nn">web.website</span> <span class="kn">import</span> <span class="n">story</span>
<span class="c1"># ...</span>
<span class="kn">from</span> <span class="nn">evennia.web.website.urls</span> <span class="kn">import</span> <span class="n">urlpatterns</span> <span class="k">as</span> <span class="n">evennia_website_urlpatterns</span>
<span class="c1"># add patterns here</span>
<span class="n">urlpatterns</span> <span class="o">=</span> <span class="p">[</span>
<span class="c1"># path(&quot;url-pattern&quot;, imported_python_view),</span>
<span class="n">path</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;story&quot;</span><span class="p">,</span> <span class="n">story</span><span class="o">.</span><span class="n">storypage</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;Story&quot;</span><span class="p">),</span>
<span class="n">custom_patterns</span> <span class="o">=</span> <span class="p">[</span>
<span class="n">url</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;story&#39;</span><span class="p">,</span> <span class="n">story</span><span class="o">.</span><span class="n">storypage</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;Story&#39;</span><span class="p">),</span>
<span class="p">]</span>
<span class="c1"># read by Django</span>
<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">urlpatterns</span> <span class="o">+</span> <span class="n">evennia_website_urlpatterns</span>
</pre></div>
</div>
<p>The above code imports our <code class="docutils literal notranslate"><span class="pre">story.py</span></code> Python view module from where we created it earlier — in
<code class="docutils literal notranslate"><span class="pre">mygame/web/website/</span></code> — and then add the corresponding <code class="docutils literal notranslate"><span class="pre">path</span></code> instance. The first argument to
<code class="docutils literal notranslate"><span class="pre">path</span></code> is the pattern of the URL that we want to find (<code class="docutils literal notranslate"><span class="pre">&quot;story&quot;</span></code>) as a regular expression, and
then the view function from <code class="docutils literal notranslate"><span class="pre">story.py</span></code> that we want to call.</p>
<p>That should be it. Reload Evennia — <code class="docutils literal notranslate"><span class="pre">evennia</span> <span class="pre">reload</span></code> — and you should now be able to navigate
your browser to the <code class="docutils literal notranslate"><span class="pre">http://localhost:4001/story</span></code> location and view your new story page as
rendered by Python!</p>
<p>That is, we import our story view module from where we created it earlier and then create an <code class="docutils literal notranslate"><span class="pre">url</span></code>
instance. The first argument to <code class="docutils literal notranslate"><span class="pre">url</span></code> is the pattern of the url we want to find (<code class="docutils literal notranslate"><span class="pre">&quot;story&quot;</span></code>) (this is
a regular expression if you are familiar with those) and then our view function we want to direct
to.</p>
<p>That should be it. Reload Evennia and you should be able to browse to your new story page!</p>
</section>
</section>
@ -242,18 +213,15 @@ rendered by Python!</p>
<a href="../../Howto-Command-Prompt.html" title="Adding a Command Prompt"
>next</a> |</li>
<li class="right" >
<a href="Beginner-Tutorial-Part5-Overview.html" title="Part 5: Showing the World"
<a href="Beginner-Tutorial-Part5-Overview.html" title="Part 5: Showing the world"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part5-Overview.html" >Part 5: Showing the World</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="Beginner-Tutorial-Part5-Overview.html" >Part 5: Showing the world</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">1. </span>Add a simple new web page</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.

View file

@ -6,7 +6,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Part 5: Showing the World &#8212; Evennia 2.x documentation</title>
<title>Part 5: Showing the world &#8212; Evennia 2.x documentation</title>
<link rel="stylesheet" href="../../../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
@ -21,8 +21,6 @@
<link rel="prev" title="1. Unimplemented" href="../../../Unimplemented.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
@ -40,11 +38,15 @@
<a href="../../../Unimplemented.html" title="1. Unimplemented"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" accesskey="U">Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Part 5: Showing the World</a></li>
<li class="nav-item nav-item-this"><a href="">Part 5: Showing the world</a></li>
</ul>
</div>
</div>
<div class="document">
@ -66,7 +68,7 @@
<script>$('#searchbox').show(0);</script>
<h3><a href="../../../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Part 5: Showing the World</a><ul>
<li><a class="reference internal" href="#">Part 5: Showing the world</a><ul>
<li><a class="reference internal" href="#lessons">Lessons</a></li>
</ul>
</li>
@ -96,40 +98,28 @@
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="Beginner-Tutorial-Part5-Overview.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section class="tex2jax_ignore mathjax_ignore" id="part-5-showing-the-world">
<h1>Part 5: Showing the World<a class="headerlink" href="#part-5-showing-the-world" title="Permalink to this headline"></a></h1>
<h1>Part 5: Showing the world<a class="headerlink" href="#part-5-showing-the-world" title="Permalink to this headline"></a></h1>
<aside class="sidebar">
<p class="sidebar-title">Beginner Tutorial Parts</p>
<ul class="simple">
<li><p><a class="reference internal" href="../Beginner-Tutorial-Overview.html"><span class="doc std std-doc">Introduction</span></a>
<li><p><span class="xref myst">Introduction</span>
<br>Getting set up.</p></li>
<li><p>Part 1: <a class="reference internal" href="../Part1/Beginner-Tutorial-Part1-Overview.html"><span class="doc std std-doc">What We Have</span></a>
<li><p>Part 1: <span class="xref myst">What we have</span>
<br>A tour of Evennia and how to use the tools, including an introduction to Python.</p></li>
<li><p>Part 2: <a class="reference internal" href="../Part2/Beginner-Tutorial-Part2-Overview.html"><span class="doc std std-doc">What We Want</span></a>
<br>Planning our tutorial game and what to consider when planning your own.</p></li>
<li><p>Part 3: <a class="reference internal" href="../Part3/Beginner-Tutorial-Part3-Overview.html"><span class="doc std std-doc">How We Get There</span></a>
<br>Getting down to the meat of extending Evennia to make your game.</p></li>
<li><p>Part 4: <a class="reference internal" href="../Part4/Beginner-Tutorial-Part4-Overview.html"><span class="doc std std-doc">Using What We Created</span></a>
<br>Building a tech-demo and world content to go with our code.</p></li>
<li><p><em>Part 5: <a class="reference internal" href="#"><span class="doc std std-doc">Showing the World</span></a></em>
<br>Taking our new game online and letting players try it out.</p></li>
<li><p>Part 2: <span class="xref myst">What we want</span>
<br>Planning our tutorial game and what to think about when planning your own in the future.</p></li>
<li><p>Part 3: <span class="xref myst">How we get there</span>
<br>Getting down to the meat of extending Evennia to make our game</p></li>
<li><p>Part 4: <span class="xref myst">Using what we created</span>
<br>Building a tech-demo and world content to go with our code</p></li>
<li><p><strong>Part 5: <span class="xref myst">Showing the world</span></strong>
<br>Taking our new game online and let players try it out</p></li>
</ul>
</aside>
<p>You have a working game! In part five we will look at the web-components of Evennia and how to modify them
@ -173,14 +163,11 @@ to bring your game online so you can invite your first players.</p>
<a href="../../../Unimplemented.html" title="1. Unimplemented"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and How-Tos</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../Beginner-Tutorial-Overview.html" >Beginner Tutorial</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Part 5: Showing the World</a></li>
<li class="nav-item nav-item-this"><a href="">Part 5: Showing the world</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.