blob: 7c9592a453fa2f7f81fd99ff4900323748b228e7 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
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
Zesstra715ec202025-07-09 22:18:31 +020010DESCRIPTION
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 User88f12472016-06-24 23:31:02 +020021
Zesstra715ec202025-07-09 22:18:31 +020022 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 User88f12472016-06-24 23:31:02 +020025
Zesstra715ec202025-07-09 22:18:31 +020026 When searching both inventory and environment of this_object(),
27 the numbering is applied linear over both spaces (see examples).
MG Mud User88f12472016-06-24 23:31:02 +020028
Zesstra715ec202025-07-09 22:18:31 +020029 The driver identifies objects by calling the lfun id() in each
30 object.
MG Mud User88f12472016-06-24 23:31:02 +020031
Zesstra715ec202025-07-09 22:18:31 +020032EXAMPLES
MG Mud User88f12472016-06-24 23:31:02 +020033 present("chest");
Zesstra715ec202025-07-09 22:18:31 +020034 --> returns the first 'chest' object in this object.
MG Mud User88f12472016-06-24 23:31:02 +020035
Zesstra715ec202025-07-09 22:18:31 +020036 present("chest 2")
37 --> returns the second 'chest' object in this object.
MG Mud User88f12472016-06-24 23:31:02 +020038
Zesstra715ec202025-07-09 22:18:31 +020039 present("chest 2", 1)
40 --> returns the first 'chest 2' object in this object.
MG Mud User88f12472016-06-24 23:31:02 +020041
Zesstra715ec202025-07-09 22:18:31 +020042 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 User88f12472016-06-24 23:31:02 +020047
Zesstra715ec202025-07-09 22:18:31 +020048 A typical 2.4.5-implementation of the "do <id> <n>" command style
49 is:
MG Mud User88f12472016-06-24 23:31:02 +020050
Zesstra715ec202025-07-09 22:18:31 +020051 void init() { add_action("open_chest", "open"); }
MG Mud User88f12472016-06-24 23:31:02 +020052
Zesstra715ec202025-07-09 22:18:31 +020053 int open_chest (string str) {
54 if (present (str) != this_object ())
55 return 0; /* Not this chest */
56 ...
MG Mud User88f12472016-06-24 23:31:02 +020057 }
58
MG Mud User88f12472016-06-24 23:31:02 +020059
Zesstra715ec202025-07-09 22:18:31 +020060HISTORY
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
68SEE ALSO
69 move_object(E), environment(E), this_object(E), present_clone(E)
MG Mud User88f12472016-06-24 23:31:02 +020070 id(A), init(A)