DGEvents SWITCH update

From: Chris Jacobson (fear@ATHENET.NET)
Date: 09/14/98


On 9/14/98 10:58 PM, The Fractal Dimension Administration
(fracdime@geocities.com) stated:

>DG-Scripts can be attached not only to mobs but also objects and
>rooms.  Scripts have a few more commands than mobprogs does and has
>sophisticated loop-handling, variables, and a events-based scripting
>system meaning you can add delays (pauses) between commands instead
>of executing them instantaneously one after the other like MobProgs.

BTW the switch in the current version of DGScripts, which I wrote, is
"bugged".  I fixed it up a long time ago but never bothered to tell
anyone :-).

The bug is that it builds a comparison for every CASE instance it checks
against.  This is improper, especially when dealing with random.# as your
case instance.

Note: these aren't patchable snippets.  You'll have to fix up your
version based on how it compares to my version.

Find find_case in your script engine file:
/*
 * scans for a case/default instance
 * returns the line containg the correct case instance, or the last
 * line of the trigger if not found.
 */
CmdlistElement *find_case(Trigger *trig, CmdlistElement *cl, ScriptObject
* go, Script *sc, char *cond) {
        CmdlistElement *c;
        char *p, *buf;

        if (!(cl->next))
                return cl;

        for (c = cl->next; c && c->next; c = c->next) {
                for (p = c->cmd; *p && isspace(*p); p++);

                if (!strn_cmp("while ", p, 6) || !strn_cmp("switch", p, 6))
                        c = find_done(c);
                else if (!strn_cmp("case ", p, 5)) {
                        buf = get_buffer(MAX_STRING_LENGTH);
                        eval_op("==", cond, p + 5, buf, go, sc, trig);
                        if (*buf && *buf != '0') {
                                release_buffer(buf);
                                return c;
                        }
                        release_buffer(buf);
                } else if (!strn_cmp("default", p, 7))  return c;
                else if (!strn_cmp("done", p, 3))               return c;
                if (!c->next)                                                   return c;
        }
        return c;
}



In script_driver, find the "switch" handler:

                } else if (!strn_cmp("switch ", p, 7)) {
                        char *buf = get_buffer(MAX_STRING_LENGTH);
                        eval_expr(p + 7, buf, go, sc, trig);
                        cl = find_case(trig, cl, go, sc, buf);
                        release_buffer(buf);
                } else if (!strn_cmp("end", p, 3)) {


- Chris Jacobson


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST