Re: [CODE]: Loading Objects on Character Creation..

From: Daniel A. Koepke (dkoepke@california.com)
Date: 04/09/99


On Sat, 10 Apr 1999, Ryan Kahn wrote:

> In function do_start:
>   obj_to_char(read_object(12105, REAL), ch);
>   obj_to_char(read_object(12102, REAL), ch);
>   obj_to_char(read_object(12106, REAL), ch);
>   obj_to_char(read_object(12106, REAL), ch);
>   obj_to_char(read_object(12108, REAL), ch);
>
> It compiles clean... but it crashes when someone enters the game.. any
> opinions?

Well, it's very ugly.  And 1210x aren't real numbers, they're virtuals, so
you'll want to change REAL->VIRTUAL.  That will fix the crash, although
writing good code would mean you don't have that problem.  This is all
very old and discussed too many times for me to count.  In fact, tag this
into the WTfaq,

  #define INVENTORY     -1
  #define BAG           -2

  void start_equip(struct char_data * ch)
  {
    const int eq_list[][3] = {
      /* Syntax: quantity, virtual num, location
       * Examples:
       * { 2, 12106, INVENTORY }, loads 2 12106s and places it in inven.
       * { 1, 12105, WEAR_WIELD }, loads a 12105 and wields it
       * { 5, 12105, BAG }, loads 5 12105s and places them in the bag
       */

      /* THIS MUST BE LAST */
      { -1, -1, -1 }
    };
    const obj_vnum bag_vnum = <insert bag vnum>;
    struct object_data * bag, * obj;
    int idx, count;

    bag = read_object(bag_vnum, VIRTUAL);

    for (idx = 0; eq_list[idx][1] != -1; idx++) {
      for (count = 0; count < eq_list[idx][0]; count++) {
        if (!(obj = read_object(eq_list[idx][1], VIRTUAL)))
          break;

        if (eq_list[idx][2] == BAG && bag != NULL)
          obj_to_obj(obj, bag);
        else if (eq_list[idx][2] >= 0)
          equip_char(ch, obj, eq_list[idx][2]);
        else
          obj_to_char(obj, ch);
      }
    }
  }

As always, it's Mailer Code(tm), with the associated terms and conditions.
That is: I wrote it in my mailer, just now.  You don't need to give me
credit for it (just don't take credit away from me and claim you wrote
it).  It isn't tested, so it may not work right, cause crashes, birth
defects, impotence, or your pet gerbil's head to explode.  Don't blame me,
you've been warned.  Anyway, headless gerbil does make a nice light
snack for those crack-o'-dawn programming projects.

(We ought to describe the concept of Mailer Code in the Mailing List FAQ
or the actual FAQ or both, just to make it clear to everyone.)

-dak


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



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