Difference between revisions of "Manual:DIL Manual/exit to"

From DikuMUD Wiki
Jump to navigation Jump to search
(Created page with "= exit_to = The '''exit_to''' field is a read-only array field available on room units that provides access to the destination rooms for each direction exit. == Syntax == r...")
 
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
 
= exit_to =
 
= exit_to =
 +
'''Field''' (unitptr, read-only; units: rooms).
  
−
The '''exit_to''' field is a read-only array field available on room units that provides access to the destination rooms for each direction exit.
+
room.exit_to[dir] : unitptr
  
−
== Syntax ==
+
The room that the exit in direction <code>dir</code> leads to, or null when the room has no exit that way. <code>dir</code> is a direction from vme.h: <code>NORTH</code> (0), <code>EAST</code>, <code>SOUTH</code>, <code>WEST</code>, <code>UP</code>, <code>DOWN</code>, <code>NORTHEAST</code>, <code>NORTHWEST</code>, <code>SOUTHEAST</code>, <code>SOUTHWEST</code> (9); <code>MAX_EXIT</code> is the last.
−
room.exit_to[direction]
 
  
−
== Field Access ==
+
== Notes ==
−
{| class="wikitable"
+
* It fails when the unit is not a room (an object, a character, null) and when <code>dir</code> is outside 0 to <code>MAX_EXIT</code>. A failed value is false in an <code>if</code>, so <code>if (room.exit_to[dir])</code> is a safe test.
−
! Access !! Type !! Description
+
* It can't be assigned (vmc: "Illegal lvalue"). Make or change exits with [[Manual:DIL Manual/setroomexit()|setroomexit()]].
−
|-
+
* Fields can be read on the result directly: <code>self.outside.exit_to[dir].movement</code> works.
−
| room.exit_to[direction] || unitptr || The destination room for the specified direction
+
* To move an NPC through an exit, use <code>exec("north", self)</code> (an ordinary move, with its messages and checks) rather than <code>link(self, room.exit_to[NORTH])</code>.
−
|}
 
  
−
== Parameters ==
+
== Example ==
−
{| class="wikitable"
+
<pre>
−
! Parameter !! Type !! Description
+
dilbegin string exit_list(room : unitptr);
−
|-
+
var
−
| direction || integer || Direction index (NORTH, EAST, SOUTH, WEST, UP, DOWN)
+
  dir : integer;
−
|}
+
  sl : stringlist;
 +
  buf : string;
 +
code
 +
{
 +
  sl := DIR_SL_SHORT;
 +
  dir := NORTH;
 +
  while (dir <= MAX_EXIT)
 +
  {
 +
      if (room.exit_to[dir])
 +
        buf := buf + sl.[dir] + " ";
 +
      dir := dir + 1;
 +
  }
 +
  return (buf);
 +
}
 +
dilend
 +
</pre>
 +
Lists a room's exits as "n e u ", as the exit line in baselook.zon does (which also skips hidden ones).
  
−
== Return Value ==
+
== See also ==
−
Returns a unit pointer to the destination room:
+
* [[Manual:DIL Manual/exit names|exit_names]]
−
* '''unitptr''' - The destination room unit if an exit exists in that direction
+
* [[Manual:DIL Manual/exit info|exit_info]]
−
* '''null''' - If no exit exists in that direction
+
* [[Manual:DIL Manual/exit key|exit_key]]
−
* '''fail''' - If the room unit is invalid or the direction index is out of range
+
* [[Manual:DIL Manual/exit diff|exit_diff]]
−
 
+
* [[Manual:DIL Manual/setroomexit()|setroomexit()]]
−
== Direction Constants ==
 
−
The direction parameter accepts any of the following constants defined in values.h or vme.h:
 
−
 
 
−
{| class="wikitable"
 
−
! Constant !! Value !! Description
 
−
|-
 
−
| NORTH || 0 || North direction
 
−
|-
 
−
| EAST || 1 || East direction
 
−
|-
 
−
| SOUTH || 2 || South direction
 
−
|-
 
−
| WEST || 3 || West direction
 
−
|-
 
−
| UP || 4 || Up direction
 
−
|-
 
−
| DOWN || 5 || Down direction
 
−
|}
 
−
 
 
−
== Examples ==
 
−
=== Basic Exit Check ===
 
−
dilbegin check_exits(room : unitptr);
 
−
code
 
−
{
 
−
    if (room.exit_to[NORTH] != null) {
 
−
      send("There is an exit to the north.");
 
−
    }
 
−
    if (room.exit_to[SOUTH] == null) {
 
−
      send("There is no exit to the south.");
 
−
    }
 
−
    quit;
 
−
} dilend
 
−
 
 
−
=== Clan Teleport Example ===
 
