Games-Axmud

 view release on metacpan or  search on metacpan

share/docs/tutorial/ch04.mkd  view on Meta::CPAN

The comma between "opens" and 60 is compulsory. If you forget it, you'll see an error message.

##<a name="4.6">4.6 Patterns</a>

By the way, when we talk about a pattern, we are actually talking about a *regular expression* (also called a *regex*). Regular expressions are an extremely powerful and flexible way of matching text.

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 [Axmud Guide](../guide/index.html).

##<a name="4.7">4.7 A practical example</a>

Let's put it all together with a script that solves a simple quest.

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.

The solution to the quest is:

* Go north, east, then north again
* Attack the orc
* Wait for the fight to finish
* Play a suitable sound effect, and wait enough time for it to finish
* Loot the corpse
* Unlock the door using the looted key
* Grab the treasure, and go back the way you came
* Display a confirmation message

And here is the finished script! Don't forget that it needs to be run as a task.

        ! 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

##<a name="4.8">4.8 Missions</a>

By the way, a script as simple as the one above can just as easily be written as a *mission*.

Axmud missions are scripts that require absolutely no programming knowledge. See the [Axmud Guide](../guide/index.html) for more details about how to write them.

##<a name="4.9">4.9 More waiting statements</a>

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.

The Status task recognises four states of being for the current character: **"alive"**, **"sleep"**, **"pass_out"** and **"dead"**. Whenever the character is not asleep, passed out or dead, they're considered alive.

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).

Each of those statements can be used with a timeout, measured in seconds.

        ! Wait for the character to fall asleep
        WAITSLEEP
        ! Wait, but give up after 60 seconds
        WAITSLEEP 60

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.

        ! Wait for HP to recover to at least 50% of maximum
        WAITHP 50

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 WAIT...

All of those statements can be used with a timeout, if you want.

        ! Wait to recover, but don't wait
        ! more than five minutes
        WAITHP 50, 300

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.)

Here are two examples, the second of which uses a timeout.

        MOVE "north"
        WAITARRIVE

        MOVE "squeeze through curtains"
        WAITARRIVE 5

WAITSCRIPT starts a new Axbasic script, and waits for it to finish running. The next script is run as a task.

        WAITSCRIPT "otherscript"

WAITTASK starts a new task, and waits for it to stop running.

        WAITTASK "compass"

Some tasks are designed to be *active* or *disactivated*. If you've written such a task, you can pause the Axbasic script until the task is active or disactivated.

        WAITACTIVE "mytask"
        WAITNOTACTIVE "mytask"

---

[Previous](ch03.html) [Index](index.html) [Next](ch05.html)



( run in 1.615 second using v1.01-cache-2.11-cpan-39bf76dae61 )