<h1>Batch Command Processor<aclass="headerlink"href="#batch-command-processor"title="Permalink to this headline">¶</a></h1>
<p>For an introduction and motivation to using batch processors, see <aclass="reference internal"href="Batch-Processors.html"><spanclass="doc std std-doc">here</span></a>. This
page describes the Batch-<em>command</em> processor. The Batch-<em>code</em> one is covered [here](Batch-Code-
Processor).</p>
<p>The batch-command processor is a superuser-only function, invoked by</p>
<p>Where <codeclass="docutils literal notranslate"><spanclass="pre">path.to.batchcmdfile</span></code> is the path to a <em>batch-command file</em> with the “<codeclass="docutils literal notranslate"><spanclass="pre">.ev</span></code>” file ending.
This path is given like a python path relative to a folder you define to hold your batch files, set
with <codeclass="docutils literal notranslate"><spanclass="pre">BATCH_IMPORT_PATH</span></code> in your settings. Default folder is (assuming your game is in the <codeclass="docutils literal notranslate"><spanclass="pre">mygame</span></code>
folder) <codeclass="docutils literal notranslate"><spanclass="pre">mygame/world</span></code>. So if you want to run the example batch file in
<codeclass="docutils literal notranslate"><spanclass="pre">mygame/world/batch_cmds.ev</span></code>, you could use</p>
<p>A batch-command file contains a list of Evennia in-game commands separated by comments. The
processor will run the batch file from beginning to end. Note that <em>it will not stop if commands in
it fail</em> (there is no universal way for the processor to know what a failure looks like for all
different commands). So keep a close watch on the output, or use <em>Interactive mode</em> (see below) to
run the file in a more controlled, gradual manner.</p>
<sectionid="the-batch-file">
<h2>The batch file<aclass="headerlink"href="#the-batch-file"title="Permalink to this headline">¶</a></h2>
<p>The batch file is a simple plain-text file containing Evennia commands. Just like you would write
them in-game, except you have more freedom with line breaks.</p>
<p>Here are the rules of syntax of an <codeclass="docutils literal notranslate"><spanclass="pre">*.ev</span></code> file. You’ll find it’s really, really simple:</p>
<ulclass="simple">
<li><p>All lines having the <codeclass="docutils literal notranslate"><spanclass="pre">#</span></code> (hash)-symbol <em>as the first one on the line</em> are considered <em>comments</em>. All non-comment lines are treated as a command and/or their arguments.</p></li>
<li><p>Comment lines have an actual function – they mark the <em>end of the previous command definition</em>. So never put two commands directly after one another in the file - separate them with a comment, or the second of the two will be considered an argument to the first one. Besides, using plenty of comments is good practice anyway.</p></li>
<li><p>A line that starts with the word <codeclass="docutils literal notranslate"><spanclass="pre">#INSERT</span></code> is a comment line but also signifies a special instruction. The syntax is <codeclass="docutils literal notranslate"><spanclass="pre">#INSERT</span><spanclass="pre"><path.batchfile></span></code> and tries to import a given batch-cmd file into this one. The inserted batch file (file ending <codeclass="docutils literal notranslate"><spanclass="pre">.ev</span></code>) will run normally from the point of the <codeclass="docutils literal notranslate"><spanclass="pre">#INSERT</span></code> instruction.</p></li>
<li><p>Extra whitespace in a command definition is <em>ignored</em>. - A completely empty line translates in to a line break in texts. Two empty lines thus means a new paragraph (this is obviously only relevant for commands accepting such formatting, such as the <codeclass="docutils literal notranslate"><spanclass="pre">@desc</span></code> command).</p></li>
<li><p>The very last command in the file is not required to end with a comment.</p></li>
<li><p>You <em>cannot</em> nest another <codeclass="docutils literal notranslate"><spanclass="pre">batchcommand</span></code> statement into your batch file. If you want to link many batch-files together, use the <codeclass="docutils literal notranslate"><spanclass="pre">#INSERT</span></code> batch instruction instead. You also cannot launch the <codeclass="docutils literal notranslate"><spanclass="pre">batchcode</span></code> command from your batch file, the two batch processors are not compatible.</p></li>
</ul>
<p>Below is a version of the example file found in <codeclass="docutils literal notranslate"><spanclass="pre">evennia/contrib/tutorial_examples/batch_cmds.ev</span></code>.</p>
<p>A button will be created, described and dropped in Limbo. All commands will be executed by the user calling the command.</p>
<blockquote>
<div><p>Note that if you interact with the button, you might find that its description changes, loosing your custom-set description above. This is just the way this particular object works.</p>
</div></blockquote>
</section>
<sectionid="interactive-mode">
<h2>Interactive mode<aclass="headerlink"href="#interactive-mode"title="Permalink to this headline">¶</a></h2>
<p>Interactive mode allows you to more step-wise control over how the batch file is executed. This is useful for debugging and also if you have a large batch file and is only updating a small part of it – running the entire file again would be a waste of time (and in the case of <codeclass="docutils literal notranslate"><spanclass="pre">create</span></code>-ing objects you would to end up with multiple copies of same-named objects, for example). Use <codeclass="docutils literal notranslate"><spanclass="pre">batchcommand</span></code> with the <codeclass="docutils literal notranslate"><spanclass="pre">/interactive</span></code> flag to enter interactive mode.</p>
<divclass="highlight-none notranslate"><divclass="highlight"><pre><span></span>01/04: @create button:tutorial_examples.red_button.RedButton (hh for help)
</pre></div>
</div>
<p>This shows that you are on the <codeclass="docutils literal notranslate"><spanclass="pre">@create</span></code> command, the first out of only four commands in this batch file. Observe that the command <codeclass="docutils literal notranslate"><spanclass="pre">@create</span></code> has <em>not</em> been actually processed at this point!</p>
<p>To take a look at the full command you are about to run, use <codeclass="docutils literal notranslate"><spanclass="pre">ll</span></code> (a batch-processor version of
<codeclass="docutils literal notranslate"><spanclass="pre">look</span></code>). Use <codeclass="docutils literal notranslate"><spanclass="pre">pp</span></code> to actually process the current command (this will actually <codeclass="docutils literal notranslate"><spanclass="pre">@create</span></code> the button) – and make sure it worked as planned. Use <codeclass="docutils literal notranslate"><spanclass="pre">nn</span></code> (next) to go to the next command. Use <codeclass="docutils literal notranslate"><spanclass="pre">hh</span></code> for a list of commands.</p>
<p>If there are errors, fix them in the batch file, then use <codeclass="docutils literal notranslate"><spanclass="pre">rr</span></code> to reload the file. You will still be at the same command and can rerun it easily with <codeclass="docutils literal notranslate"><spanclass="pre">pp</span></code> as needed. This makes for a simple debug cycle. It also allows you to rerun individual troublesome commands - as mentioned, in a large batch file this can be very useful. Do note that in many cases, commands depend on the previous ones (e.g. if <codeclass="docutils literal notranslate"><spanclass="pre">create</span></code> in the example above had failed, the following commands would have had nothing to operate on).</p>
<p>Use <codeclass="docutils literal notranslate"><spanclass="pre">nn</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">bb</span></code> (next and back) to step through the file; e.g. <codeclass="docutils literal notranslate"><spanclass="pre">nn</span><spanclass="pre">12</span></code> will jump 12 steps forward (without processing any command in between). All normal commands of Evennia should work too while working in interactive mode.</p>
</section>
<sectionid="limitations-and-caveats">
<h2>Limitations and Caveats<aclass="headerlink"href="#limitations-and-caveats"title="Permalink to this headline">¶</a></h2>
<p>The main issue with batch-command builds is that when you run a batch-command script you (<em>you</em>, as in your character) are actually moving around in the game creating and building rooms in sequence, just as if you had been entering those commands manually, one by one.</p>
<p>You have to take this into account when creating the file, so that you can ‘walk’ (or teleport) to the right places in order. It also means that you may be affected by the things you create, such as mobs attacking you or traps immediately hurting you.</p>
<p>If you know that your rooms and objects are going to be deployed via a batch-command script, you can plan for this beforehand. To help with this, you can use the fact that the non-persistent Attribute <codeclass="docutils literal notranslate"><spanclass="pre">batch_batchmode</span></code> is <em>only</em> set while the batch-processor is running. Here’s an example of how to use it:</p>
<p>So we skip the hook if we are currently building the room. This can work for anything, including making sure mobs don’t start attacking you while you are creating them.</p>
<p>There are other strategies, such as adding an on/off switch to actiive objects and make sure it’s always set to <em>off</em> upon creation.</p>
<h2>Editor highlighting for .ev files<aclass="headerlink"href="#editor-highlighting-for-ev-files"title="Permalink to this headline">¶</a></h2>
<ulclass="simple">
<li><p><aclass="reference external"href="https://www.gnu.org/software/emacs/">GNU Emacs</a> users might find it interesting to use emacs’<em>evennia mode</em>. This is an Emacs major mode found in <codeclass="docutils literal notranslate"><spanclass="pre">evennia/utils/evennia-mode.el</span></code>. It offers correct syntax highlighting and indentation with <codeclass="docutils literal notranslate"><spanclass="pre"><tab></span></code> when editing <codeclass="docutils literal notranslate"><spanclass="pre">.ev</span></code> files in Emacs. See the header of that file for installation instructions.</p></li>
<li><p><aclass="reference external"href="https://www.vim.org/">VIM</a> users can use amfl’s <aclass="reference external"href="https://github.com/amfl/vim-evennia">vim-evennia</a> mode instead, see its readme for install instructions.</p></li>