−
dilbegin clan_move(i:integer);
 
−
code
 
−
{
 
−
    act("<div class='clan'>$1n vanishes.</div>",A_HIDEINV,self, null, null, TO_ROOM);
 
−
    act("<div class='clan'>You are teleported.</div>", A_SOMEONE,self, null, null, TO_CHAR);
 
−
    link(self, self.outside.exit_to[i]);
 
−
    act("<div class='clan'>$1n appears from thin air.</div>",A_HIDEINV, self, null, null, TO_ROOM);
 
−
    exec("look", self);
 
−
    quit;
 
−
} dilend
 
−
 
 
−
=== Exit Validation ===
 
−
dilbegin validate_exit(room : unitptr, direction : integer);
 
−
code
 
−
{
 
−
    if (direction < 0 or direction > 5) {
 
−
      send("Invalid direction.");
 
−
      quit;
 
−
    }
 
−
   
 
−
    if (room.exit_to[direction] != null) {
 
−
      send("Exit leads to: " + room.exit_to[direction].title);
 
−
    } else {
 
−
      send("No exit in that direction.");
 
−
    }
 
−
    quit;
 
−
} dilend
 
−
 
 
−
=== Room Light Check ===
 
−
dilbegin check_room_light(room : unitptr);
 
−
var
 
−
    dir : integer;
 
−
    buff : string;
 
−
code
 
−
{
 
−
    buff := "Exits: ";
 
−
    for (dir := 0; dir < 6; dir := dir + 1) {
 
−
      if (room.exit_to[dir]) {
 
−
          buff := buff + room.exit_to[dir].title + "<br/>";
 
−
      }
 
−
    }
 
−
    send(buff);
 
−
    quit;
 
−
} dilend
 
−
 
 
−
== Error Handling ==
 
−
The field performs comprehensive validation:
 
−
* '''Room validation'' - Ensures the unit is a valid room type
 
−
* '''Direction validation'' - Checks that the direction index is between 0 and MAX_EXIT
 
−
* '''Exit existence'' - Returns null if no exit exists in the specified direction
 
−
* '''Type validation'' - Returns fail if accessed on non-room units
 
−
 
 
−
Note: The C implementation shows that the function uses is_in() to validate the direction range and ROOM_EXIT() macro to access the exit data structure.
 
−
 
 
−
== Usage Notes ==
 
−
* This field is read-only - you cannot change exit destinations through DIL
 
−
* Only available on room units (UNIT_ST_ROOM type)
 
−
* Always check for null return values before using the destination room
 
−
* The field is commonly used for navigation, teleportation, and room validation
 
−
* Use with exit_names[] and exit_info[] for complete exit management
 
−
* Direction constants are defined in values.h and vme.h header files
 
−
 
 
−
== Related Fields ==
 
−
* [[exit_names]] - Array of exit name strings for each direction
 
−
* [[exit_info]] - Array of exit flag bits for each direction
 
−
* [[roomflags]] - Room property flags
 
−
* [[movement]] - Room movement type
 
−
 
 
−
== See Also ==
 
−
* [[unitptr]] - Unit pointer data type
 
−
* [[link]] - Function to move units between rooms
 
−
* [[findroom]] - Function to find rooms by name
 
−
* [[UNIT_ST_ROOM]] - Room unit type constant
 

Latest revision as of 23:13, 14 November 2026

exit_to

Field (unitptr, read-only; units: rooms).

room.exit_to[dir] : unitptr

The room that the exit in direction dir leads to, or null when the room has no exit that way. dir is a direction from vme.h: NORTH (0), EAST, SOUTH, WEST, UP, DOWN, NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST (9); MAX_EXIT is the last.

Notes

  • It fails when the unit is not a room (an object, a character, null) and when dir is outside 0 to MAX_EXIT. A failed value is false in an if, so if (room.exit_to[dir]) is a safe test.
  • It can't be assigned (vmc: "Illegal lvalue"). Make or change exits with setroomexit().
  • Fields can be read on the result directly: self.outside.exit_to[dir].movement works.
  • To move an NPC through an exit, use exec("north", self) (an ordinary move, with its messages and checks) rather than link(self, room.exit_to[NORTH]).

Example

dilbegin string exit_list(room : unitptr);
var
   dir : integer;
   sl : stringlist;
   buf : string;
code
{
   sl := DIR_SL_SHORT;
   dir := NORTH;
   while (dir <= MAX_EXIT)
   {
      if (room.exit_to[dir])
         buf := buf + sl.[dir] + " ";
      dir := dir + 1;
   }
   return (buf);
}
dilend

Lists a room's exits as "n e u ", as the exit line in baselook.zon does (which also skips hidden ones).

See also