LDMud logo: an emblem with three snakes, on the left behind that emblem a cogwheel. In front of both is a sword.


Home of LDMud

View the Project on GitHub ldmud/ldmud


Functions are code blocks that have a name. Every LPC code that wants to be executed must be somewhere within a function. (There is just one exception: the initialization of global variables.)

A function has a name, a return type, arguments (i.e. values given to the function when called) and its code block:

    int get_square(int x)
        return x*x;

In this example the first int denotes the return type. It's followed by the function name and the arguments in parenthesis. After that comes the code block in braces.

To call a function within the object just write the name and the values for its arguments in parenthesis,

    x = get_square(42);

To call a function in another object there is an efun call_other which can be abbreviated with ->.

    x = ob->get_square(42);
    x = call_other(ob, "get_square", 42);


Functions and global variables can have modifiers to change the behaviour of the function resp. variable. The modifier is written just before the return type.

This function can only be called from within this program (this file and included files). Calls from other objects or inheriting programs will ignore this function. For global variables this means that inheriting programs can't access the variable.
This function can only be called from within this object. Calls via call_other (from this object or another object) will ignore this function.
This function can only be called from within this object, even via call_other. Calls from other objects (via call_other) will ignore this function.
The function can be called from within this object or from other objects. This is the default for functions. For global variables it prevents changing the visibility to private or static by inheritance. The variable will stay visible in inheriting programs.
This function cannot be overriden by inheriting objects. Nor can shadows shadow this function.
Issue a warning whenever this function is called or the variable is used.
When calling this function from within the object arguments can be ommitted. Ommitted arguments will be set to 0. Please note that calls via call_other are always treated as varargs calls.
Declare that this variable should not be stored with save_object or restored by restore_object