CLEAN_UP(L)

NAME
	clean_up - notify an object that it's time to clean up

SYNOPSIS
	int clean_up(int ref_count)

RETURN VALUE
	A zero value means never call again clean_up in object again.
	A non-zero value means call it again later.

DESCRIPTION
	In an effort to save valuable memory space, here is your possibility
	to help reduce the load on the machine.

	clean_up() will be called when no function has been called in this
	object for a certain amount of time. (normally about half an hour)

	ref_count is a count of how many objects there is that has pointers
	to this object. If in doubt, never destruct an object with more than
	1 refcount. (an object always has at least one refcount)

	It is up to the object itself to self destruct
	("destruct(this_object());").

	If clean_up() returns 1 it will be called again later.

EXAMPLES
	A minimal and reasonably safe clean_up() for rooms would be this one:

	int clean_up(int ref_count) 
	{
	  if (ref_count>1 || /* If someone has a pointer to this object, or */
	      environment() || /* if we are inside another object, (room/bag/player) */
	      first_inventory(this_object())  /* or if there is someting inside us */
	    )
	    return 1;  /* don't destruct, call me later */
  
	  destruct(this_object()); /* self destruct */
	  return 0; /* Don't call me again, I am gone */
	} /* clean_up */

	This clean_up will destruct a room if it empty and noone has visite it
	for 30 minutes. This is the default for rooms that inherit room/room.c
	on nannymud. A more general approach would be to take into
	consideration that any objects that was cloned in reset() will be
	cloned again if the room is destructed and loaded again, this is not
	normally the case.

	Here is an example of a clean_up that will destruct the master if
	there are no clones of it. (Note that it does not care if there
	is objects in the master or not)

	int clean_up(int arg)
	{
	  if(environment()) return 0;
	  while(first_inventory()) destruct(first_inventory());
	  if(_isclone(this_object()) ||
	     (arg<2 && this_object()==_next_clone(this_object())))
	    destruct(this_object());
	  return 1;
	}

NOTA BENE
	Remember that if you have a room that keeps track of important
	variables or something, remember that to redefine clean_up so that
	you won't loose any data when it is destructed.

SEE ALSO
	destruct(E)

Help topics available:
add_hook add_weight can_put_and_get clean_up drop
extra_look get heart_beat id init
init_arg is_armour is_money is_weapon long
query_auto_load query_hook query_long query_name query_prevent_move_from_statue
remove_hook reset set_long set_name set_short
short

[START|BACK ]




[ NannyMuds main page | FAQ | Contact us ]

You are guest number 82 since November 2019.
This file was last modified: June 2000.