[DGD] The function call_other

birgit.schulte at philips.com birgit.schulte at philips.com
Mon Aug 23 18:31:13 CEST 2004





> I have another question. I edited the auto object before to call the
> create() function every time a new object is cloned.
> I added the following to the function clone_object:
> if(function_exists("create", retobj)) {
>   retobj->create();
>     }
> I noticed that this only affects the objects beeing cloned, not the ones
> called for the first time. If another object does
> "/obj/an-object"->display_text() the create() doesn't get called. I'm
> wondering. Can I rewrite the function compile_object in auto to?

Well, you can rewrite any kernel-function by redefining it in the auto
object.

The check which you added to your clone_object-function will probably not
work
in the intended way. First, function_exists() should be function_object()
(dunno if that
changed maybe due to the DGD version, or due to your library).
Second, function_object() will only check the very object you have given
for the
function name, not any objects which are inherited. So if create() was
defined
by some ancestor, and not redefined in your toplevel object, your check
will always fail.
Third, create() is usually defined as static, meaning you can't do a call
to
some_object->create().

Generally, you don't need to check at all if a function exists to call it -
just do it.
If the function you are calling does not exist, nothing happens, not even
an error.

So you don't have to call create() explicitely in clone_object(),
since DGD will do that for you. If you have a look at the mud.ini file,
you'll
see that a create_function is defined in there. I don't know if you are
working with
the kernel-library, if so, then there will be wrapper-function defined in
the auto object
to make sure that the function create() gets called when needed.
DGD will call this function in any clone right after cloning, and else in
any object
upon the first function-call to it.

If you want to make sure that every object gets initialized as soon as
possible,
just add the following into your compile_object somewhere after the
successful compile
happened:

::call_other(new_obj,"");

This will try to perform a call to a nameless function which will never
exist, and thus
make DGD call the create() in that object.


Regards,
Birgit

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list