Manual:DIL Manual/findsymbolic()
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.