View Single Post
Old 05-10-2004, 06:44 PM   #2
erdos
 
Posts: n/a
AFKMud, being a SMAUG derivative, has a feature whereby multiple copies of an object will coalesce to save system resources if they're grouped  (thus if you have a sword in inventory and someone gives you an identical sword, the new sword is purged and the old sword gets its "count" parameter incremented).  Obviously, if you want to move an object to the floor and still operate on it afterwards, you must anticipate such behavior.  Code such as
[code] obj_to_room( obj, room);
do_get( ch, obj );[/quote]
will crash if the obj pointer becomes invalid due to the coalescing;  the proper code would be
[code] obj = obj_to_room( obj, room );
do_get( ch, obj );[/quote]
or, if you want, even simply
[code] do_get( ch, obj_to_room( obj, room ) );
[/quote](although this slightly simpler still leaves the obj pointer possibly invalid and thus would have to be the last thing using that pointer)

[note that do_get obviously is misused above; this is done on purpose for the sake of making the results clearer]
  Reply With Quote