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

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="bffinds"></span>
+
= findsymbolic() =
−
unitptr findsymbolic ( s : string )
+
'''Function''' (unitptr). Finds a unit by its symbolic name, the <code>name@zone</code> it was defined with.
−
    s : Symbolic name of the NPC or Object to find.
 
−
    return: A pointer to an instance of the unit, or null.
 
−
    Example: findsymbolic("bread@midgaard")
 
  
−
    This routine supplements findroom and findunit. It comes in handy,if it is
+
  findsymbolic(sym : string) : unitptr
−
    important to get a correct reference to a NPC in the world. If for example,
+
  findsymbolic(sym : string, idx : integer) : unitptr
−
    Mary needs to send a message to John the Lumberjack, then she should NOT
+
findsymbolic(u : unitptr, sym : string, flags : integer) : unitptr
−
    use the findunit() since it may locate a different John - even a player!
 
−
    If she instead locates him using findsymbolic("john@haon_dor") she will be
 
−
    certain that it is in fact her husband, and not the player John Dow from
 
−
    Norway.  It will NOT locate rooms, for the only reason that findroom is a
 
−
    lot more efficient.
 
  
 +
Every NPC, object and room comes from a definition in a zone file, and its symbolic name says which: <code>"janitor1@midgaard"</code>. Unlike [[Manual:DIL Manual/findunit()|findunit()]], which goes by the names players use, this finds a copy of exactly that definition, whatever it is called and whether or not anyone can see it.
  
−
unitptr findsymbolic ( u : unitptr, s : string, i : integer )
+
* With one argument it returns a copy of <code>sym</code> anywhere in the game, the most recently made one.
−
    u : Search is relative to this unit.
+
* With an index it returns the one copy whose <code>idx</code> field is <code>idx</code>, so a program can find a particular unit again later, after a wait, with only its <code>symname</code> and <code>idx</code> stored as text.
−
    s : Symbolic name of the NPC or Object to find.
+
* With a unit and flags it looks only in places around <code>u</code>, like findunit does.
−
    i : FIND_UNIT_XXX bit vector of places to search.
 
−
    return: A pointer to an instance of the unit, or null.
 
−
    Example: findsymbolic(self, "bread@midgaard", FIND_UNIT_INVEN)
 
  
