blob: dd48ec21f2422f65e7c37e4d25ab8098adac1d7b [file] [log] [blame]
Zesstrad59c3892019-11-28 20:53:39 +01001SYNOPSIS
Zesstra715ec202025-07-09 22:18:31 +02002 object clone_object(string name, ...)
3 object clone_object(object template, ...)
MG Mud User88f12472016-06-24 23:31:02 +02004
Zesstra715ec202025-07-09 22:18:31 +02005DESCRIPTION
6 Clone a new object from definition <name>, or alternatively from
7 the object <template>. In both cases, the new object is given
8 an unique name and returned.
MG Mud User88f12472016-06-24 23:31:02 +02009
Zesstra715ec202025-07-09 22:18:31 +020010 The original used for cloning, called blueprint, should not be
11 used in the system, just for cloning. The cloned objects
12 contain only the data but the blueprint also the function code.
13 The blueprint is the one without a unique number at the end of
14 the object's name. The clone_object() function never
15 returns a blue print.
MG Mud User88f12472016-06-24 23:31:02 +020016
Zesstra715ec202025-07-09 22:18:31 +020017 If the <name> or <template> designates a cloned object itself,
18 the system looks up the blueprint object _by name_.
Zesstrad59c3892019-11-28 20:53:39 +010019
Zesstra715ec202025-07-09 22:18:31 +020020 Any further arguments will be passed to the H_CREATE_CLONE
21 hook to initialize the cloned object.
Zesstrad59c3892019-11-28 20:53:39 +010022
Zesstra715ec202025-07-09 22:18:31 +020023 If the blueprint exists and has a heart_beat(), clone_object()
24 turns it off.
25
26 Note that the pathname must be complete, which means there are no
27 relative paths allowed.
28
29 If strict euids are enforced, the cloning object must have
30 a non-zero euid.
Zesstrad59c3892019-11-28 20:53:39 +010031
32
Zesstra715ec202025-07-09 22:18:31 +020033 -- Variable Initialization --
Zesstrad59c3892019-11-28 20:53:39 +010034
Zesstra715ec202025-07-09 22:18:31 +020035 In general, variables are initialized for blueprints and clones alike
36 with a call to the internal lfun __INIT().
37
38 However, if #pragma share_variables is in effect (either explicitely
39 given in the source or implicitly as runtime option), the values for
40 a clone's uninitialized variables are taken from the _current_
41 variables of the object's blueprint.
Zesstrad59c3892019-11-28 20:53:39 +010042
Zesstra715ec202025-07-09 22:18:31 +020043 In the absence of share_variables, variables without explicit
44 initializers are initialized to 0.
Zesstrad59c3892019-11-28 20:53:39 +010045
46
Zesstra715ec202025-07-09 22:18:31 +020047EXAMPLES
48 // Clone a torch (filename in non-compat format)
49 object torch;
50 torch = clone_object("/obj/torch");
Zesstrad59c3892019-11-28 20:53:39 +010051
Zesstra715ec202025-07-09 22:18:31 +020052 // Clone two keys (filename in compat format)
Zesstrad59c3892019-11-28 20:53:39 +010053 object key1, key2;
54 key1 = clone_object(load_object("obj/key"));
55 key2 = clone_object(key1);
56
57 // Create a specialized weapons blueprint.
58 --- std/weapon.c: ---
59 #pragma share_variables
60 int weapon_class = 1;
61
62 --- broadsword.c: ---
63 inherit "/std/weapon";
64
65 int create() {
66 weapon_class = 2;
67 replace_program("/std/weapon");
68 }
69
70
Zesstra715ec202025-07-09 22:18:31 +020071HISTORY
72 Modified in LDMud 3.2.6 to take an object as argument.
73 LDMud 3.3.378 consolidated the variable initialization with the
74 share_variables pragma.
Zesstrad59c3892019-11-28 20:53:39 +010075
Zesstra715ec202025-07-09 22:18:31 +020076SEE ALSO
Zesstrad59c3892019-11-28 20:53:39 +010077 blueprint(E), clonep(E), destruct(E), clones(E), load_name(E),
78 load_object(E), move_object(E), uids(C), program_name(E), pragma(LPC)