Man chatter

From LSWiki

Jump to: navigation, search

Description

Detailed below are the functions found in the chatter daemon, followed by a brief description of how to use them to set up chatter in rooms.

varargs status add_chatter(string chatter_id, mixed *chatter, int interval,
mixed what, status cycling) 

chatter_id - The chatter daemon keeps track of separate chatters by assigning them each a unique chatter_id. This argument should be a string with some sort of information about the chatter, e.g. "Northlands Wind" or "Camelot Moat".

chatter - Traditionally, this argument has been an array of strings. However, the elements of this can also be closures. The closures will be given the argument of the room the chatter is happening in. An example of *chatter might be:

               ({ "The wind whistles around you.\n",

"Birds chirp in the distance.\n", "The water laps gently at the shore.\n", lambda(({'x}),({#'call_other,'x,"do_stuff"})), }) The first three are fairly easy to understand. The fourth element here is a closure, which will cause the function do_stuff() to be called in every room which is affected by this chatter. The implications of this may not be readily apparent, but it makes it possible for chatter to trigger events and the like. For instance, do_stuff() might look like this in the room's code:

 void do_stuff() {
     tell_room(this_object(),"Fixy is upset!  You all die!\n"); 
     filter_array(all_livings(),#'call_other,"die");
 }

In this case, instead of having a nice chatter message broadcast to the room, everyone who's alive in the room dies. Beginning to see the power of closures in chatter?


interval - This argument sets how many seconds will elapse between each burst of chatter. It can be no smaller than 15, and must be a multiple of 15.

what - This defines which rooms the chatter will occur in. It can either be a room, an array of rooms, or a closure. There are a number of pre-built closures in /lib/chatter_conditions.h which will cause the chatter to occur in rooms of given realms, areas, etc. If you want an area-wide chatter, it is best to use a closure. If you want the chatter to occur in only a single room or a few rooms, it is best to give this argument a room or array of rooms. If add_chatter is called with a chatter_id that already exists and the 'what' argument is not a closure, it will add the room(s) defined by the new add_chatter to the rooms defined in the old add_chatter.

Keep in mind that if you give a closure argument as 'what', the closure will be bound to the object that called add_chatter. This means that things will break if this object is destructed. If you intend to use a closure, it is a good idea to call add_chatter from a daemon or a room that will not remove itself when empty.

It is also possible to give the file name of a room or an array of file names for this argument.


cycling - If this argument is 1, then the chatter will proceed in order and loop back to the beginning once it reaches the end. This is useful if it is important for chatter events to happen in a particular order. The default of 0 will cause the chatter line to be randomly picked from the chatter array each time.


Setting up chatter for your area

If you want chatter to happen only in a single room, build the add_chatter call directly into the room's code. Here's an example:

#include <daemons.h>
#include <My_Area.h>
inherit My_Area_Base;
void create() {
::create();
    set_short("an example room");
    set_long(format("What a boring long description."));
        Chatter_Daemon->add_chatter("Test Chatter", ({
            "The wind whistles by.\n",
            "Trees rustle in the wind.\n",
            "Footsteps echo throughout the canyon.\n", 
        }), 30, this_object() );
 }

To make an entire area chatter, one would write a daemon not unlike this one:

#include <daemons.h>
#include <chatter_conditions.h>
void create() {
	 Chatter_Daemon->add_chatter("Area Chatter", ({
        "Eerie drums beat all around you.\n",
        "The ground shakes.\n",
        "Voices drift by on the wind.\n",
        }), 45, In_Area("My Area") );
}

Once the daemon is created, add a line similar to this to your area's Base.c file:

My_Area_Daemon("chatter")->load();

More on closures

An array of all of the users' environments is filtered through the closure; if '1' is returned, then the chatter message is broadcast to the room. The closures can be combined using the Combine(a,b) closure as defined in chatter_conditions.h. For instance, if you wanted to have a chatter be broadcast to all rooms that are have set_exposure >= Exposure_Open and are in the realm "MyRealm", the appropriate closure would be this:

Combine(Is_Outdoors(Exposure_Open), In_Realm("MyRealm"))

You can embed a 'Combine' closure within another 'Combine' closure to create as many conditions as you desire:

Combine(Is_Outdoors(2),Combine(In_Realm("MyRealm"), In_Area("This Area")))

Personal tools