Next: Passing Messages

Prev: Calling Functions

Sending Messages

If you want to retrieve information from or modify an object other than the current object, you can do so by sending it a message. You can do this with a message expression, which has the following syntax:

receiver.message(arg1, arg2, ...)
You may omit receiver, in which case it is assumed to be the current object. Otherwise, receiver must be an expression of dbref or frob type, and message an identifier giving the name of the message. arg1, arg2, ... are the arguments to be sent with the message. The arguments are evaluated from left to right. You must include the parentheses around the argument list, even if there are no arguments. The result of a message expression is the value returned by receiver's method for the message message.

If receiver is a frob, then the message is sent to the frob's class object, with the frob's representation inserted as the first argument. If receiver is a dbref, then the message is sent to the object with that dbref.

If receiver is not an object or frob, then the interpreter throws a ~type error. If receiver is a dbref which does not refer to an existing object, or if it is a frob whose class is not an existing object, then the interpreter throws an ~objnf error. If receiver does not have a method defined for message, then the interpreter throws a ~methodnf error. See Errors for information on how to handle errors.

Here are some examples of message expressions:

.tell("I don't see that here.");
$sys.wizards()
loc.tell_contents(args[1]);
You can substitute an arbitrary expression for message, by enclosing it in parentheses. The syntax for sending an arbitrary message is:

receiver.(message-expression)(arg1, arg2, ...)
As before, receiver can be omitted, in which case it is assumed to be the current object. message-expression must be an expression of symbol type, or the expression will cause a ~type error. You must include the parentheses around the argument list, even if there are no arguments.

In order to prevent incidents of infinite recursion, Coldmud has a maximum calling depth for messages. This maximum depth is 128 method calls in the current version. If sending a message would exceed the maximum calling depth, the interpreter raises a ~maxdepth error.