−
    This routine supplements findroom, findunit and findsymbolic(#). It comes in
+
== Parameters ==
−
    handy, if it is important to get a correct reference to a unit somewhere
+
{| class="wikitable"
−
    relative to 'u'. If for example, Mary needs to check if she has her own
+
! Name !! Type !! Meaning
−
    cooking pot, then she should NOT use the findunit since it may locate a
+
|-
−
    different pot, not belonging to Haon-Dor but to some other zone. If she
+
| sym || string || The symbolic name, <code>"name@zone"</code> (or <code>"zone/name"</code>). Case doesn't matter. A unit's own is its <code>symname</code> field.
−
    instead locates it using findsymbolic(self, "pot@haon_dor", FIND_UNIT_IN_ME)
+
|-
−
    she would be certain that it is in fact her own cooking pot that she is
+
| idx || integer || The unit's <code>idx</code> field, read earlier.
−
    carrying around, and not some other pot from a Joe Blow's zone.
+
|-
 +
| u || unitptr || The unit to search around.
 +
|-
 +
| flags || integer || Where to look, <code>FIND_UNIT_*</code> from <code>vme/include/vme.h</code>, joined with <code>|</code>: <code>FIND_UNIT_EQUIP</code> (worn by <code>u</code>), <code>FIND_UNIT_INVEN</code> (carried by <code>u</code>, not worn; for a room or container, what is in it), <code>FIND_UNIT_SURRO</code> (the room <code>u</code> is in and what is there), <code>FIND_UNIT_ZONE</code> (a copy in the zone <code>u</code> is in), <code>FIND_UNIT_WORLD</code> (a copy anywhere). <code>FIND_UNIT_IN_ME</code> is equip and inventory.
 +
|}
  
 +
== Returns ==
 +
The unit, or null when there is no such unit (the name has no definition, or no copy exists right now, or none in the places searched). When <code>u</code> is null, or a string variable that has never been given a value is passed, the call fails or returns null.
  
−
---~---~---~---~---~---~---~---~---
+
== Notes ==
 +
* It finds rooms too: <code>findsymbolic("temple@udgaard")</code> is the room. [[Manual:DIL Manual/findroom()|findroom()]] does the same for rooms only.
 +
* Without <code>@zone</code> nothing is found: the zone is never taken from the program's own.
 +
* For a player, <code>symname</code> and <code>idx</code> find the player while he or she is in the game, and nothing once logged out. An NPC or object found again by <code>idx</code> is the same unit only while it exists; after it is gone, null.
 +
* The places are searched in the order equipment, inventory, surroundings, zone, world, and the first copy found is returned.
 +
* It's quick: it goes through the copies of that one definition, not through every unit in the game.
  
−
dilbegin zonelog (s:string);
+
== Example ==
−
code
+
<pre>
 +
dilbegin call_janitor();
 +
var
 +
  u : unitptr;
 +
code
 +
{
 +
  if (findsymbolic(self, "torch@midgaard", FIND_UNIT_IN_ME) != null)
 +
  {
 +
      sendtext("You already have a torch.<br/>", self);
 +
      quit;
 +
  }
 +
  u := findsymbolic("janitor1@midgaard");
 +
  if (u == null)
 +
  {
 +
      sendtext("The janitor is nowhere to be found.<br/>", self);
 +
      quit;
 +
  }
 +
  sendto("torch please", u);
 +
  quit;
 +
}
 
dilend
 
dilend
 +
</pre>
 +
Checks the character's own things for a Midgaard torch, then sends a message to the programs of a Midgaard janitor, wherever he is.
  
−
---~---~---~---~---~---~---~---~---
+
== See also ==
−
 
+
* [[Manual:DIL Manual/findunit()|findunit()]]
−
</i><!--ENDCODE-->
+
* [[Manual:DIL Manual/findroom()|findroom()]]
−
The previous DIL function will work in any zone to log to a file with that zones
+
* [[Manual:DIL Manual/symname|symname]]
−
  name each zone could use it to keep zone logs separate.
+
* [[Manual:DIL Manual/idx|idx]]
−
 
+
* [[Manual:DIL Manual/load()|load()]]
−
 
+
* [[Manual:DIL Manual/sendto()|sendto()]]
−
---~---~---~---~---~---~---~---~---
 
−
<span id="bffinds"></span>
 
−
unitptr findsymbolic ( s : string )
 
−
    s : Symbolic name of the NPC or Object to find.
 
−
    return: A pointer to an instance of the unit, or null.
 
−
    Example: findsymbolic("bread@midgaard")
 
−
 
 
−
    This routine supplements findroom and findunit. It comes in handy,if it is
 
−
    important to get a correct reference to a NPC in the world.  If for example,
 
−
    Mary needs to send a message to John the Lumberjack,  then she should NOT
 
−
    use the findunit() since it may locate a different John - even a player!
 
−
    If she instead locates him using findsymbolic("john@haon_dor") she will be
 
−
    certain that it is in fact her husband, and not the player John Dow from
 
−
    Norway.  It will NOT locate rooms, for the only reason that findroom is a
 
−
    lot more efficient.
 
−
 
 
−
 
 
−
unitptr findsymbolic ( u : unitptr, s : string, i : integer )
 
−
    u : Search is relative to this unit.
 
−
    s : Symbolic name of the NPC or Object to find.
 
−
    i : FIND_UNIT_XXX bit vector of places to search.
 
−
    return: A pointer to an instance of the unit, or null.
 
−
    Example: findsymbolic(self, "bread@midgaard", FIND_UNIT_INVEN)
 
−
 
 
−
    This routine supplements findroom, findunit and findsymbolic(#).  It comes in
 
−
    handy, if it is important to get a correct reference to a unit somewhere
 
−
    relative to 'u'.  If for example, Mary needs to check if she has her own
 
−
    cooking pot, then she should NOT use the findunit since it may locate a
 
−
    different pot, not belonging to Haon-Dor but to some other zone.  If she
 
−
    instead locates it using findsymbolic(self, "pot@haon_dor", FIND_UNIT_IN_ME)
 
−
    she would be certain that it is in fact her own cooking pot that she is
 
−
    carrying around, and not some other pot from a Joe Blow's zone.
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
dilbegin zonelog (s:string);
 
−
code
 
−
dilend
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 
−
The previous DIL function will work in any zone to log to a file with that zones
 
−
  name each zone could use it to keep zone logs separate.
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 

Latest revision as of 23:18, 14 November 2026

findsymbolic()

Function (unitptr). Finds a unit by its symbolic name, the name@zone it was defined with.

findsymbolic(sym : string) : unitptr
findsymbolic(sym : string, idx : integer) : unitptr
findsymbolic(u : unitptr, sym : string, flags : integer) : unitptr

Every NPC, object and room comes from a definition in a zone file, and its symbolic name says which: "janitor1@midgaard". Unlike findunit(), which goes by the names players use, this finds a copy of exactly that definition, whatever it is called and whether or not anyone can see it.

  • With one argument it returns a copy of sym anywhere in the game, the most recently made one.
  • With an index it returns the one copy whose idx field is idx, so a program can find a particular unit again later, after a wait, with only its symname and idx stored as text.
  • With a unit and flags it looks only in places around u, like findunit does.

Parameters

Name Type Meaning
sym string The symbolic name, "name@zone" (or "zone/name"). Case doesn't matter. A unit's own is its symname field.
idx integer The unit's idx field, read earlier.
u unitptr The unit to search around.
flags integer : FIND_UNIT_EQUIP (worn by u), FIND_UNIT_INVEN (carried by u, not worn; for a room or container, what is in it), FIND_UNIT_SURRO (the room u is in and what is there), FIND_UNIT_ZONE (a copy in the zone u is in), FIND_UNIT_WORLD (a copy anywhere). FIND_UNIT_IN_ME is equip and inventory.

Returns

The unit, or null when there is no such unit (the name has no definition, or no copy exists right now, or none in the places searched). When u is null, or a string variable that has never been given a value is passed, the call fails or returns null.

Notes

  • It finds rooms too: findsymbolic("temple@udgaard") is the room. findroom() does the same for rooms only.
  • Without @zone nothing is found: the zone is never taken from the program's own.
  • For a player, symname and idx find the player while he or she is in the game, and nothing once logged out. An NPC or object found again by idx is the same unit only while it exists; after it is gone, null.
  • The places are searched in the order equipment, inventory, surroundings, zone, world, and the first copy found is returned.
  • It's quick: it goes through the copies of that one definition, not through every unit in the game.

Example

dilbegin call_janitor();
var
   u : unitptr;
code
{
   if (findsymbolic(self, "torch@midgaard", FIND_UNIT_IN_ME) != null)
   {
      sendtext("You already have a torch.<br/>", self);
      quit;
   }
   u := findsymbolic("janitor1@midgaard");
   if (u == null)
   {
      sendtext("The janitor is nowhere to be found.<br/>", self);
      quit;
   }
   sendto("torch please", u);
   quit;
}
dilend

Checks the character's own things for a Midgaard torch, then sends a message to the programs of a Midgaard janitor, wherever he is.

See also