LPC Basics Written by Descartes of Borg first edition: 23 april 1993 second edition: 01 july 1993
After examining your workroom code, it might look something like this (depending on the mudlib):
----- inherit "/std/room"; void create() { ::create(); set_property("light", 2); set_property("indoors", 1); set("short", "Descartes' Workroom"); set("long", "This is where Descartes works.\nIt is a cube.\n"); set_exits( ({ "/d/standard/square" }), ({ "square" }) ); } -----If you understand the entire textbook to this point, you should recognize of the code the following:
This chapter will seek to answer the questions that should be in your head at this point:
If you had to write the code necessary for you to define the workroom above, you would have to write about 1000 lines of code to get all the functionality of the room above. Clearly that is a waste of disk space. In addition, such code does not interact well with players and other rooms since every creator is making up his or her own functions to perform the functionality of a room. Thus, what you might use to write out the room's long description, query_long(), another wizard might be calling long(). This is the primary reason mudlibs are not compatible, since they use different protocols for object interaction.
OOP overcomes these problems. In the above workroom, you inherit the functions already defined in a file called "/std/room.c". It has all the functions which are commonly needed by all rooms defined in it. When you get to make a specific room, you are taking the general functionality of that room file and making a unique room by adding your own function, create().
----- inherit "/std/room"; -----has you inherit the functionality of the room "/std/room.c". By inheriting the functionality, it means that you can use the functions which have been declared and defined in the file "/std/room.c" In the Nightmare Mudlib, "/std/room.c" has, among other functions, set_property(), set(), and set_exits() declared and defined. In your function create(), you are making calls to those functions in order to set values you want your room to start with. These values make your room different from others, yet able to interact well with other objects in memory.
In actual practice, each mudlib is different, and thus requires you to use a different set of standard functions, often to do the same thing. It is therefore beyond the scope of this textbook even to describe what functions exist and what they do. If your mudlib is well documented, however, then (probably in /doc/build) you will have tutorials on how to use the inheritable files to create such objects. These tutorials should tell you what functions exist, what input they take, the data type of their output, and what they do.
----- inherit "filename"; -----where filename is the name of the file of the object to be inherited. This line goes at the beginning of your code.
An example:
----- #1 inherit "/std/room"; void create() { create(); } ----- ----- #2 inherit "/std/room"; void create() { ::create(); } -----Example 1 is a horror. When loaded, the driver calls create(), and then create() calls create(), which calls create(), which calls create()... In other words, all create() does is keep calling itself until the driver detects a too deep recursion and exits.
Example 2 is basically just a waste of RAM, as it is no different from room.c functionally. With it, the driver calls its create(), which in turn calls ::create(), the create() in room.c. Otherwise it is functionally exactly the same as room.c.