Difference between revisions of "Manual:DIL Manual/load()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
 
(checked against the compiler and the interpreter; example compiles)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
= load() =
 +
'''Function''' (unitptr). Makes a new NPC or object from its zone definition.
  
 +
load(sym : string) : unitptr
  
−
<span id="bfload"></span>
+
Creates a new copy of the NPC or object defined as <code>sym</code>, <code>"name@zone"</code>, and puts it inside the unit running the program: in an NPC's inventory, in an object, or in a room. Move it where it should be with [[Manual:DIL Manual/link()|link()]].
  
−
unitptr load ( s : string )
+
== Parameters ==
−
    s : Symbolic name of unit.
+
{| class="wikitable"
−
    return: A pointer to the unit, or null
+
! Name !! Type !! Meaning
−
    Example: load("garlic@midgaard")
+
|-
−
    The loaded unit is automatically placed inside the object
+
| sym || string || The symbolic name, <code>"name@zone"</code> (or <code>"zone/name"</code>). Case doesn't matter.
−
    which loaded it. Use for example the link command to move
+
|}
−
    it into other units.
+
 
 +
== Returns ==
 +
The new unit, or null when it couldn't be made: no such unit (the log says "DIL load(...) - unit does not exist."), or a room ("DIL trying to load a room ..."). A string variable that has never been given a value makes the call fail.
 +
 
 +
== Notes ==
 +
* The reset limits of the zone don't apply: every call makes another one.
 +
* The new unit's DIL programs start at once, before <code>load()</code> returns.
 +
* An NPC loaded by a program on an NPC or object starts inside that unit; <code>link()</code> it to the room.
 +
* Rooms can't be loaded.
 +
* A unit variable is cleared at the next <code>wait</code> or <code>pause</code>: give or move the unit before waiting, or <code>secure</code> it.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin baker_gift();
 +
var
 +
  u : unitptr;
 +
code
 +
{
 +
  :loop:
 +
  wait(SFB_CMD, command("bow") and (activator.type == UNIT_ST_PC));
 +
  u := load("bread@midgaard");
 +
  if (u == null)
 +
      goto loop;
 +
  act("$1n gives $3n $2n.", A_SOMEONE, self, u, activator, TO_NOTVICT);
 +
  act("$1n gives you $2n.", A_SOMEONE, self, u, activator, TO_VICT);
 +
  link(u, activator);
 +
  goto loop;
 +
}
 +
dilend
 +
</pre>
 +
An NPC that hands a loaf of bread to each player who bows.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/clone()|clone()]]
 +
* [[Manual:DIL Manual/link()|link()]]
 +
* [[Manual:DIL Manual/destroy()|destroy()]]
 +
* [[Manual:DIL Manual/findsymbolic()|findsymbolic()]]
 +
* [[Manual:DIL Manual/loadcount|loadcount]]

Latest revision as of 23:18, 14 November 2026

load()

Function (unitptr). Makes a new NPC or object from its zone definition.

load(sym : string) : unitptr

Creates a new copy of the NPC or object defined as sym, "name@zone", and puts it inside the unit running the program: in an NPC's inventory, in an object, or in a room. Move it where it should be with link().

Parameters

Name Type Meaning
sym string The symbolic name, "name@zone" (or "zone/name"). Case doesn't matter.

Returns

The new unit, or null when it couldn't be made: no such unit (the log says "DIL load(...) - unit does not exist."), or a room ("DIL trying to load a room ..."). A string variable that has never been given a value makes the call fail.

Notes

  • The reset limits of the zone don't apply: every call makes another one.
  • The new unit's DIL programs start at once, before load() returns.
  • An NPC loaded by a program on an NPC or object starts inside that unit; link() it to the room.
  • Rooms can't be loaded.
  • A unit variable is cleared at the next wait or pause: give or move the unit before waiting, or secure it.

Example

dilbegin baker_gift();
var
   u : unitptr;
code
{
   :loop:
   wait(SFB_CMD, command("bow") and (activator.type == UNIT_ST_PC));
   u := load("bread@midgaard");
   if (u == null)
      goto loop;
   act("$1n gives $3n $2n.", A_SOMEONE, self, u, activator, TO_NOTVICT);
   act("$1n gives you $2n.", A_SOMEONE, self, u, activator, TO_VICT);
   link(u, activator);
   goto loop;
}
dilend

An NPC that hands a loaf of bread to each player who bows.

See also