Difference between revisions of "Manual:DIL Manual/string in extraptr"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="esine"></span>
+
= string in extraptr =
−
string in extraptr
+
'''Operator''' (extraptr).
−
    Argument 1: A string to find.
 
−
    Argument 2: An extra description list to search.
 
−
    Return: Extraptr to first entry with string matching .names or
 
−
            null if none. (names must be exact letter by letter
 
−
            match, although case is ignored).
 
  
−
  '''Example:'''
+
  s in exlist : extraptr
  
−
<nowiki>
+
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.
  
−
  dilbegin foo();
+
== Returns ==
−
  code
+
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.
−
dilend</nowiki>
 
−
<span id="esine"></span>
 
−
string in extraptr
 
−
    Argument 1: A string to find.
 
−
    Argument 2: An extra description list to search.
 
−
    Return: Extraptr to first entry with string matching .names or
 
−
            null if none. (names must be exact letter by letter
 
−
            match, although case is ignored).
 
  
−
'''Example:'''
+
== 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.
  
−
<nowiki>
+
== 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.
  
−
  dilbegin foo();
+
== See also ==
−
  code
+
* [[Manual:DIL Manual/string in string|string in string]]
−
dilend</nowiki>
+
* [[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.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