Merentha
Come code with us
Come code with us
The adventure begins

Merentha Website
Overview
About LPC Coding
Header Files
The Problem Sets

Rooms
Normal Rooms
Monster Rooms
Search Rooms
Exit Rooms
Door Rooms

Monsters
Normal Monster
Random/Emote Monster
Patrol/Talking Monster
Skills/Interactive Monster

Armour
A Vest
A Ring
Cursed Armour

Weapons
Normal Staff
Two Handed Sword
Special Attack Weapon
Cursed Weapon
Talkin Weapon

Lights
A Match
A Torch
A Lantern

Bags
A Normal Bag
A Backpack (wearable)
An Expanding Bag

Misc Objects
A Leaf
A Sea Shell
A Key
A Snowball

Ok, lets get to work...

Unfortunatly I'm not going to set you lose quite yet. I will not take a moment to discuss a few topics armout LPC. You should take some time in the near future and read Descarte's LPC tutorial books available here since they will explain LPC in more detail.

Quite simply LPC is an object orientated language. That means everything you create is an object. For the most part each file you create will be an object as well. So each room will be a different file, and each monster and object will be a different file too. You should try and keep the following format of all your files:

1. comments
2. main function (usually create())
3. other functions
Most of the files you will encounter will have that format. Let us look at your workroom file. You will end up editing this file to make a custom workroom for yourself.
  1  // single line comment line
  2
  3  /* different type of comment
  4     can go on many lines */
  5
  6  // Petrarch
  7  // Standard Workroom
  8
  9  #include 
 10
 11  inherit ROOM;
 12
 13  void create() {
 14      ::create();
 15      set_properties(([
 16          "light" : 2,
 17          "indoors" : 1
 18        ]));
 19      set_short("a new workroom");
 20      set_long("This is the grand workroom of a new immortal.  Inventive new realms will originate here.");
 21      set_exits(([
 22          "square" : "/domains/Praxis/square"
 23        ]));
 24      set_items(([
 25          "workroom" : "Code is being created here."
 26        ]));
 27      set_smell("default", "It smells like a new immortal.");
 28      set_listen("default", "The sounds of code creation vibrate the room.");
 29  }
That is a listing of what it looks like in ed with number mode on. There are additional comments added here so we can talk about them. Typically your files will begin with what is on line 6, a simple comment line which names you as the author.

Ok, so lets talk about comments. When you see // that is the start of a comment. A // can be anywhere on a line, sometimes you will see it in the middle of a line. Bascilly this tells the MUD that everything after the // is a comment and to ignore the rest of the line, it is not code.

The /* and */ type comments are different. These comments are ment for multiple lines. Basiclly /* is the start of a comment and */ is the end of the comment. Do not ever put a /* */ comment inside another /* */ comment. It can cause problems.

Line 9 is of interest as well. This line includes a header file called std.h. Header files are used to define information. More info on header files is in problem set 6.

Line 11 tells us that this file (this object) is a room, and we inherit all in information about rooms.

Line 13 starts our main function, called create() and it ends on line 29. Functions are in the format of:

type functionname(args) { ..... }

  • type is the type of information the function returns, in this case it is void, but functions can return strings, integers, or other data types.
  • functionname is the name of the function, in this case it is create
  • inside the () we put and arguments or parameters we have for the function. In this case there are none so its just empty.
  • { and } are sort of like begin and end tags so we know where functions begin and end.
Line 14 is interesting as well. This line and lines beginning with :: allow us to call functions from the object we inherit. In this case we inherited a generic room. When rooms (and all files for that matter) are created the create() function is called to create it. Because of this we can setup the room in the create() function. BUT there is one problem. There may be important information in the create() function of the object we inherited. So ::create(); allows us to call the create() function in the inheritable object.

The rest of the file sets information. This information is what you will edit. Rooms are discussed in much more details in the room examples and many more features are shown in those. For now though use your skills from the previous problem set and edit your workroom. Once you are ready it is time to move on to the next problem set.

Just a note, the numbers are not part of the code. Those numbers can be turned on and off with the n command in the editor. They are there to allow simple editing of the file. So when you edit lines don't type in those numbers.



Merentha
It's your creation
Merentha Entertainment
© Copyright 1998-2002
Merentha Entertainment
All rights reserved.