Manual:DIL Manual/in

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:14, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

in

Keyword (operator; integer or extraptr). Looks for a string in a string, a stringlist or a list of extras.

s in text      : integer   (text : string)
s in list      : integer   (list : stringlist)
s in extras    : extraptr  (extras : extraptr)

The left side is always a string. What in does depends on the right side:

  • string: TRUE (1) if s occurs anywhere in text, ignoring case, otherwise FALSE (0). "key" in "Do you have a KEY?" is TRUE, and so is "spook" in "nospook".
  • stringlist: the position of the first entry that matches, plus one (so 1 for the first entry), or 0 if none does. An entry matches when it is s, or the first word or words of s, ignoring case: "ship arrived" in {"ship"} is 1, but "arrived" in {"arrived_port"} is 0.
  • extraptr (such as u.extra or pc.quests): the first extra that has s as one of its names (the whole name, ignoring case), or null.

Returns

An integer for a string or stringlist, an extraptr for extras. Both work directly in an if: 0 and null are false. If either side fails (a field of a null unit, say), the result fails, which is also false.

Notes

  • in binds like *, / and and: tighter than +, -, or and comparisons, looser than not. So write not ("x" in sl): not "x" in sl is read as (not "x") in sl and vmc stops with "Arg 1 of 'in' not string". Likewise "a" + b in s means "a" + (b in s).
  • The string test is a substring test. To match a whole word, split the text into words first (getwords()) and use the stringlist form.
  • In the stringlist form, leading spaces in s are skipped and runs of spaces count as one.
  • A list in braces works on the right: arg in {":brief:", ":chars:"} (baselook.zon). The braces take only constants, not variables.
  • For quests, use quests.zon's functions (qstOngoing@quests and friends) rather than testing pc.quests by hand.

Example

dilbegin gate_talk();
var
   ex : extraptr;
   n : integer;
code
{
:start:
   wait(SFB_CMD, command("say") and (activator.type == UNIT_ST_PC));

   if (not ("password" in argument))
      goto start;

   n := getword(argument) in {"swordfish", "dragon"};
   ex := "$gate_pass" in activator.extra;

   if (n == 0)
      act("$1n shakes $1s head.", A_ALWAYS, self, null, activator, TO_ROOM);
   else if (ex != null)
      act("$1n nods to $3n: 'Welcome back.'", A_ALWAYS, self, null, activator, TO_ROOM);
   else
   {
      addextra(activator.extra, {"$gate_pass"}, "1");
      act("$1n lets $3n through.", A_ALWAYS, self, null, activator, TO_ROOM);
   }
   goto start;
}
dilend

A guard who listens for "password" anywhere in what is said (string form), checks the first word against the passwords (stringlist form) and remembers who has been let through (extra form).

See also