MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
| 2 | object present(string str) |
| 3 | object present(string str, int n) |
| 4 | object present(string str, object env) |
| 5 | object present(string str, int n, object env) |
| 6 | |
| 7 | object present(object ob) |
| 8 | object present(object ob, object env) |
| 9 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 10 | DESCRIPTION |
| 11 | This efun checks if an object is present in a given environment. |
| 12 | The object is identified by id <str> or by an object <ob>. This |
| 13 | latter form of the efun can be used as a fast way to test for the |
| 14 | presence of a known object. |
| 15 | |
| 16 | When searching objects by id, the efun by default returns the first |
| 17 | object found matching the id. In order to search for other than the |
| 18 | first object, a number can be specified either directly as the |
| 19 | argument <n>, or implicetely inside the <str> in the form "<id> |
| 20 | <n>". |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 21 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 22 | By default, the efun searches first in the inventory of |
| 23 | this_object(), then in its environment. However, if <env> is given, |
| 24 | the efun searches just inside <env>. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 25 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 26 | When searching both inventory and environment of this_object(), |
| 27 | the numbering is applied linear over both spaces (see examples). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 28 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 29 | The driver identifies objects by calling the lfun id() in each |
| 30 | object. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 31 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 32 | EXAMPLES |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 33 | present("chest"); |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 34 | --> returns the first 'chest' object in this object. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 35 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 36 | present("chest 2") |
| 37 | --> returns the second 'chest' object in this object. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 38 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 39 | present("chest 2", 1) |
| 40 | --> returns the first 'chest 2' object in this object. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 41 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 42 | Assume there is one "chest" inside the current object, and |
| 43 | two in its environment: |
| 44 | present("chest", 1) -> returns the chest inside |
| 45 | present("chest", 2) -> returns the first chest outside |
| 46 | present("chest", 3) -> returns the second chest outside |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 47 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 48 | A typical 2.4.5-implementation of the "do <id> <n>" command style |
| 49 | is: |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 50 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 51 | void init() { add_action("open_chest", "open"); } |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 52 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 53 | int open_chest (string str) { |
| 54 | if (present (str) != this_object ()) |
| 55 | return 0; /* Not this chest */ |
| 56 | ... |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 57 | } |
| 58 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 59 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 60 | HISTORY |
| 61 | LDMud 3.2.11/3.3.610 introduced the (str, n) argument form. |
| 62 | LDMud 3.3.713 modified the <n> search behaviour so that the |
| 63 | numbering is applied over both inventory and environment |
| 64 | together. Before, the numbering was individual in each |
| 65 | space, leading to situations where low-numbered objects in the |
| 66 | environment were hidden by those in the inventory. |
| 67 | |
| 68 | SEE ALSO |
| 69 | move_object(E), environment(E), this_object(E), present_clone(E) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 70 | id(A), init(A) |