Games-Axmud
view release on metacpan or search on metacpan
share/docs/tutorial/ch04.html view on Meta::CPAN
<pre><code> The door opens and an angry orc steps out from behind it!
</code></pre>
<p>In Axbasic, the WAITTRIG statement (short for <em>wait for a trigger</em>) creates a temporary trigger and pauses execution of the script until the trigger fires. WAITTRIG is another example of a statement that won't work if the script isn't run a...
<p>The pattern we'll use is the word <strong>opens</strong>. The trigger fires when the world sends any text containing that word.</p>
<pre><code> SEND "knock door"
WAITTRIG "opens"
SEND "kill orc"
END
</code></pre>
<p>Of course, there's a small possibility that the orc won't open the door at all. Rather than allowing your script to wait indefinitely, you can specify a timeout in seconds.</p>
<pre><code> WAITTRIG "opens", 60
</code></pre>
<p>If sixty seconds pass and no-one has opened the door, execution of the script resumes. If the trigger fires before that time, execution of the script resumes immediately.</p>
<p>The comma between "opens" and 60 is compulsory. If you forget it, you'll see an error message.</p>
<h2><a name="4.6">4.6 Patterns</a></h2>
<p>By the way, when we talk about a pattern, we are actually talking about a <em>regular expression</em> (also called a <em>regex</em>). Regular expressions are an extremely powerful and flexible way of matching text.</p>
<p>All Axbasic script writers need to know at the least the basics of regular expressions. You'll find a handy (and short) tutorial in the <a href="../guide/index.html">Axmud Guide</a>.</p>
<h2><a name="4.7">4.7 A practical example</a></h2>
<p>Let's put it all together with a script that solves a simple quest.</p>
<p>If you like, you can read the example below to see how it works, or you can try to the script yourself, comparing it against the example when you're ready.</p>
<p>The solution to the quest is:</p>
<ul>
<li>Go north, east, then north again</li>
<li>Attack the orc</li>
<li>Wait for the fight to finish</li>
<li>Play a suitable sound effect, and wait enough time for it to finish</li>
<li>Loot the corpse</li>
<li>Unlock the door using the looted key</li>
<li>Grab the treasure, and go back the way you came</li>
<li>Display a confirmation message</li>
</ul>
<p>And here is the finished script! Don't forget that it needs to be run as a task.</p>
<pre><code> ! Solve the orc treasure quest
MOVE "north"
MOVE "east"
MOVE "north"
SEND "kill orc"
! Wait for 'the orc is dead' message
! Use a timeout, in case the orc runs away
WAITTRIG "dead", 60
! Orc is either dead or not here any more
CLIENT "playsoundeffect cheer"
PAUSE 5
SEND "loot corpse"
SEND "unlock door with key"
MOVE "north"
SEND "get treasure"
! Go back the way you came
MOVE "south"
MOVE "south"
MOVE "west"
MOVE "south"
PRINT "Finished!"
END
</code></pre>
<h2><a name="4.8">4.8 Missions</a></h2>
<p>By the way, a script as simple as the one above can just as easily be written as a <em>mission</em>.</p>
<p>Axmud missions are scripts that require absolutely no programming knowledge. See the <a href="../guide/index.html">Axmud Guide</a> for more details about how to write them.</p>
<h2><a name="4.9">4.9 More waiting statements</a></h2>
<p>WAITTRIG waits for a trigger to fire, but there are a number of statements that wait for something else. Many of them depend on a properly-configured Status task that's running right now.</p>
<p>The Status task recognises four states of being for the current character: <strong>"alive"</strong>, <strong>"sleep"</strong>, <strong>"pass_out"</strong> and <strong>"dead"</strong>. Whenever the character is not asleep, passed out or dead, they'...
<p>WAITALIVE, WAITSLEEP, WAITPASSOUT and WAITDEAD pause the script until the character's status changes. (If the character is already alive, sleep, passed out or dead, the script resumes immediately).</p>
<p>Each of those statements can be used with a timeout, measured in seconds.</p>
<pre><code> ! Wait for the character to fall asleep
WAITSLEEP
! Wait, but give up after 60 seconds
WAITSLEEP 60
</code></pre>
<p>Most worlds keep track of the character's health points. You can wait for your character's health to recover to a certain minimum level before resuming execution.</p>
<pre><code> ! Wait for HP to recover to at least 50% of maximum
WAITHP 50
</code></pre>
<p>At worlds that implement them, you can wait for energy points, guild points, mana (magic) points and/or social points with WAITEP, WAITGP, WAITMP and WAITSP. You can wait for the character's experience points (XP) with the WAITXP, WAITNEXTXP and W...
<p>All of those statements can be used with a timeout, if you want.</p>
<pre><code> ! Wait to recover, but don't wait
! more than five minutes
WAITHP 50, 300
</code></pre>
<p>When your character is moving around the world, you can wait for them to arrive using a WAITARRIVE statement. (This statement relies on the Locator task.)</p>
<p>Here are two examples, the second of which uses a timeout.</p>
<pre><code> MOVE "north"
WAITARRIVE
MOVE "squeeze through curtains"
WAITARRIVE 5
</code></pre>
<p>WAITSCRIPT starts a new Axbasic script, and waits for it to finish running. The next script is run as a task.</p>
<pre><code> WAITSCRIPT "otherscript"
</code></pre>
<p>WAITTASK starts a new task, and waits for it to stop running.</p>
<pre><code> WAITTASK "compass"
</code></pre>
<p>Some tasks are designed to be <em>active</em> or <em>disactivated</em>. If you've written such a task, you can pause the Axbasic script until the task is active or disactivated.</p>
<pre><code> WAITACTIVE "mytask"
WAITNOTACTIVE "mytask"
</code></pre>
<hr>
<p><a href="ch03.html">Previous</a> <a href="index.html">Index</a> <a href="ch05.html">Next</a></p>
</body>
</html>
( run in 1.372 second using v1.01-cache-2.11-cpan-39bf76dae61 )