Manual:DIL Manual/string in extraptr

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:25, 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

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.extra doesn't find an extra named "$visits", and no partial words or first words match, unlike in with a stringlist.
  • Spaces before s are 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() or pause every 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.

See also