Re: Equipment problem

From: Hades (tourach@cyber1.servtech.com)
Date: 04/11/96


> 
> Ok, this may seem a little strange, but I'm trying to write a function that
> (among other things) removes and deletes all of a player's equipment and
> inventory.  I looked in handler.c and act.obj.c, and have come up with the
> following code:
> 
>   /* Remove & delete all objects and equipment */
>   /* for (i=0; i < NUM_WEARS; i++)
>     if (GET_EQ(ch, i)) extract_obj(unequip_char(ch, i));
>     
>   while(ch->carrying) { 
>     obj = obj->next;
>     extract_obj(obj);
>   } */ 
> 

while(ch->carrying) {
  obj = obj->next;
  etxract_obj(obj);
}
You are moving to the next object before it's extracted. Um also... I just
noticed this. What is obj? It was never set to anything. Sure the while loop
will work, but obj = nothing, and obj->next is very very bad. To make this
work it should be:

while(ch->carrying) {
  obj = ch->carrying;
  extract_obj(obj);
}

That's a bit ugly though. More code but looks right is:
for(obj = ch->carrying; obj; obj = tobj) {
  tobj = obj->next;
  obj_from_char(obj);
  extract_obj(obj);
}

That's the nicest way to do it.



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