![]() |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
As stated object references either are strings or object pointers. Turning
an object reference to a string is done with the efun file_name()
:
string file_name(object ob) e.g. write("This object is: " + file_name(this_object()) + "\n"); |
The string that pops out of file_name
is the string
representation of the object reference pointer. It's given as
<file path>#<object number>
, for example
"/w/Wizard/magic_potion#2321"
. This string is a valid object
reference to that specific object as well.
To turn a string object reference into an object pointer reference you
use the efun find_object()
.
object find_object(string obref) e.g. object the_ob; // The master object the_ob = find_object("/w/Wizard/magic_potion"); // The specific clone the_ob = find_object("/w/Wizard/magic_potion#2321"); |
If the function doesn't find the object (the path might be wrong, the specified clone might not exist or the object might not be loaded), it returns 0.
Sometimes it's useful to find all the clones of a specific object. The
efun for that is object_clones()
. It will return an array holding
all clones of the master object the object reference indicates. This means
that you can give either a master object or an object clone pointer as
argument. However, be a bit careful here. If the object was updated and
your provide the master object as argument, you will get a list of all
the 'new' clones. If you give an old object as argument you will get a
list of all contemporary objects, the objects of that 'generation'. If
no clones can be found, an empty array is returned.
object *object_clones(object obref) e.g. object *ob_list; ob_list = object_clones(find_object("/w/Wizard/magic_potion")); |
Some objects are living. In the game this denotes the fact that the
objects can be attacked and (perhaps) killed and that they want to receive
command updates from objects that turn up either in the environment or the
inventory of the object itself. Living objects have the option of registering
themselves in a special list in the gamedriver. This is done in order to
make them easier to find. The special efun find_living()
looks for a
named living object in the internal list of names.
object *find_living(string name, void|int 1) e.g. object balrog_ob, *bals; // Search for the 'balrog' monster in the game. balrog_ob = find_living("balrog"); |
If you give '1' as second argument, the efun will return a list of all objects with that name found instead.
bals = find_living("balrog", 1); |
If no living object with the given name can be found, 0 is returned.
In order for the name to become part of the list of names, the object itself
must add the name to the central list with the efun set_living_name()
.
void set_living_name(string name) e.g. // This is part of the 'create()' function of the balrog above. set_living_name("balrog"); |
Remember that if you have several objects with the same name,
find_living()
in the single object mode will randomly return one
of them.
For your own sake you ought to reserve the use of npc names with the special 'banish' command in the game, so that no players turn up with the same name as you npc. If that happens things are very likely to get confused...
In order to get the master object reference of an object you have a
pointer to, you can convert it to a string, then strip off the object
specifying bits. However, there's already a macro doing that in the
standard package `/sys/macros.h'. Simply add the line
#include <macros.h>
to the top of your file and use the macro
MASTER_OB
.
string MASTER_OB(object ob) e.g. string master; // Assume that /sys/macros.h is included in this file. master = MASTER_OB(find_living("balrog")); |
As stated, this returns the string reference to the master object, if you
particularly need the object reference just get it with find_object()
given the just established object path as argument.
A clone is easiest distinguished from the master object by comparing the
object reference strings. The macro IS_CLONE
does that for you,
also available in `/sys/macros.h'. The macro works on
this_object()
and takes no argument
int IS_CLONE e.g. if (IS_CLONE) write("I am a clone!\n"); |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |