Important Concepts
Important Concepts
IMPORTANT CONCEPTS WITHIN A DUTCHPIPE UNIVERSE
The dpuniverse/ directory
Filename based classes
The universe object
The standard class
Other standard classes
Inventory, environment
Moving objects
The dpuniverse/ directory
Your universe is constructed from objects in the following
directory:
dpuniverse/
The dpuniverse/ directory contains
subdirectories for pages, "non playing characters" (bots) and other
objects: dpuniverse/page/,
dpuniverse/npc/ and
dpuniverse/obj/.
Filename based classes
Each .php file within
dpuniverse/ should contain only one class,
with the classname the same as the filename, without
.php, and the first letter in upper case. For
example:
dpuniverse/page/bar.php defines class
Bar
Class names must be unique. See DutchPIPE Issues for more
information about this limitation.
The universe object
The universe object is created when the DutchPIPE server is started,
keeps track of all objects in the site and sports a number of
important methods you can call.
A reference to the universe object is obtained by the
get_current_dbuniverse() method. Example:
$universe = get_current_dbuniverse();
$note = $universe->newDpObject('/obj/note.php');
See DpUniverse for a list of callable methods in this
object.
The standard class
Each object extends on the DpObject class from
dpuniverse/std/DpObject.php,
either directly, or by using a class that extends on it.
Other standard classes
Other standard classes provide several building blocks for your
site:
DpPage to make a page;
DpNpc to make a non playing character (a bot);
DpDrink to make a drink.
They all extend on DpObject.
Inventory, environment
Objects can "contain" other objects. You can call the getEnvironment
and getInventory methods in all objects to see how they are related
to the objects surrounding them or contained in them:
/* List of what the user is carrying */
$inv = $user->getInventory();
foreach ($inv as &$ob) {
}
$env = $note->getEnvironment();
if ($env->getProperty('is_page')) {
... /* The note is sitting on the page */
} elseif ($env->getProperty('is_user')) {
... /* Someone is carrying the note */
}
Moving objects
Call moveDpObject in objects to move them around, for example:
/* Moves note to inventory of user */
$note->moveDpObject($user);
/* Moves note to page */
$note->moveDpObject($user->getEnvironment());