Difference between revisions of "Manual:DIL Manual/findsymbolic()"
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = findsymbolic() = | |
| − | + | '''Function''' (unitptr). Finds a unit by its symbolic name, the <code>name@zone</code> 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: <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. | ||
| − | + | * With one argument it returns a copy of <code>sym</code> anywhere in the game, the most recently made one. | |
| − | + | * 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. | |
| − | + | * With a unit and flags it looks only in places around <code>u</code>, like findunit does. | |
| − | |||
| − | |||
| − | |||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| − | + | ! Name !! Type !! Meaning | |
| − | + | |- | |
| − | + | | 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. | |
| − | + | |- | |
| − | + | | idx || integer || The unit's <code>idx</code> field, read earlier. | |
| − | + | |- | |
| + | | 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. | ||
| − | + | == Example == | |
| − | + | <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()]] | |
| − | + | * [[Manual:DIL Manual/findroom()|findroom()]] | |
| − | + | * [[Manual:DIL Manual/symname|symname]] | |
| − | + | * [[Manual:DIL Manual/idx|idx]] | |
| − | + | * [[Manual:DIL Manual/load()|load()]] | |
| − | + | * [[Manual:DIL Manual/sendto()|sendto()]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
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
symanywhere in the game, the most recently made one. - With an index it returns the one copy whose
idxfield isidx, so a program can find a particular unit again later, after a wait, with only itssymnameandidxstored 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
@zonenothing is found: the zone is never taken from the program's own. - For a player,
symnameandidxfind the player while he or she is in the game, and nothing once logged out. An NPC or object found again byidxis 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.