Come code with us
Come code with us
The adventure begins

Merentha Website
About LPC Coding
Header Files
The Problem Sets

Normal Rooms
Monster Rooms
Search Rooms
Exit Rooms
Door Rooms

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

A Vest
A Ring
Cursed Armour

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

A Match
A Torch
A Lantern

A Normal Bag
A Backpack (wearable)
An Expanding Bag

Misc Objects
A Leaf
A Sea Shell
A Key
A Snowball

Merentha is an LP type MUD which means the language we code in is LPC. It is very simular to both C and C++ but different in other ways as well.

Objects are inherited, which means from a base object we can copy the functions and abilities from it with a single line of code instead of copying all the code by hand.

To understand a little more, take a look at the diagram below...

                      ARMOUR  |   FOOD
                         \    |   /   
                          \   |  /    
                           / \   \        
                          /   \   \       
           TAMEABLE   LIVING BOARD \      
               \      /   \         \     
                \    /     \       CONTAINER
  RIDEABLE------MONSTER   USER        /    \   
                  /  \          STORAGE  ROOM
                 /    \                  /  \    
                /      \                /    \
             VENDOR   BARKEEP        PIER   VAULT
Every object stems from the root file which is OBJECT. So a monster you create will inherit MONSTER which in itself inherits all the abilities of LIVING which inherits all the abilities of the core OBJECT.

Now what are these abilities you may ask. Well they are such things as the name of the object in question. All objects have names. The player Petrarch is an object which has the name "Petrarch". A snowball has the name "Snowball" and so on. This information is recorded in the OBJECT and since LIVING inherits OBJECT and MONSTER inherits LIVING and the monster you create will inherit MONSTER then the monster you create will not have to worry about the code needed to give an object a name, or to store it or anything of the sort, its already taken care of.

There are also other things which LIVING inherits besides OBJECT but they are not shown for the sake of simplicity. It also inherits BODY and COMBAT which describe how the body works, what limbs are on the body, what armour or weapons are wielded or worn as well.

It is also possible to do multiple inheritance. For eaxmple in the "bags" section for coding we do in one example where we inherit both ARMOUR and STORAGE to make a backpack that can both be worn and store things.

Inheritance is used all the time. Most of the files/objects you create will have at least one inheritance line in them. This line will look something like:
inherit MONSTER;
inherit "/std/monster.c";
Infact, both of those lines are the same. The section on header files will explain it a bit more, but MONSTER translates down to "/std/monster.c"

You will also see lines like this:
This is a rather special line of code. Remember how when you inherit an object you inherit all the abilities of that object. You inherit all the variables and functions. If this concept is still a bit tricky to understand think of it like normal genetic inheritance. A frog inherits it's colour and shape from its parents, and a human inherits his shape and colour from his parents. The shapes and colours are different, so are the abilities. Frogs can jump higher and people can think better.

Ok, so back to the ::create(); line. In the object/file you inherit there are functions which define many things. One of the functions in the inheritable object is a function called create()

Now this function is really a special function which will automaticlly get called in all objects when the object is created, but that is not too important right now. What is important is that in the example of a monster file you will set its name, race, level and so on in this function. However, this function also exists in the inheritable file and contains some important information. Now if you write your own create() function you will overwrite the inheritable function and lose any of the important information that the inheritable object did.

So what you want to do is call the inheritable's create() function then do your own. The problem is you can't just call the function as create(); because then you will get an infinate loop. You have to call the function as ::create(); which means call the inheritable create() function.

You can also write the function as monster::create(); if you wished. This is somewhat important when you inherit multiple objects and need to specify from which object you wish to call a function.

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