So, what does this mythical code stuff look like? Lots of mystical 1s and 0s and Greek characters? Nope. Actually, it's pretty ordinary looking. MOO code is written in lines - you enter a line at a time in the verb editor. At the end of each line is a semicolon (;). Not so scary huh? (By the way, don't forget the semicolons, they are actually important!)
To create a variable in your code the easiest way is:
<variable name> = <value>;
For example:
my_number = 1;
This would create a variable called 'my_number' that held the integer '1'. You can't create a variable without giving it a value at the same time - you couldn't just say 'my_number' and have a valueless variable - in the same what that properties have to contain some value.
Variables last only as long as the code in which they're created is running. To store values longer than that, write them to an appropriate property.
They also have no set 'type' that they can contain, unlike variables in a lot of other programming languages. my_number = "string value";
is quite permissible, even after creating it as a variable to store a number in.
There are some variables that are set automatically for every piece of code. They're used all the time, so here they are and what they mean.
say hello
, then in the say verb player would have the value #2
. This is absolutely vital for any MOO coding - otherwise you wouldn't know who to tell what happened when they typed in their command!
this
would hold the object reference for particular child of the generic thing - so for example in 'drop this
variable to move the object that's being dropped to the room, rather than the generic thing to the room!
argstr
variable would contain the string "my gold ring to Kassandra"
verb
, plus a space, plus argstr
.
These two variables are useful for finding out what the player wanted to do with the command.
prepstr
. Likewise, dobjstr
will hold the string that the server matched as being where the direct object should be, and iobjstr
where the indirect object should be.
args
variable holds a list. For commands, it is a list of the words in the argstr
so is not especially useful. However, for verbs that are called from within other verbs, it contains a list of the values that were passed to it. This is the information inside the ()s.#2:tell("Hello!");
the args
variable in the tell function would be a list, with the string "Hello!"
in it.