MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 2 | object first_inventory() |
| 3 | object first_inventory(string ob) |
| 4 | object first_inventory(object ob) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 5 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 6 | DESCRIPTION |
| 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 10 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 11 | EXAMPLES |
| 12 | This efun is mostly used in the following context: |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 13 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 14 | for(ob=first_inventory(container);ob;ob=next_inventory(ob)) { |
| 15 | <some actions> |
| 16 | } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 17 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 18 | If you use such calls frequently then it would be very useful |
| 19 | to use a preprocessor macro: |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 20 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 21 | #define FORALL(x, y) for(x=first_inventory(y);x;x=next_inventory(x)) |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 22 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 23 | So the above example could be written like this: |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 24 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 25 | FORALL(ob, container) { |
| 26 | <some actions> |
| 27 | } |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 28 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 29 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 34 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 35 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 40 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 41 | |
| 42 | SEE ALSO |
| 43 | next_inventory(E), all_inventory(E), environment(E), |
| 44 | deep_inventory(E) |