blob: 612b3c8cd5f49c34fff521cc090a06e08ddfac56 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstrad59c3892019-11-28 20:53:39 +01002 object first_inventory()
3 object first_inventory(string ob)
4 object first_inventory(object ob)
MG Mud User88f12472016-06-24 23:31:02 +02005
Zesstra715ec202025-07-09 22:18:31 +02006DESCRIPTION
7 Get the first object in the inventory of ob, where ob is
8 either an object or the file name of an object. If ob is not
9 given, the current object is assumed.
MG Mud User88f12472016-06-24 23:31:02 +020010
Zesstra715ec202025-07-09 22:18:31 +020011EXAMPLES
12 This efun is mostly used in the following context:
MG Mud User88f12472016-06-24 23:31:02 +020013
Zesstra715ec202025-07-09 22:18:31 +020014 for(ob=first_inventory(container);ob;ob=next_inventory(ob)) {
15 <some actions>
16 }
MG Mud User88f12472016-06-24 23:31:02 +020017
Zesstra715ec202025-07-09 22:18:31 +020018 If you use such calls frequently then it would be very useful
19 to use a preprocessor macro:
Zesstrad59c3892019-11-28 20:53:39 +010020
Zesstra715ec202025-07-09 22:18:31 +020021 #define FORALL(x, y) for(x=first_inventory(y);x;x=next_inventory(x))
Zesstrad59c3892019-11-28 20:53:39 +010022
Zesstra715ec202025-07-09 22:18:31 +020023 So the above example could be written like this:
Zesstrad59c3892019-11-28 20:53:39 +010024
Zesstra715ec202025-07-09 22:18:31 +020025 FORALL(ob, container) {
26 <some actions>
27 }
Zesstrad59c3892019-11-28 20:53:39 +010028
Zesstra715ec202025-07-09 22:18:31 +020029 Warning: If the object ob is moved inside <some actions>, then
30 next_inventory() will return an object from the new inventory
31 of ob. You also shouldn't call next_inventory() on destructed
32 objects. So in case of move and/or destruction the following
33 is a better solution:
MG Mud User88f12472016-06-24 23:31:02 +020034
Zesstra715ec202025-07-09 22:18:31 +020035 for(ob=first_inventory(container);ob;) {
36 next=next_inventory(ob);
37 <some actions and moves and/or removes>
38 ob=next;
39 }
MG Mud User88f12472016-06-24 23:31:02 +020040
Zesstra715ec202025-07-09 22:18:31 +020041
42SEE ALSO
43 next_inventory(E), all_inventory(E), environment(E),
44 deep_inventory(E)