prev| toc| next
 

4.2 Making a Multi-Action

Over time, many players end up creating several handy little macro commands that provide shortcuts for frequent tasks, or create rooms that have a number of specific, local commands. Rather than creating a separate action for each command (an approach that quickly leads to dbase bloat and eats up your quota), you can combine a number of commands in a single action. The basic technique is to give the action an alias name for each command, store MPI strings in properties with the same names as the aliases, and use the command name typed by the user to determine which property should be executed.

The following example creates a multi-action that lets you determine the dbref of something in the same room, enter or review a page of `to do' notes, and remotely lock or unlock the door into your home. First, create the action attached to your character, and lock it to a condition that always fails. Since the action is attached to you, no one else should be able to use it... Nonetheless, it would be a good idea to secure the exit by linking it to something, such as a do-nothing program.

====================================
> @act ref;note;notes;lockhome;unlockhome = me
  Action created with number 9456 and attached.
> @lock ref = me&!me
  Locked.
> @link ref = $nothing
  Linked to gen-nothing.muf(#363FLM2).
====================================

The lock will fail unless the user is and is not you... it will always fail. Now, set the action's @fail with an MPI string that will cause other MPI strings stored in properties on the object to be executed.

====================================
> @fail ref = {exec:{&cmd}}
  Message set.
====================================

{&cmd} is a variable... it holds whatever command name the user typed. If you used the action by typing `ref', then the string `ref' would be substituted for {&cmd} when the @fail is parsed; if you used the the action by typing `notes', then `notes' would be substituted for {&cmd}.

{exec} evaluates the property following it, executing any MPI contained in it, and returning any resulting strings to the user. So, typing `notes' would cause the `notes' property on the object to be evaluated: {&cmd} would be replaced by `notes', and {exec} would use this value to determine which property it should evaluate.

Now, set a property for each alias, containing MPI that performs a function. One of the simplest ways to do this, is to force yourself to use a command. In order to do so, you need to be set X(forcible) and force_locked to yourself.

====================================
> @set me = X
  Flag set.
> @flock me = me
  Force lock set.

> @set ref =ref:{ref:{&arg}}
  Property set.
> @set note =note:{force:me,lsedit notes=notes}
  Property set.
> @desc note ={list:notes}
  Description set.
> @set notes =notes:{force:me,look notes}
  Property set.
> @set lockhome =lockhome:{force:me,@lock #17212=me&!me}
  Property set.
> @set unlockhome =unlockhome:{force:me,@unlock #17212}
  Property set.
====================================

The one action can now be used to do several different things. Typing `ref here' would show the dbref of the room you are in ({&arg}, like {&cmd}, a variable: it holds whatever was typed following the command name. If you typed `ref here', the &arg variable would hold the string `here'). Typing `note' would force you to use lsedit to edit your page of notes. Typing `notes' would force you to look at the notes: the list would be printed on your screen. Typing `lockhome' would force you to lock the exit into your home, specifying it by dbref so that it doesn't matter where on the MUCK you are located. Typing `unlockhome' would unlock the exit in the same way.

(Notice that several of the actions world by `forcing' you to do something. This is an easy way to make little macro commands. However, be aware that in order for it to work, you must be set 'Xforcible', and you must be 'force_locked' to yourself. So, do the following as well:

====================================
> @set me=X
  Flag set.
> @flock me=me
  Locked.
====================================
)

A single multi-action like this can be extended indefinitely, by adding aliases and a corresponding prop. To add a `look at my watch and check the time' function, you could rename the action and set a `watch' property that uses simple MPI.

====================================
> @name ref = ref;note;notes;lockhome;unlockhome;watch
  Name set.
> @set watch = watch:You glance at your watch. The time is {time}.
  Property set.

> watch
  You glance at your watch. The time is 14:18:46.
====================================

prev| toc| top| next