Sure!  I suppose I just want (wanted, now; I will inevitably change it now to 
something else) to
keep the switch because that's what it came with.

Here's what the switch does:

switch(ev->action)
                        {
                         case ACTION_PRINT:
                                if((!ev->args[0]) || (!ev->argv[0])) {
                                        kill_event
                                }
                                send_to_char(ev->args[0], ev->argv[0]);
                                break;
                         case ACTION_FUNCTION:
                                if(!ev->args[0])
                                {
                                    kill_event
                                }
                                do_function(ev->argv[0], ev->do_fun, 
ev->args[0]);
                                break;
                         case ACTION_WAIT:
                                if(!ev->argv[0]) {
                                        kill_event
                                }
                                WAIT_STATE((CHAR_DATA *)ev->argv[0],
PULSE_PER_SECOND*ev->argi[0]);
                                break;
                         case ACTION_ACT:
                                if(!ev->args[0] || !ev->argv[0]) {
                                        kill_event
                                }
                                act(ev->args[0], ev->argv[0], ev->argv[1],
ev->argv[2],ev->argi[0]);
                                break;
                         case ACTION_KILLMENU: (my own custom action for menus)
                                if(!ev->argv[0] || !ev->argv[1])
                                {
                                        kill_event
                                        break;
                                }
                                CHAR_DATA *ch = (CHAR_DATA *)ev->argv[0];
                                MENU_DATA *menu = (MENU_DATA *)ev->argv[1];

                                ch_printf(ch, "Killing menu %s--menu 
expired.\n\r", menu->name);
                                menu_from_char(ch, menu);
                                break;
                        }

What I might end up doing is replacing the above with, in conjunction with an 
updated structure:

struct event_action_type
{
    char *name;
    sh_int *pea; //PEA!!  Pointer-to-Event-Action [number]
<some function pointer>
};

and then:

const struct event_action_type event_action_table[] =
{
    {"print", &ea_print, event_print},
    {"wait", &ea_wait, event_wait},
    {"act", &ea_act, event_act},
    {"function", &ea_function, event_function},
    {"kill_menu", &ea_killmenu, event_killmenu},
    {"NULL", NULL}
};

And then simply dispatch the function for the event:

<however this is done>

Actually, I have no idea how this is done, come to think of it.  Would I do a 
"void *fun"; in
the struct declaration, do "&event_print" in the table,  and then to dispatch 
the function, do
"*event_action_table[ev->action].fun;" ?

-- Jeremy

----- Original Message ----- 
From: "Chad Simmons" <[EMAIL PROTECTED]>
To: "Jeremy Hill" <[EMAIL PROTECTED]>
Cc: <[email protected]>
Sent: Saturday, August 30, 2003 12:43 PM
Subject: Re: More describable event actions


>
> --- Jeremy Hill <[EMAIL PROTECTED]> wrote:
> [SNIP]
> > I decided to move the actions into a table that looks like (structure and
> > table):
> > struct event_action_type
> > {
> >     char *name;
> >     sh_int *pea; //Pointer-to-Event-Action [number]
> > };
> >
> > const struct event_action_type event_action_table[] =
> > {
> >     {"print", &ea_print},
> >     {"wait", &ea_wait},
> >     {"act", &ea_act},
> >     {"function", &ea_function},
> >     {"kill_menu", &ea_killmenu},
> >     {"NULL", NULL}
> > };
>
>
> Looks good so far....
>
>
> [SNIP]
>
> >
> > In the meantime, I have run into a serious problem.  In event_update, a
> > switch statement is used
> > to see what the ev->action is.  My cases are ea_print, ea_wait, etc, but I
> > cannot use them as
> > case labels.  Eg.:
> >
> > switch (ev->action)
> >     case ea_print:
> >
> > This obviously won't work.
> [SNIP]
>
> Hrm.. Just curious, but what do you need this switch statement for?? I
> shouldn't think you need it, as you already have a function pointer for what
> you want the event to do, so just call the event's function and move on to the
> next one..
>
> If you can show what you're trying to do in this switch, I may be able to
> suggest a better design..
>
> ~Kender
>
> =====
> -----BEGIN GEEK CODE BLOCK-----
> Version 3.1
> GCS/L/C/O d-(+) s++: a-- C+++$>++++ UBLS++++$
> P+++(--)$ L+++>++++ E--- W+>++$ N !o K? w(--) !O
> M- !V PS+ PE(++) Y+ PGP->+ t+ 5 X+() R(+) tv+@
> b++(+++) !DI+++ D G(-) e>+++$ h---() r+++ y+++
> ------END GEEK CODE BLOCK------
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com


Reply via email to