A
          / \      _             Play Now                         Nemesis on fb
          | |     | |  _______   _        _   _______    _______   _    _______
          | |\    | | |   ____| |  \    /  | |   ____|  /   ____| | |  /   ____|
 /-------/-------------------------------------------------------------------,
O= Home <=XX|  About  News  Pics  Adventurers  Wizards  Download  Connect     >
 \-------\-------------------------------------------------------------------'
          | |   \   | |  |____  | |      | | |  |____   ___ \  \  | |  ___ \  \
          | |     \_| |_______| |_|      |_| |_______| |_______/  |_| |_______/
          \ /
           V  

Documentation Area

Document Path: /doc/LPC/inheritance


INHERITANCE

An object can inherit all variables and functions from another object.
This is done with the declaration 'inherit "file";'. This must come before
any local variables or functions.

An example, defining a monster:

inherit "obj/monster";

reset(arg) {
    ::reset(arg);
    if (arg) return;
    set_name("troll");
    set_level(9);
    set_hp(100);
    set_wc(12);
    set_al(-60);
    set_short("a troll");
    set_long("It is a nasty troll that looks very aggressive.\n");
    set_aggressive(1);
}

Here you see something like a "family tree" of the most important
inheritance in Nemesis:

  obj/wizard
      |
  obj/player         obj/monster
      |                    |
      +---------+----------+
                |
           obj/living

obj/living is inherited by obj/monster and obj/player as the base of livings.
The code there are the basics of "life". Monsters, based on obj/monster, need
different code as players or wizards. So they have there own code: obj/monster.
Players are clones of obj/players. Wizards, that are clones of obj/wizard
need a bit more code than players, so obj/wizard inherits obj/player.


INHERITING FROM MULTIPLE FILES

Consider the following code

  inherit "path/to/a";
  inherit "path/to/b";

  func() {
    return ::func();
  }

If both inherited files define func() this ::func will call func in the first
inherited file that defines the function (in this example "path/to/a").

If you want to call the function in a specific parent you can set its filename
before the ::, in this example:

  func() {
    return b::func();
  }

WARNING: Due to restrictions of the parser this syntax does not work with 
filenames containing a hyphen ("-")!

See also:


This page was generated in LPC

Imprint / Impressum