Difference between revisions of "Manual:DIL Manual/string in extraptr"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = string in extraptr = | |
| − | + | '''Operator''' (extraptr). | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | s in exlist : extraptr | |
| − | + | Finds the extra description whose names include <code>s</code>, in a list of extras such as <code>u.extra</code> or <code>pc.quests</code>, and gives that extra; null when there is none. Use it to find hidden data extras (<code>"$visits" in pc.extra</code>) and quest entries. | |
| − | + | == Returns == | |
| − | + | The first extra in the list with a name equal to <code>s</code>, or null. Read its <code>descr</code>, <code>names</code> and <code>vals</code> fields, or change them. | |
| − | |||
| − | < | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == Notes == | |
| + | * The name must match exactly, letter by letter; only case is ignored. <code>"$visit" in u.extra</code> doesn't find an extra named "$visits", and no partial words or first words match, unlike <code>in</code> with a stringlist. | ||
| + | * Spaces before <code>s</code> are skipped; spaces after it are not. | ||
| + | * An extra with no names at all is found by <code>""</code>. | ||
| + | * <code>u.extra.["$visits"]</code> does the same search. | ||
| + | * The extraptr is only good until the program waits: after <code>wait()</code> or <code>pause</code> every extraptr variable is null, so look it up again. | ||
| − | + | == Example == | |
| + | <pre> | ||
| + | dilbegin integer visits(pc : unitptr); | ||
| + | var | ||
| + | exd : extraptr; | ||
| + | code | ||
| + | { | ||
| + | exd := "$visits" in pc.extra; | ||
| + | if (exd == null) | ||
| + | { | ||
| + | addextra(pc.extra, {"$visits"}, "1"); | ||
| + | return (1); | ||
| + | } | ||
| + | exd.descr := itoa(atoi(exd.descr) + 1); | ||
| + | return (atoi(exd.descr)); | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Counts a player's visits in a hidden extra and gives the new count. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/string in string|string in string]] | |
| − | + | * [[Manual:DIL Manual/string in stringlist|string in stringlist]] | |
| + | * [[Manual:DIL Manual/in|in]] | ||
| + | * [[Manual:DIL Manual/extraptr|extraptr]] | ||
| + | * [[Manual:DIL Manual/extra|extra]] | ||
| + | * [[Manual:DIL Manual/addextra()|addextra()]] | ||
| + | * [[Manual:DIL Manual/subextra()|subextra()]] | ||
Latest revision as of 23:25, 14 November 2026
string in extraptr
Operator (extraptr).
s in exlist : extraptr
Finds the extra description whose names include s, in a list of extras such as u.extra or pc.quests, and gives that extra; null when there is none. Use it to find hidden data extras ("$visits" in pc.extra) and quest entries.
Returns
The first extra in the list with a name equal to s, or null. Read its descr, names and vals fields, or change them.
Notes
- The name must match exactly, letter by letter; only case is ignored.
"$visit" in u.extradoesn't find an extra named "$visits", and no partial words or first words match, unlikeinwith a stringlist. - Spaces before
sare skipped; spaces after it are not. - An extra with no names at all is found by
"". u.extra.["$visits"]does the same search.- The extraptr is only good until the program waits: after
wait()orpauseevery extraptr variable is null, so look it up again.
Example
dilbegin integer visits(pc : unitptr);
var
exd : extraptr;
code
{
exd := "$visits" in pc.extra;
if (exd == null)
{
addextra(pc.extra, {"$visits"}, "1");
return (1);
}
exd.descr := itoa(atoi(exd.descr) + 1);
return (atoi(exd.descr));
}
dilend
Counts a player's visits in a hidden extra and gives the new count.