7.2. Echoing and Sending Text

As mentioned in the previous section, the $world->echo function is used to print (or echo) text to the MUD window, without sending it to the World. It works like the print built-in function: it accepts any number of arguments, and echoes all of them, sequentially.

For example, $world->echo("Variable var contains ", $var, ".\n") would print the first string, followed by the contents of $var, followed by a period and a new line. Of course, you could do all that in a single string using variable interpolation.

A variant of $world->echo is $world->echonl. The difference is that $world->echonl always prints automatically a newline after each argument. This is just a shorthand to make some things simpler and possibly more readable.

Similar to $world->echo is the $world->send function. This function sends something to the MUD. For example, $world->send("who") will have the same effect as if you had typed who in the command entry box and pressed ENTER. Note that you do not have to add a newline to the end of the line to send, because send automatically sends a newline after each argument (since commands must be terminated by a newline for the MUD to recognize them).

It is possible to pass several arguments to send. If you do so, each argument will be sent as a separate command. For example, $world->send("who", "look") will first send a who to the MUD, and then a look, just as if you had typed each of these commands in order.

All the examples given above did nothing that could not be done without Perl, and using send for that was actually less efficient that typing the commands directly. However, when combined with variables and/or control flow structures, send can actually be quite useful.

7.2.1. Paths and Speed-Walking

A useful feature of some MUD clients, which KildClient implements, is the support for speed-walking. This feature allows you to define paths to go directly from one place to another without having to type a lot of movement commands.

For example, suppose that to go to some place from a fixed point (such as the center of a town) you need to take the following directions: s s s e e s e e e e n nw n. This is often written in a more compact way as 3s 2e s 4e n nw n. KildClient allows you to send to the MUD all the 13 required commands in a single command. To do that, use the $world->path function. For example, if you enter /$world->path("3s2es4en{nw}n") in the command line, 13 commands will be sent to the MUD: exactly the 13 that form the path defined above.

Note the syntax: the movement commands are defined one after another, optionally prefixed by a number, which determines how many times that command will be sent. So 3s means send s three times. If there is no number, the command is sent only once.

Note also that the command to move to the north-west is enclosed in braces: {nw}. This is because if the $world->path function sees nw, it will think you want to move to the north than to the west. Enclosing it in braces causes $world->path to see that as a single command. Should you need to move several times to the northwest, you can add a number before: 4{nw} will send nw four times.

Naturally, you can include any command that is not a single letter in braces to force $world->path to see it as a command. It is likely that some paths will need something like {open door} in the middle.

Of course, simply entering paths in the command line is not that useful. But you can store the path in a variable, and then just call $world->path($stored_path). Just add a line that defines the variable to you script file (see Section 7.1, “The Basics”), and you will be able to use the variabled anywhere.

Alternatively, you can define an alias (see Chapter 9, Aliases) or a macro (see Chapter 10, Macros) to execute your path even faster. The easypath plugin does that, see section Section 13.3.1, “easypath”.