![]() |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
As described earlier, an object defines an inside as well as an outside. The outside, or environment can only be one object, while the inside, or inventory, can contain many objects.
A newly cloned object ends up in a sort of limbo, without an environment. In order for an object to actually enter the simulated physical world of the game it has to be moved there. However, not all objects can be moved around. In order for the game to work ANY object that wants to be inserted somewhere or have objects inserted into it MUST inherit `/std/object.c' somewhere along the way in the inheritance chain. Why this limitation? Well, the reason is that the standard object defines a number of handy functions we rely on all objects in the game to define.
The most important of these lfuns are:
NB! The above ONLY works if you use the lfun
move()
in the object to move them around. That's why it's so
important that you do it this way and not by the efun that actually
performs the move.
The efun used in the move()
lfun is
move_object()
. BUT, remember when doing that none of the
object internals like light, weight or volume is updated. As previously
stated the efun fails if the object you want to move, or move to,
doesn't inherit `/std/object.c'. Furthermore the efun can only be used
from within the object that wants to move, it can't be used to move
another object. The same goes for the move()
lfun, naturally.
In order to get the enclosing object reference you use the efun
environment()
. As I have said before all objects have no environment
on creation, it's only after they have been moved somewhere that it gets
a proper environment. Once an object has been moved into another object
it can't be moved out into limbo again, i.e. you can't move it to '0'.
The objects in the game you can expect not to have an environment are
either rooms, souls, shadows or daemon objects of one kind or another.
You have two efuns to chose between when it comes to finding what's in
the inventory of an object. The efun all_inventory()
returns an
array with all the objects in the inventory of a specified object, while
the efun deep_inventory()
return an array with all objects
recursively found in the inventory, i.e. not only the objects you'll find
immediately but also the objects in the objects in the inventory,
and so on.
object *all_inventory(object ob) object *deep_inventory(object ob) e.g. /* * This function dumps the inventory of Fatty on the screen, * either just what's immediately visible or all depending * on a given flag. */ void fatty_say_aaah(int all) { object fatty_ob, *oblist; if (!objectp((fatty_ob = find_player("fatty")))) { write("Sorry, Fatty isn't in the game today.\n"); return 0; } oblist = all ? deep_inventory(fatty_ob) : all_inventory(fatty_ob); write("The " + (all ? "entire " : "") + " content of Fatty's bloated tummy:\n"); dump_array(oblist); } |
So... how do you go about to determine if a specific object actually is
present in the inventory of another object? Well, the base object
/std/object.c
define both names and descriptions in objects, as
described before. It also defines a special function called id()
that, given a name, checks all given names to an object for a match and
returns 1 if the object has that name. The efun present()
takes
a name or object reference and searches one or more object's inventories
for the presence of the named or specified object. If you specify the
object to search for as a name string it will use the previously mentioned
id()
function to determine if the object is the right one or not
for all objects it examines. The execution of the function is aborted as
soon as it finds one that fits the description. That means that if there
are several objects fitting the search pattern you will only get one of
them.
object present(object ob|string obref, object *oblist|object ob|void) e.g. /* * Look for donuts in Fatty */ void find_donut() { object fatty_ob; fatty_ob = find_player("fatty"); // Can't find Fatty! if (!objectp(fatty_ob)) { write("Fatty isn't in at the moment, please try later.\n"); return; } if (present("donut", fatty_ob)) write("Yes, Fatty looks happy with life at present"); else write("If I were you, I'd keep out of Fatty's " + "reach until he's fed.\n"); } |
If you don't give any second argument to present
, it will look
for the specified object in the inventory of this_object()
, i.e.
the object itself. If the second argument is given as an array, the
function will look for the specified object in all of the objects in the
array. If no fitting object is found, 0 is returned.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |