Phantasmal MUD Lib for DGD

Phantasmal Site > DGD > DGD Reference Manual (legacy) > Getting Started

3.1 Getting Started

Now that you have the Kernel Library running, it's time to start learning some simple LPC code. There are two ways to test your LPC code with the Kernel Library. We'll start with the simpler way, which is called the "code" command.

Log in as admin, if you haven't already. Type code 7+4. You should see a response like $0 = 11. The $0 is a value that DGD will store for you. You can refer to it later whenever you like. For instance, if you typed code $0+9, you'd see a result like $1 = 20. Note that this time the history value is $1, not $0. $0 keeps its old value, and a new history item, $1, gets the new value. The history number will keep increasing as you perform commands that place values into the history list.

Next try typing code status()[ST_VERSION]. Note the opening and closing parentheses go before ST_VERSION in square brackets. If you do it right, you'll get the current version of DGD, such as $2 = "DGD 1.2.101".

The parentheses after a name mean to call a function by that name. Anything between the parentheses are the arguments of the function, also called parameters. For instance, try typing code sin(2.0 * 3.14159). You should get a result like $3 = -5.3071519e-6. Whatever result you get, it should be a very small number, like the above. That's because you're calculating the sine of two pi, which (if calculated absolutely perfectly) is zero. Now try typing the same thing, but with 2 instead of 2.0. If you're used to programming in C, the result may surprise you!

It turns out that ST_VERSION, in the example with status(), is actually a number. The code command defines certain constant values for you, and assigns names to them. So if you type simply code ST_VERSION, you should see the numerical value of ST_VERSION, 0, printed out. That's because underneath, ST_VERSION is just the number 0. We've assigned a value to it using the C Preprocessor, a very powerful part of the language that will be described in a later chapter.

You can put in extra spaces almost anywhere — between operators, before and after operators, between the function name and the opening parenthesis. Experiment liberally with where you can add spaces, it's useful to know. Note that you cannot add spaces before the code command. The Kernel Library won't parse it correctly, and will tell you that there isn't any such command as nothing. It's a bug in the Kernel Library's command parser.

The code command is very powerful, but very limited. It's very powerful because you can use it to evaluate any valid LPC code. It's very limited because you have to put all the code on a single line, and because it's hard to save old code commands to use again. This tutorial will use it to teach you the basics of LPC. Later, you'll find out how to put LPC code into files and compile those files into programs and objects.

<— Prev
A Quick LPC Tutorial
Up
A Quick LPC Tutorial
Next —>
Variables and Arithmetic Expressions