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

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the compiler and the interpreter; example compiles)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
−
unitptr findroom ( s : string )
+
= findroom() =
−
    s : Symbolic name of room.
+
'''Function''' (unitptr). Finds a room by its symbolic name.
−
    return: A pointer to the room, or null
 
−
    Example: findroom("inn@udgaard")
 
  
−
Will return the unitptr to the room. If the symbolic name is not a room then NULL will
+
findroom(sym : string) : unitptr
−
be returned. Using findsymbolic(#) is equally efficient and does the same except it
+
 
−
returns any type. This function is really mostly here for historical reasons.
+
Returns the room defined as <code>sym</code>, <code>"name@zone"</code>, for example to move someone there with [[Manual:DIL Manual/link()|link()]].
 +
 
 +
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| sym || string || The room's symbolic name, <code>"name@zone"</code> (or <code>"zone/name"</code>). Case doesn't matter.
 +
|}
 +
 
 +
== Returns ==
 +
The room, or null when there is no room of that name: an unknown zone or name, a name without <code>@zone</code>, or the symbolic name of an NPC or object.
 +
 
 +
== Notes ==
 +
* The result can't take a field directly: <code>findroom(s).title</code> doesn't compile. Put it in a variable first.
 +
* A unit variable doesn't keep its value across a <code>wait</code> or <code>pause</code>; look the room up again afterwards.
 +
* To move a character through an exit, use <code>exec("north", u)</code>; use <code>link()</code> with findroom where no exit leads.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin to_temple(pc : unitptr);
 +
var
 +
  rm : unitptr;
 +
code
 +
{
 +
  rm := findroom("temple@udgaard");
 +
  if (rm == null)
 +
  {
 +
      log("to_temple: no temple@udgaard");
 +
      quit;
 +
  }
 +
  act("$1n disappears in a flash of light.", A_SOMEONE, pc, null, null, TO_ROOM);
 +
  link(pc, rm);
 +
  act("$1n appears in a flash of light.", A_SOMEONE, pc, null, null, TO_ROOM);
 +
  quit;
 +
}
 +
dilend
 +
</pre>
 +
Moves a character to the temple of Udgaard, as death.zon does.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/findsymbolic()|findsymbolic()]]
 +
* [[Manual:DIL Manual/findzone()|findzone()]]
 +
* [[Manual:DIL Manual/link()|link()]]
 +
* [[Manual:DIL Manual/exec()|exec()]]

Latest revision as of 23:18, 14 November 2026

findroom()

Function (unitptr). Finds a room by its symbolic name.

findroom(sym : string) : unitptr

Returns the room defined as sym, "name@zone", for example to move someone there with link().

Parameters

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

Returns

The room, or null when there is no room of that name: an unknown zone or name, a name without @zone, or the symbolic name of an NPC or object.

Notes

  • The result can't take a field directly: findroom(s).title doesn't compile. Put it in a variable first.
  • A unit variable doesn't keep its value across a wait or pause; look the room up again afterwards.
  • To move a character through an exit, use exec("north", u); use link() with findroom where no exit leads.

Example

dilbegin to_temple(pc : unitptr);
var
   rm : unitptr;
code
{
   rm := findroom("temple@udgaard");
   if (rm == null)
   {
      log("to_temple: no temple@udgaard");
      quit;
   }
   act("$1n disappears in a flash of light.", A_SOMEONE, pc, null, null, TO_ROOM);
   link(pc, rm);
   act("$1n appears in a flash of light.", A_SOMEONE, pc, null, null, TO_ROOM);
   quit;
}
dilend

Moves a character to the temple of Udgaard, as death.zon does.

See also