Re: [Question] dig/bury

From: Mike Breuer (mbreuer@new.rr.com)
Date: 04/02/01


> > I noticed an odd bug in digging/searching up buried items recently, it seems
> > to search the entire world for buried items and uncovers them, can anybody
> > help me with where the loop or whatnot is going wrong?
> >
> >   obj = world[IN_ROOM(ch)].contents;
> >
> >   while (obj != NULL) {
> >     if (IS_BURIED(obj)) {
> >        /* Remove the buried bit so the player can see it. */
>         <...snip...>
> >        }
> >        else {
> >           SET_BIT(GET_OBJ_EXTRA(obj), ITEM_BURIED);
> >        }
> >     }
> >     /* go to the next obj */
> >     obj = obj->next;
> >   }
>
>
> Don't you want obj->next_content (next in room) and not ->next?  What I
> really want to know is why every other item isn't buried?
> --Angus

Part of the code that you snipped out was calling obj_from_room(obj) and
obj_to_char(...).  This will modify the obj->next_content pointer, so that
the obj = obj->next_content at the bottom will cause undesired behavior.
You need to grab the next_content pointer before it is altered and use it
for the next iteration of the loop.  I posted a message about this recently,
and there are many examples of for loops in the stock code that accomplish
this.

To modify the loop, declare an obj_data pointer called "next", and assign
next = obj->next_content as the first line in your while loop.  Modify the
assignment at the bottom of your loop to be: obj = next;

As to your last question, if you are referring to the removal of the
ITEM_BURIED bit and then setting it again in the else clause,  it seems to
me THAT code needs to remain as written.

Mike

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/05/01 PST