[DGD]mappings, use of.

The MUD Thingie mud at hal9000.net.au
Tue Apr 13 22:29:08 CEST 1999


> This usually means that your mapping is empty (0).
That is quite possible.

> (i.e. your thinking is alright you probably didn't fill your mapping or
> its is cleared by accident)
Well Im thinking it may not be getting set.  Erm the value of the mapping
that is.

> Send your code for more info....
Here it is, I apologise for the spam.  If you meant send it privately Marc,
I
apologise doubly.
This is my beginning at an attempt at replacing the social_d.c in the
Melville mudlib that Ive been working on and rewriting.
Note it dont do much so far :)  Just the whole mapping thing confused me
before I got any further.  BTW Ive never used restore_object() or
save_object()
before so am not sure I got the right idea.

/* The social server.
   <cut out my huge comment and explanation>
 */

#include <config.h>

/* These hold the actual socials:
   socials_wt is the socials with a target,
   socials_wot is the socials without a target.
   adverbs holds the list of adverbs.
 */
mapping socials_wt ;
mapping socials_wot ;
string  *adverbs ;

/* Read in Social file at start up */
void create() {
    /* If socials file doesnt exist, or there is some error
       in the variables stored, then initialise
       variables so we dont get some sorta horrible
       error.
     */
    if (restore_object(SOCIAL_FILE) == 0) {
        /* No data file - initialise */
     /* These would normally be zeroed
        Just given them values for test reasons.
      */
        socials_wt = (["smile":"$N $vsmile."]);
        socials_wot = (["smile":"$N $vsmile at $T."]);
        adverbs = ({"happily"});
    }
}

/* This function is called from player.c to check for a social command,
   and process it if one is found.
   It handles processing the incoming string, writing to the
   player and room any text if a social command is found,
   plus returns a 1 if successful and a 0 if it isnt.
 */

int do_social (string str) {
    /* The actual social command given */
    string command;
    /* arg2 and arg3 could either not exist, or
       be either an adverb, some extra text or
       a target for the social command
     */
    string arg2;
    string arg3;
    /* Number of arguments passed to this function */
    int number_args;
    /* Array to store the break up of the string passed */
    string *args;

    /* Break up given string */
    args = big_explode(str, " ");
    number_args = sizeof(args);

    /* Assign to string variables */
    if (number_args >= 1)
        command = args[0];
    if (number_args >= 2)
        arg2 = args[1];
    if (number_args >= 3)
        arg3 = args[2];

    /* If it isnt a social command, exit the function - our work here is
done.
       The 0 might have to be a NULL, not sure with the latest
       driver changes.
     */
    /* if (socials_wt[command] == 0 && socials_wot[command] == 0) {
     return 0;
    } */

    /* Now the following works if I put the part of setting the
       values of the mappings in create() inside this function
     */
    write(map_sizeof(socials_wt)+"\n");

    /* Lets find out what these are currently being set to */
    write("Command: " + command + "\n");
    write("Arg2: " + arg2+"\n");
    write("Arg3: " + arg3 + "\n");

    return 1 ;
}



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



More information about the DGD mailing list