Manual:DIL Manual/in
Jump to navigation
Jump to search
Contents
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
soccurs anywhere intext, 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 ofs, ignoring case:"ship arrived" in {"ship"}is 1, but"arrived" in {"arrived_port"}is 0. - extraptr (such as
u.extraorpc.quests): the first extra that hassas 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
inbinds like*,/andand: tighter than+,-,orand comparisons, looser thannot. So writenot ("x" in sl):not "x" in slis read as(not "x") in sland vmc stops with "Arg 1 of 'in' not string". Likewise"a" + b in smeans"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
sare 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@questsand friends) rather than testingpc.questsby 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).