Re: [CODE] Newbie Snippet --- Loads a "bug" (obj #0, or #1)

Johan.Dustler@EPK.ERICSSON.SE
Date: 03/02/98


> From: Julian Buckley <s348266@STUDENT.UQ.EDU.AU>
>
>        }
>        for(ii = 1; give_obj[ii] != -1; ii++) {
                  ^
                  |
        Change to 0.


>           obj = read_object(give_obj[ii], VIRTUAL);
>             if (obj == NULL)
>               continue;
>           obj_to_char(obj, victim);
>        }
>        switch (GET_CLASS(victim)) {
>        case CLASS_THIEF:
>          tmp = 0;
>          break;
>        case CLASS_WARRIOR:
>          tmp = 1;
>          break;
>        }
>        obj = read_object(tmp, VIRTUAL);
>        if (obj == NULL)
>          return;
>        obj_to_char(obj, victim);

It loads a bug because you tell it to do it. You have to change
the tmp values in the case statement to valid object numbers.

You will also have to add cases for all other classes you may
have, otherwise tmp will be uninitialized for those classes.

Or rewrite it to something like:

  switch (GET_CLASS(victim)) {
    case CLASS_THIEF:
      tmp = some valid object #;
      break;
    case CLASS_WARRIOR:
      tmp = some valid object #;
      break;
    case CLASS_MAGE:
    case CLASS_CLERIC:
    default:
      tmp = 0;
  }

  if (tmp) {
    if (obj = read_object(tmp, VIRTUAL)) {
      obj_to_char(obj, victim);
    } else {
      Print a message or log that specific class item couldn't
      be loaded.
    }
  }

Haven't really worked with the code the last months, so this
may be totaly wrong, but I think it should work.

/Johan


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