<h2>A first example with a first character<aclass="headerlink"href="#a-first-example-with-a-first-character"title="Permalink to this headline">¶</a></h2>
<p>This will create a merchant in the room where you currently are. It doesn’t have anything, like a
description, you can decorate it a bit if you like.</p>
<p>As said above, the in-game Python system consists in linking objects with arbitrary code. This code
will be executed in some circumstances. Here, the circumstance is “when someone says something in
the same room”, and might be more specific like “when someone says hello”. We’ll decide what code
to run (we’ll actually type the code in-game). Using the vocabulary of the in-game Python system,
we’ll create a callback: a callback is just a set of lines of code that will run under some
conditions.</p>
<p>You can have an overview of every “conditions” in which callbacks can be created using the <codeclass="docutils literal notranslate"><spanclass="pre">@call</span></code>
command (short for <codeclass="docutils literal notranslate"><spanclass="pre">@callback</span></code>). You need to give it an object as argument. Here for instance, we
<p>You should see a table with three columns, showing the list of events existing on our newly-created
merchant. There are quite a lot of them, as it is, althougn no line of code has been set yet. For
our system, you might be more interested by the line describing the <codeclass="docutils literal notranslate"><spanclass="pre">say</span></code> event:</p>
<p>We’ll create a callback on the <codeclass="docutils literal notranslate"><spanclass="pre">say</span></code> event, called when we say “hello” in the merchant’s room:</p>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">@call</span></code> is the command name, <codeclass="docutils literal notranslate"><spanclass="pre">/add</span></code> is a switch. You can read the help of the command to get the
help of available switches and a brief overview of syntax.</p></li>
<li><p>The event’s name. Here, it’s “say”. The available events are displayed when you use <codeclass="docutils literal notranslate"><spanclass="pre">@call</span></code>
without switch.</p></li>
<li><p>After a space, we enter the conditions in which this callback should be called. Here, the
conditions represent what the other character should say. We enter “hello”. Meaning that if
someone says something containing “hello” in the room, the callback we are now creating will be
<li><p>We can set callbacks to fire when specific keywords are present in the phrase by putting them as
additional parameters. Here we have set this parameter to “hello”. We can have several keywords
separated by a comma (we’ll see this in more details later).</p></li>
<li><p>We have three default variables we can use in this callback: <codeclass="docutils literal notranslate"><spanclass="pre">speaker</span></code> which contains the
character who speaks, <codeclass="docutils literal notranslate"><spanclass="pre">character</span></code> which contains the character who’s modified by the in-game Python
system (here, or merchant), and <codeclass="docutils literal notranslate"><spanclass="pre">message</span></code> which contains the spoken phrase.</p></li>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="n">character</span><spanclass="o">.</span><spanclass="n">location</span><spanclass="o">.</span><spanclass="n">msg_contents</span><spanclass="p">(</span><spanclass="s2">"</span><spanclass="si">{character}</span><spanclass="s2"> shrugs and says: 'well, yes, hello to you!'"</span><spanclass="p">,</span>
<p>Once you have entered this line, you can type <codeclass="docutils literal notranslate"><spanclass="pre">:wq</span></code> to save the editor and quit it.</p>
<p>And now if you use the “say” command with a message containing “hello”:</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="n">You</span><spanclass="n">say</span><spanclass="p">,</span><spanclass="s2">"Hello sir merchant!"</span>
<spanclass="n">a</span><spanclass="n">merchant</span><spanclass="p">(</span><spanclass="c1">#3) shrugs and says: 'well, yes, hello to you!'</span>
</pre></div>
</div>
<p>If you say something that doesn’t contain “hello”, our callback won’t execute.</p>
<li><p>The callback is then executed as normal Python code. Here we have called the <codeclass="docutils literal notranslate"><spanclass="pre">msg_contents</span></code>
method on the character’s location (probably a room) to display a message to the entire room. We
have also used mapping to easily display the character’s name. This is not specific to the in-game
Python system. If you feel overwhelmed by the code we’ve used, just shorten it and use something
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="n">speaker</span><spanclass="o">.</span><spanclass="n">msg</span><spanclass="p">(</span><spanclass="s2">"You have said something to me."</span><spanclass="p">)</span>
<h2>The same callback for several keywords<aclass="headerlink"href="#the-same-callback-for-several-keywords"title="Permalink to this headline">¶</a></h2>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="n">character</span><spanclass="o">.</span><spanclass="n">location</span><spanclass="o">.</span><spanclass="n">msg_contents</span><spanclass="p">(</span><spanclass="s2">"</span><spanclass="si">{character}</span><spanclass="s2"> says: 'Ho well, trade's fine as long as roads are</span>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="n">You</span><spanclass="n">say</span><spanclass="p">,</span><spanclass="s2">"and how is your trade going?"</span>
<spanclass="n">a</span><spanclass="n">merchant</span><spanclass="p">(</span><spanclass="c1">#3) says: 'Ho well, trade's fine as long as roads are safe.'</span>
</pre></div>
</div>
<p>We can set several keywords when adding the callback. We just need to separate them with commas.</p>
<spanclass="n">character</span><spanclass="o">.</span><spanclass="n">location</span><spanclass="o">.</span><spanclass="n">msg_contents</span><spanclass="p">(</span><spanclass="s2">"</span><spanclass="si">{character}</span><spanclass="s2"> scratches his head, considering."</span><spanclass="p">,</span>
<spanclass="n">character</span><spanclass="o">.</span><spanclass="n">location</span><spanclass="o">.</span><spanclass="n">msg_contents</span><spanclass="p">(</span><spanclass="s2">"</span><spanclass="si">{character}</span><spanclass="s2"> whispers: 'Aye, saw some of them, north from here. No</span>
<spanclass="n">speaker</span><spanclass="o">.</span><spanclass="n">msg</span><spanclass="p">(</span><spanclass="s2">"</span><spanclass="si">{character}</span><spanclass="s2"> looks at you more</span>
<spanclass="n">speaker</span><spanclass="o">.</span><spanclass="n">msg</span><spanclass="p">(</span><spanclass="s2">"</span><spanclass="si">{character}</span><spanclass="s2"> continues in a low voice: 'Ain't my place to say, but if you need to find</span>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="n">You</span><spanclass="n">say</span><spanclass="p">,</span><spanclass="s2">"have you seen bandits?"</span>
<spanclass="n">a</span><spanclass="n">merchant</span><spanclass="p">(</span><spanclass="c1">#3) scratches his head, considering.</span>
<spanclass="n">a</span><spanclass="n">merchant</span><spanclass="p">(</span><spanclass="c1">#3) whispers: 'Aye, saw some of them, north from here. No trouble o' mine, but...'</span>
<spanclass="n">a</span><spanclass="n">merchant</span><spanclass="p">(</span><spanclass="c1">#3) looks at you more closely.</span>
<spanclass="n">a</span><spanclass="n">merchant</span><spanclass="p">(</span><spanclass="c1">#3) continues in a low voice: 'Ain't my place to say, but if you need to find 'em,</span>
<spanclass="n">they</span><spanclass="s1">'re encamped some distance away from the road, I guess near a cave or something.'</span><spanclass="o">.</span>