MUSHCODE for Beginners
Project #1 - The Simple Description Changer
Another Tutorial of Questionable Merit from Kirra (Dee Dreslough). Public Domain - feel free to alter and redistribute
Am I ready for This? This tutorial assumes that you know how to say things on a
mush, move around a mush, create simple objects on a MUSH, and perhaps have done some building, but not much more.
But I do know MUSH. I'm a Psychocoder! Then you will probably weep to read this,
as my code is never elegant or efficient, but it's straightforward and it gets people there. :-)
MUSH code is a relatively simple type of coding language. It allows you to load sets of actions into Attributes
(Variables) on objects, players, rooms or exits, and then run them. Functions, special tools that MUSH uses, allow
you to compare, change, rearrange and perform all kinds of things on Attributes. You'll start with very simple,
direct actions - like making a simple description changer for yourself. Over time, you'll learn to add different
functions and before you know it, you'll be writing things that are more and more complex. It's a gradual process!
It's like math: you have to know how to add and subtract before you can do Calculus. Just enjoy the ride.
Things you type are in Preformatted Red.
Things the MUSH will say to you, or things you'll see after typing something are marked in Preformatted
Let's get started! Mastering the Attribute
Attriubtes are lines of code, data, or numbers that you can put on yourself or your MUSH objects. To set an
attribute, you type:
&<name of attribute> <object> = <value>
Like: &Title me=King of Beers
To show how this works, let's make ourselves a dog.
You should get a message:
You can examine the dog with ex Dog to see that the attribute is there.
You see nothing special.
Owner: You Key: *Unlocked* Pennies: 10
In the case of the attributes above (Position) it's just strings of text. It doesn't do anything in particular.
What good is that? Well, try this:
@desc dog=You see a black labrador. He is [v(position)].
You see a black labrador. He is Sitting.
You've stored his position on him - and with code we'll write later on, you can change the value of that Attribute
(ie: Make it say something else), which in turn will change his description! Instead of re-writing his entire
description, you can change it with the Attribute. More on this for your character desc changer later.
What about that weird V and all that [( stuff in the [v(position)] thing?
[v( )] is a function - your first function! Congratulations! Let's define
It means, in English: 'Go get the value of the attribute POSITION and use that instead of [v(position)]'
Basically, whatever's inside Position will be used in the desc, instead of [v(position)]. So, if you set Position
to 'Standing and barking loudly', with the command:
&Position dog=Standing and barking loudly
(type this now)
You see a black labrador. He is Standing and barking loudly.
It takes the set of characters [v(position)] and swaps in whatever you put in the POSITION Attribute.
If you feel shaky on this concept, you can try setting Position a few more times.
&position Dog= Doing "the Pigeon Dance" with Bert
&position Dog= the Head of the United Nations and flies a black helicopter
&position Dog= Sleeping on the rug
Okay..you should be pretty comfortable with setting the Position attribute on the poor dog by now.
Typing in &position Dog= is a Hassle! Time for $Commands
The makers of MUSH agreed wholeheartedly. So, they invented a way for you to make your own commands in the MUSH
with $Commands. You can make a shorty-cut for &position Dog=. Here's how it works (Type this in to add
it to your dog):
&setposition Dog=$Position dog=*:&Position Dog=%0
You'll recognize that &setposition Dog= is the command to set an Attribute on the dog - just like
we used ot set a position, and if you're really on your game today, you'll notice that &Position Dog=%0
is similar to &position dog=Sleeping on the rug - it's just got some weird characters: %0.
You see nothing special.
Owner: You Key: *Unlocked* Pennies: 10
SETPOSITION:$Position dog=*:&Position Dog=%0
Basically, we've set another Attribute on the dog, but this time, it's a whole command, and not just a string
like 'Sitting'. THIS IS MUSHCODE - Your first command!
If you type:
Position dog=sitting in a Porsche
and then type
You see a black labrador. He is sitting in a Porsche.
Wow! What did I just do?
You created a User defined command "$Position Dog=". Anyone in the same room with the dog who
types Position Dog=<text> will reset the dog's position. Typing Position Dog= isn't much easier than typing
&Position Dog=, but I wanted to make the command clear. You could use $Pos as your command word:
Then when you typed Pos Sitting it would reset position on the
dog. That's shorter and easier to use, but harder to remember.
Exact Structure for Setting User Defined Commands:
&<Attribute Name> <Object>=$<command Word and any *'s>: <Action to do>
Let's take a close look at the stuff after the = sign.
$<command Word and any *'s>: <Action
In the case of our dog, it's
$Pos *:&Position Dog=%0
Everything between the $ and the : is
the command string. Whenever you type:
pos <something> on a line by itself when you're in the same room with the
Dog object, the MUSH will put <Something> into the POSITION variable on the Dog and change it's desc.
What's the * for? Wildcards
* is a WildCard. Wildcards let the $Command know that it's waiting for
the user to give it information along with the command words. In the case of our Dog example, Pos <Something>,
The Something 'Goes Into' the *.
If you just typed Pos (with no word after it), you'd get this from the MUSH:
Huh? Type help for help.
The command knows from the * that you should be telling it what to put in Position.
How do we get the stuff from the *? Using
%0 and [v(0)]
That's where the weird %0 comes in. %0 is a way of saying 'Whatever was in the first *'. Since it's on
the other side of the :, it is stated as %0 or [v(0)]. There is no difference between
[v(0)] and %0.
If your command word had two *'s, like $Command * to *,
[v(0)] would get the word put in the first *,
and [v(1)] or %1 would get the word given
after the to *.
If you typed Command Bob to Joe, %0 would be Bob, and %1
would be Joe.
Just to show this in action, let's make a multi-input example for the Dog.
Type this in for your dog:
&SetPosition Dog=$Pos *
on *:&Position Dog=%0 quite near %1
Pos Sitting on the Table
This would set Position on the dog to Sitting quite near the Table:
You see a black labrador. He is Sitting quite near the Table.
The word Sitting went into the %0, and then on matched the 'on' in %0 on %1. So the remaining words, The Table,
went into %1.
Try a few other combinations to get used to the idea.
Pos Standing on The Furniture
Pos Sitting on A Thermonuclear Device
Pos Pooping on The Rug
Even More on Multiple Inputs. (If you're comfortable with the ideas of %0 and %1, just skim this.)
The ability to give $Commands data to work with can be quite useful. The trick to working with *'s is to remember
the structure of the command. Any * between the $ and the : on the left of the command becomes %# on the other
Add this to dog
&MultiInput Dog=$Command one=* two=* three=* four=* five=*:say one is
%0, two is %1, three is %2, four is %3, five is %4.
Command one=Foodles two=Poodles three=Noodles four=Oodles five=Toodles
What you'll get is a very bizarre talking labrador.
Dog says "one is Foodles, two is Poodles, three is Noodles, four is
Oodles, five is Toodles."
That's a good example for showing how you can pass information to a command, and it shows how $commands can
be used to make an object do something.
So, what we know now:
#1. How to set an attribute - &Attribute Object=Value
#2. How to call the value of an attribute with [v( )] function. - @desc Object= [v(Attribute)]
#3. How to make a simple $command to change the value of an attribute, or to make an object say something.
And, we learned that you can hand a $command more than one piece of information to work with.
Now What? Multiple actions with one $command
Before we can get to the project session of this tutorial (making our very own description changer), we need
to learn one more powerful aspect of attributes.
Attributes can contain strings of commands all on the same line. Above, we had our dog saying %0 %1 %2, etc.
But, we could also make him do more than one thing with the same $command. Here's a fun example (type this in on
&Attack dog = $attack
*:pose growls viciously
at %0!;pose attacks
You see nothing special.
Owner: You Key: *Unlocked* Pennies: 10
SETPOSITION:$Position dog=*:&Position Dog=%0
ATTACK:$attack *:pose growls viciously at %0!;pose attacks %0!;kill %0=100
If you look at this line, it has <action>;<action>;<action>
all separated by a semicolon. ; Pose
the word is the same as : the symbol that you might use to pose on the
MUSH. Only the first : is used by the mush to separate the $command words from the
action list, but I use pose instead of : just to keep
my own confusion to a minimum.
So, what have we made? We've made a Killer Dog!
Dog growls viciously at Dog! (The first action was 'pose growls
viciously at %0 - we're having the Dog attack itself.)
Dog attacks Dog! (The second action was 'pose attacks %0!')
Dog killed Dog! (The third action was the actual good old MUSH Kill
command. To kill someone, you use kill Name=100. In this case, the dog is killing itself. Killing, if you're unfamiliar
with it, will simply send a person home and give them 50 pennies.)
Dog> Dog killed you! You receive 50 pennies from your insurance policy.
Dog has gone home.
Dog has arrived. (Since we set the dog's home to here with @link Dog=here, it will return here after
it's been killed.)
If there's another player in the room with you (who won't get completely pissed off if you
kill them) try having the dog attack them. Or, have the dog attack you. Or create another puppet object
and have the dog attack it.
Now we have all the pieces we need to assemble our Description Changer.
You can either destroy the poor crazed talking dog you just made, or continue to terrorize your home MUSH with
Project 1: Making a Simple Description Changer
The first step is to make the device.
@create Description Changer
Here's what the device will do:
Each description you set will have three sections: 1> Face/emotions, 2> Build/Physique, and 3>Clothing.
Your changer will allow you to change sections on the fly, so that instead of having to re-write all three,
you can change your clothing, or your face, or your build without affecting the other parts of your description.
You can review your stored sections to preview what the desc will look like as you edit parts, and then when you
want to change to that description, you'll type SetDesc and it will change your description to the new description,
discarding the old one.
So, to make this changer, we need five $commands:
- Face to set the first section of the description
- Build to set the second section of the description
- Clothing to set the third section of the description
- Review to check what you entered before you set your new desc
- SetDesc to put the desc on you.
Let's start with the Face command, as Build and Clothing will be identical to it - they'll just set different
attributes to store information:
&SetFace Description Changer=$Face
*:&Face Desc Changer=%0;@emit Face Set: [v(Face)]
From what we have learned, we know:
&SetFace Description Changer=
makes the attribute on the Description Changer.
We know that
is a $command that will take anything after the word Face and put it into the *, which will become %0 on the
other side of the :
We know &face Desc Changer=%0 will set the description for our face into a variable called Face on the desc
But what about @emit Face Set: [v(Face)]
Well, [v(Face)] is the value of what we just entered, so the changer is basically showing us what it put in
Face for us.
See if you can alter the Face line to store Build and Clothing. If you're not sure, the answers are below:
&SetBuild Description Changer=$Build *:&Build Desc Changer=%0;@emit
Build Set: [v(Face)]
&SetClothing Description Changer=$Clothing *:&Clothing Desc Changer=%0;@emit
Clothing Set: [v(Face)]
You can try Face, Build and Clothing with these test values:
Face You see a nice person with a round face.
Build He/She is of a healthy build, with strong looking shoulders for holding
back his/her crazy labrador dog.
Clothing He/She is wearing ripped jeans and a T-Shirt.
Before we actually let this device set our new description, we'll want a Review command to check the values
of Face, Build and Clothing before they're written onto us as a Description.
&Review Desc Changer=$Review:@emit Current Description: %r%t[v(Face)]
If you type Review, you'll see:
You see a nice person with a round face.
He/she is of a healthy build, with strong looking shoulders for holding back his/her
crazy labrador dog.
He/She is wearing ripped jeans anda T-Shirt.
What about %r and %t? Formatting
%r means 'New Line' or 'Carriage Return'. Type this:
say Hi there%rMy name is%r%r%tTest.
You say, "Hi there
My name is
They're just ways of making output to the screen prettier. Any time the MUSH sees %r, it will continue writing
whatever it was writing on the next line. %t or Tab is a little more finicky. It pushes whatever text it's writing
up to an invisible tab line. Generally, from the start of a new line, it will push things in five spaces. That's
why Test, above, is in five spaces.
The final command - SetDesc
Type this to add this command to your Desc Changer.
&setdesc Description Changer=$SetDesc:@desc %#=%t[v(Face)]%r%t[v(Build)]%r%t[v(Clothing)];@emit
This command will take the values of Face, Build and Clothing and actually write them to you. %# means 'The
number of the person who used this command'. So, @desc %#=<stuff> means: Change the desc of the person who
just used this command to <stuff>. To let you know that it's done it's work, there's also a simple message:
@emit Description Changed.
It's always a good idea with code projects to list the commands in the description for them, or make yourself
a simple $desc help command.
Here's a sample description for what we just made:
@desc Description Changer=This is a simple device for changing and loading descriptions.
The commands are:%r%rFace <message>%rThis sets the first part of your description. Example: Face A woman
with a smiling face.%r%rBuild <message>%r%rThis sets the second section of your description. Example: Build
She has broad shoulders and short legs.%r%rThe third part is Clothing <message>%rThis sets the final part
of the description. Example: Clothing She is wearing a green t-shirt and ripped jeans. Her sneakers are worn, and
are a grey plaid.%r%rReview - lets you check your description before you set it.%r%rSetDesc - This will write the
new description over your old one.
This will look like:
This is a simple device for changing and loading descriptions. The commands are:
This sets the first part of your description. Example: Face A woman with a smiling face.
This sets the second part of your description. Example: Build She has broad shoulders and short legs.
This sets the final part of the description. Example: Clothing She is wearing a green t-shirt and ripped jeans.
Her sneakers are worn, and are a grey plaid.
Review - lets you check your description before you set it.
SetDesc - This will write the new description over your old one.
A simple Help command would be:
&help Description Changer=$deschelp:@emit This is a simple device for changing
and loading descriptions. The commands are:%r%rFace <message>%rThis sets the first part of your description.
Example: Face A woman with a smiling face.%r%rBuild <message>%r%rThis sets the second section of your description.
Example: Build She has broad shoulders and short legs.%r%rThe third part is Clothing <message>%rThis sets
the final part of the description. Example: Clothing She is wearing a green t-shirt and ripped jeans. Her sneakers
are worn, and are a grey plaid.%r%rReview - lets you check your description before you set it.%r%rSetDesc - This
will write the new description over your old one.
This would simply emit the same info we had in the Desc above.
#1. Create Individual Help Files for each of the commands in the Desc changer.
Example: Deschelp Review would give you help on the review command, but not
on all the other commands.
#2. Instead of @emit,
try using @pemit %#= for all the messages. The @pemit stands for
Private Emit. Only you will see the messages from the Desc Changer with this command. Type help @pemit for more
information on the 'Private Emit'.
#3. Super Bonus Credit - if you can do this, you're well on your way
to coding complex items.
Can you figure out a way to store various parts of the description in different variables instead of overwriting
them each time? Example: Clothing1 would be ripped jeans and a t-shirt, but Clothing2 might have a tuxedo, or something
Need Help or hints on extra credit? Found a bug in the tutorial? Want to know more? Email firstname.lastname@example.org