Re: [CODE] Running functions from variables

From: Stephen Wolfe (siv@CYBERENET.NET)
Date: 08/09/98


> If ch->func was a type char, let's say its:
>
> "do_something(yahoo, yeh, 1)"
>
> Is there a way I can run that char (ch->func) as a function? Something
> like
 well..it depends..if you mean just have a character command (ie, ACMD)
stored to the character in order to run later then that would be pretty
simple..

first, add the variable to the char_data struct near hunting and memory
and stuff..

struct char_data
{
.
.
  struct char_data *hunting;
+ ACMD(char_func);

then you can assign it like so:

void some_function(struct char_data *ch, int which_func)
{
  ACMD(some_command);   /* declare extern (may not be needed) */
  ACMD(another_command);

  switch (which_func)
  {
    case CASE_1:
      ch->char_func = some_command;
      break;
    case CASE_2:
      ch->char_func = another_command;
      break;
    default:
      log("Something screwed up!");
  }

then you can call the function like so:

  ch->char_func(ch, "arguments go here", subcmd);

that should work..i haven't actually tried this, but i do something
very similar with my events..i'm not even sure if this is what you're
asking for..if you need any more help email me private..

siv


     +------------------------------------------------------------+
     | 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