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

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="bplink"></span>
+
= link() =
−
  link ( u : unitptr, t : unitptr )
+
'''Procedure.''' Moves a unit into another unit, with no checks and no messages.
−
    u : Unit to link.
+
 
−
    t : Unit to link into.
+
  link(u : unitptr, into : unitptr)
−
    result: Link a unit into another unit hierarchy. (Automatically
+
 
−
            unequipps if equipped).
+
<code>link</code> puts <code>u</code> inside <code>into</code>: a character into a room, an object into a container or into a character's inventory, and so on. It is a plain move: there are no messages, and no checks of position, doors, exits, weight or capacity. Give the messages yourself with <code>act()</code>.
−
<span id="bplink"></span>
+
 
−
link ( u : unitptr, t : unitptr )
+
To move an NPC through an exit, use <code>exec("north", self)</code> instead, so that it is an ordinary move, then check <code>self.outside</code>. Use <code>link</code> where there is no exit (teleports, magic, a ship moving between rooms).
−
    u : Unit to link.
+
 
−
    t : Unit to link into.
+
== Parameters ==
−
    result: Link a unit into another unit hierarchy. (Automatically
+
{| class="wikitable"
−
            unequipps if equipped).
+
! Name !! Type !! Meaning
 +
|-
 +
| u || unitptr || The unit to move.
 +
|-
 +
| into || unitptr || Where to put it.
 +
|}
 +
 
 +
== Notes ==
 +
* Nothing happens when either is null, when <code>into</code> is <code>u</code> itself or is inside <code>u</code>, or when <code>u</code> is a room and <code>into</code> isn't. <code>findroom()</code> returns null for a room that doesn't exist, so <code>link(pc, findroom(...))</code> does nothing then.
 +
* An object that is worn or wielded is taken off first.
 +
* Programs that wait for someone to walk in or out don't hear about it, and a player moved into a room doesn't see it until they look: <code>exec("look", pc)</code>.
 +
* When the program has <code>secure</code>d <code>u</code> and moves it out of its surroundings, the secure fires at the next wake.
 +
* In a <code>while</code> loop over <code>u.next</code>, the next unit after <code>link</code> is in the other place. Use <code>foreach()</code> for a loop that moves units.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin send_home(pc : unitptr);
 +
var
 +
  home : unitptr;
 +
code
 +
{
 +
  home := findroom(pc.hometown);
 +
  if (home == null)
 +
      return;
 +
 
 +
  act("$1n vanishes in a flash of light!", A_HIDEINV, pc, null, null, TO_ROOM);
 +
  link(pc, home);
 +
  act("$1n materializes.", A_HIDEINV, pc, null, null, TO_ROOM);
 +
  exec("look", pc);
 +
  return;
 +
}
 +
dilend
 +
</pre>
 +
Sends a player to their home town, with messages in both rooms. Adapted from basis.zon.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/exec()|exec()]]
 +
* [[Manual:DIL Manual/findroom()|findroom()]]
 +
* [[Manual:DIL Manual/act()|act()]]
 +
* [[Manual:DIL Manual/foreach()|foreach()]]
 +
* [[Manual:DIL Manual/outside|outside]]
 +
* [[Manual:DIL Manual/unequip()|unequip()]]

Latest revision as of 23:23, 14 November 2026

link()

Procedure. Moves a unit into another unit, with no checks and no messages.

link(u : unitptr, into : unitptr)

link puts u inside into: a character into a room, an object into a container or into a character's inventory, and so on. It is a plain move: there are no messages, and no checks of position, doors, exits, weight or capacity. Give the messages yourself with act().

To move an NPC through an exit, use exec("north", self) instead, so that it is an ordinary move, then check self.outside. Use link where there is no exit (teleports, magic, a ship moving between rooms).

Parameters

Name Type Meaning
u unitptr The unit to move.
into unitptr Where to put it.

Notes

  • Nothing happens when either is null, when into is u itself or is inside u, or when u is a room and into isn't. findroom() returns null for a room that doesn't exist, so link(pc, findroom(...)) does nothing then.
  • An object that is worn or wielded is taken off first.
  • Programs that wait for someone to walk in or out don't hear about it, and a player moved into a room doesn't see it until they look: exec("look", pc).
  • When the program has secured u and moves it out of its surroundings, the secure fires at the next wake.
  • In a while loop over u.next, the next unit after link is in the other place. Use foreach() for a loop that moves units.

Example

dilbegin send_home(pc : unitptr);
var
   home : unitptr;
code
{
   home := findroom(pc.hometown);
   if (home == null)
      return;

   act("$1n vanishes in a flash of light!", A_HIDEINV, pc, null, null, TO_ROOM);
   link(pc, home);
   act("$1n materializes.", A_HIDEINV, pc, null, null, TO_ROOM);
   exec("look", pc);
   return;
}
dilend

Sends a player to their home town, with messages in both rooms. Adapted from basis.zon.

See also